-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🌱 Improve dry run for server side apply using an annotation #6709
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -42,6 +42,7 @@ import ( | |||||
"sigs.k8s.io/cluster-api/internal/controllers/topology/cluster/patches" | ||||||
"sigs.k8s.io/cluster-api/internal/controllers/topology/cluster/scope" | ||||||
"sigs.k8s.io/cluster-api/internal/controllers/topology/cluster/structuredmerge" | ||||||
"sigs.k8s.io/cluster-api/internal/controllers/topology/cluster/structuredmerge/diff" | ||||||
runtimecatalog "sigs.k8s.io/cluster-api/internal/runtime/catalog" | ||||||
runtimeclient "sigs.k8s.io/cluster-api/internal/runtime/client" | ||||||
"sigs.k8s.io/cluster-api/util" | ||||||
|
@@ -114,7 +115,8 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt | |||||
r.patchEngine = patches.NewEngine(r.RuntimeClient) | ||||||
r.recorder = mgr.GetEventRecorderFor("topology/cluster") | ||||||
if r.patchHelperFactory == nil { | ||||||
r.patchHelperFactory = serverSideApplyPatchHelperFactory(r.Client) | ||||||
crdSchemaCache := diff.NewCRDSchemaCache(r.Client) | ||||||
r.patchHelperFactory = serverSideApplyPatchHelperFactory(r.Client, crdSchemaCache) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Should we just do |
||||||
} | ||||||
return nil | ||||||
} | ||||||
|
@@ -338,15 +340,15 @@ func (r *Reconciler) machineDeploymentToCluster(o client.Object) []ctrl.Request | |||||
} | ||||||
|
||||||
// serverSideApplyPatchHelperFactory makes use of managed fields provided by server side apply and is used by the controller. | ||||||
func serverSideApplyPatchHelperFactory(c client.Client) structuredmerge.PatchHelperFactoryFunc { | ||||||
return func(original, modified client.Object, opts ...structuredmerge.HelperOption) (structuredmerge.PatchHelper, error) { | ||||||
return structuredmerge.NewServerSidePatchHelper(original, modified, c, opts...) | ||||||
func serverSideApplyPatchHelperFactory(c client.Client, crdSchemaCache diff.CRDSchemaCache) structuredmerge.PatchHelperFactoryFunc { | ||||||
return func(ctx context.Context, original, modified client.Object, opts ...structuredmerge.HelperOption) (structuredmerge.PatchHelper, error) { | ||||||
return structuredmerge.NewServerSidePatchHelper(ctx, original, modified, c, crdSchemaCache, opts...) | ||||||
} | ||||||
} | ||||||
|
||||||
// dryRunPatchHelperFactory makes use of a two-ways patch and is used in situations where we cannot rely on managed fields. | ||||||
func dryRunPatchHelperFactory(c client.Client) structuredmerge.PatchHelperFactoryFunc { | ||||||
return func(original, modified client.Object, opts ...structuredmerge.HelperOption) (structuredmerge.PatchHelper, error) { | ||||||
return func(ctx context.Context, original, modified client.Object, opts ...structuredmerge.HelperOption) (structuredmerge.PatchHelper, error) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
nit |
||||||
return structuredmerge.NewTwoWaysPatchHelper(original, modified, c, opts...) | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just that I get it right:
The output of this func for the Path
is a Path
I somehow can't map the method name to the functionality. Isn't it rather something like
ToArray
orAsArray
??Should we add a unit test?