Skip to content

Commit 3d2ba16

Browse files
authored
Merge pull request #1639 from fluxcd/backport-1635-to-release/v1.8.x
[release/v1.8.x] Introduce support for migrating API version
2 parents 9f05e0d + 745c45c commit 3d2ba16

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

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)