Skip to content

Commit 51518cd

Browse files
committed
replace the last use of the old apply client with the SSA client
1 parent e0ce87f commit 51518cd

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

controllers/toolchainclusterresources/toolchaincluster_resources_controller.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager, operatorNamespace string
4141
if err != nil {
4242
return err
4343
}
44+
4445
mapToOwnerByLabel := handler.EnqueueRequestsFromMapFunc(commoncontroller.MapToControllerByMatchingLabel(toolchainv1alpha1.ProviderLabelKey, ResourceControllerLabelValue))
4546
for _, obj := range r.templateObjects {
4647
build = build.Watches(obj.DeepCopyObject().(runtimeclient.Object), mapToOwnerByLabel, builder.WithPredicates(commonpredicates.LabelsAndGenerationPredicate{}))
@@ -53,6 +54,7 @@ type Reconciler struct {
5354
Client runtimeclient.Client
5455
Scheme *runtime.Scheme
5556
Templates *embed.FS
57+
FieldManager string
5658
templateObjects []*unstructured.Unstructured
5759
}
5860

@@ -72,5 +74,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
7274

7375
// TODO implement delete logic for objects that were renamed/removed from the templates
7476

75-
return reconcile.Result{}, applycl.ApplyUnstructuredObjectsWithNewLabels(ctx, r.Client, r.templateObjects, newLabels) // apply objects on the cluster
77+
cl := applycl.NewSSAApplyClient(r.Client, r.FieldManager)
78+
return reconcile.Result{}, applycl.ApplyAll(ctx, cl, r.templateObjects, applycl.EnsureLabels(newLabels)) // apply objects on the cluster
7679
}

controllers/toolchainclusterresources/toolchaincluster_resources_controller_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ func prepareReconcile(sa *v1.ServiceAccount, cl *test.FakeClient, templates *emb
110110
Client: cl,
111111
Scheme: scheme.Scheme,
112112
Templates: templates,
113+
FieldManager: "testOwner",
113114
templateObjects: templateObjects,
114115
}
115116
req := reconcile.Request{

pkg/client/ssa_client.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,13 @@ func EnsureGVK(obj client.Object, scheme *runtime.Scheme) error {
238238

239239
// Apply is a utility function that just calls `ApplyObject` in a loop on all the supplied objects.
240240
func (c *SSAApplyClient) Apply(ctx context.Context, toolchainObjects []client.Object, opts ...SSAApplyObjectOption) error {
241+
return ApplyAll(ctx, c, toolchainObjects, opts...)
242+
}
243+
244+
// ApplyAll is a generic version of c.Apply that can accept a slice of anything that implements client.Object.
245+
func ApplyAll[T client.Object](ctx context.Context, cl *SSAApplyClient, toolchainObjects []T, opts ...SSAApplyObjectOption) error {
241246
for _, toolchainObject := range toolchainObjects {
242-
if err := c.ApplyObject(ctx, toolchainObject, opts...); err != nil {
247+
if err := cl.ApplyObject(ctx, toolchainObject, opts...); err != nil {
243248
return err
244249
}
245250
}

0 commit comments

Comments
 (0)