Skip to content

Commit 4f98d34

Browse files
committed
Introduce support for migrating API version
Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
1 parent 9d23cc5 commit 4f98d34

5 files changed

Lines changed: 27 additions & 3 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ require (
2929
github.com/fluxcd/pkg/http/fetch v0.22.0
3030
github.com/fluxcd/pkg/kustomize v1.29.0
3131
github.com/fluxcd/pkg/runtime v0.103.0
32-
github.com/fluxcd/pkg/ssa v0.70.0
32+
github.com/fluxcd/pkg/ssa v0.70.1-0.20260415163824-18b0e9d64ba8
3333
github.com/fluxcd/pkg/tar v0.17.0
3434
github.com/fluxcd/pkg/testserver v0.13.0
3535
github.com/fluxcd/source-controller/api v1.8.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ github.com/fluxcd/pkg/runtime v0.103.0 h1:J5y5GPhWdkyqIUBlaI1FP2N02TtZmsjbWhhZub
225225
github.com/fluxcd/pkg/runtime v0.103.0/go.mod h1:mbo2f3azo3yVQgm7XZGxQB6/2zvzQ5Wgtd8TjRRwwAw=
226226
github.com/fluxcd/pkg/sourceignore v0.17.0 h1:Z72nruRMhC15zIEpWoDrAcJcJ1El6QDnP/aRDfE4WOA=
227227
github.com/fluxcd/pkg/sourceignore v0.17.0/go.mod h1:3e/VmYLId0pI/H5sK7W9Ibif+j0Ahns9RxNjDMtTTfY=
228-
github.com/fluxcd/pkg/ssa v0.70.0 h1:IBylYPiTK1IEdCC2DvjKXIhwQcbd5VufXA9WS3zO+tE=
229-
github.com/fluxcd/pkg/ssa v0.70.0/go.mod h1:6igtlt7/zF+nNFQpa5ZAkkvtpL6o36NRU39/PqqC+Bg=
228+
github.com/fluxcd/pkg/ssa v0.70.1-0.20260415163824-18b0e9d64ba8 h1:u02kshFVUoZgiJpPjCGnLTloXqbYImTCfM8fLf9h3CA=
229+
github.com/fluxcd/pkg/ssa v0.70.1-0.20260415163824-18b0e9d64ba8/go.mod h1:6igtlt7/zF+nNFQpa5ZAkkvtpL6o36NRU39/PqqC+Bg=
230230
github.com/fluxcd/pkg/tar v0.17.0 h1:uNxbFXy8ly8C7fJ8D7w3rjTNJFrb4Hp1aY/30XkfvxY=
231231
github.com/fluxcd/pkg/tar v0.17.0/go.mod h1:b1xyIRYDD0ket4SV5u0UXYv+ZdN/O/HmIO5jZQdHQls=
232232
github.com/fluxcd/pkg/testserver v0.13.0 h1:xEpBcEYtD7bwvZ+i0ZmChxKkDo/wfQEV3xmnzVybSSg=

internal/controller/kustomization_controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ type KustomizationReconciler struct {
120120
DirectSourceFetch bool
121121
FailFast bool
122122
GroupChangeLog bool
123+
MigrateAPIVersion bool
123124
StrictSubstitutions bool
124125
}
125126

@@ -867,6 +868,7 @@ func (r *KustomizationReconciler) apply(ctx context.Context,
867868
fmt.Sprintf("%s/force", kustomizev1.GroupVersion.Group): kustomizev1.EnabledValue,
868869
}
869870
applyOpts.CustomStageKinds = r.CustomStageKinds
871+
applyOpts.MigrateAPIVersion = r.MigrateAPIVersion
870872

871873
fieldManagers := []ssa.FieldManager{
872874
{

internal/features/features.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ const (
5555
// immediate processing of the new revision. This can help avoid getting
5656
// stuck on failing deployments when fixes are available.
5757
CancelHealthCheckOnNewRevision = "CancelHealthCheckOnNewRevision"
58+
59+
// MigrateAPIVersion controls whether the controller migrates the API
60+
// version referenced by the managed fields entries of in-cluster objects
61+
// to the API version of the applied objects when they differ.
62+
//
63+
// This works around a server-side apply dry-run failure that can occur
64+
// after a CRD upgrade introduces a new optional field with a default
65+
// value in a newer API version: the managed fields entry owned by the
66+
// controller still references the old API version, and the API server
67+
// reports the defaulted field as "field not declared in schema" when
68+
// validating managed fields against the old version's schema.
69+
MigrateAPIVersion = "MigrateAPIVersion"
5870
)
5971

6072
var features = map[string]bool{
@@ -88,6 +100,9 @@ var features = map[string]bool{
88100
// DirectSourceFetch
89101
// opt-in from v1.8
90102
controller.FeatureGateDirectSourceFetch: false,
103+
// MigrateAPIVersion
104+
// opt-in from v1.8.4
105+
MigrateAPIVersion: false,
91106
}
92107

93108
func init() {

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,12 @@ func main() {
303303
os.Exit(1)
304304
}
305305

306+
migrateAPIVersion, err := features.Enabled(features.MigrateAPIVersion)
307+
if err != nil {
308+
setupLog.Error(err, "unable to check feature gate "+features.MigrateAPIVersion)
309+
os.Exit(1)
310+
}
311+
306312
var tokenCache *pkgcache.TokenCache
307313
if tokenCacheOptions.MaxSize > 0 {
308314
var err error
@@ -357,6 +363,7 @@ func main() {
357363
KubeConfigOpts: kubeConfigOpts,
358364
Mapper: restMapper,
359365
Metrics: metricsH,
366+
MigrateAPIVersion: migrateAPIVersion,
360367
NoCrossNamespaceRefs: aclOptions.NoCrossNamespaceRefs,
361368
NoRemoteBases: noRemoteBases,
362369
SOPSAgeSecret: sopsAgeSecret,

0 commit comments

Comments
 (0)