Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager, operatorNamespace string
if err != nil {
return err
}

mapToOwnerByLabel := handler.EnqueueRequestsFromMapFunc(commoncontroller.MapToControllerByMatchingLabel(toolchainv1alpha1.ProviderLabelKey, ResourceControllerLabelValue))
for _, obj := range r.templateObjects {
build = build.Watches(obj.DeepCopyObject().(runtimeclient.Object), mapToOwnerByLabel, builder.WithPredicates(commonpredicates.LabelsAndGenerationPredicate{}))
Expand All @@ -53,6 +54,7 @@ type Reconciler struct {
Client runtimeclient.Client
Scheme *runtime.Scheme
Templates *embed.FS
FieldManager string
templateObjects []*unstructured.Unstructured
}

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

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

return reconcile.Result{}, applycl.ApplyUnstructuredObjectsWithNewLabels(ctx, r.Client, r.templateObjects, newLabels) // apply objects on the cluster
cl := applycl.NewSSAApplyClient(r.Client, r.FieldManager)
return reconcile.Result{}, applycl.ApplyAll(ctx, cl, r.templateObjects, applycl.EnsureLabels(newLabels)) // apply objects on the cluster
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func prepareReconcile(sa *v1.ServiceAccount, cl *test.FakeClient, templates *emb
Client: cl,
Scheme: scheme.Scheme,
Templates: templates,
FieldManager: "testOwner",
templateObjects: templateObjects,
}
req := reconcile.Request{
Expand Down
7 changes: 6 additions & 1 deletion pkg/client/ssa_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,13 @@ func EnsureGVK(obj client.Object, scheme *runtime.Scheme) error {

// Apply is a utility function that just calls `ApplyObject` in a loop on all the supplied objects.
func (c *SSAApplyClient) Apply(ctx context.Context, toolchainObjects []client.Object, opts ...SSAApplyObjectOption) error {
return ApplyAll(ctx, c, toolchainObjects, opts...)
}

// ApplyAll is a generic version of c.Apply that can accept a slice of anything that implements client.Object.
func ApplyAll[T client.Object](ctx context.Context, cl *SSAApplyClient, toolchainObjects []T, opts ...SSAApplyObjectOption) error {
for _, toolchainObject := range toolchainObjects {
if err := c.ApplyObject(ctx, toolchainObject, opts...); err != nil {
if err := cl.ApplyObject(ctx, toolchainObject, opts...); err != nil {
return err
}
}
Expand Down
Loading