Skip to content

Commit

Permalink
actually set controller reference
Browse files Browse the repository at this point in the history
  • Loading branch information
bastjan committed Oct 23, 2024
1 parent 209b365 commit e15bbc1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion controllers/machine_api_controllers_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/log"
)

Expand Down Expand Up @@ -85,6 +86,9 @@ func (r *MachineAPIControllersReconciler) Reconcile(ctx context.Context, req ctr
},
},
}
if err := controllerutil.SetControllerReference(&imageCM, &caBundleConfigMap, r.Scheme); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to set controller reference: %w", err)
}
if err := r.Client.Patch(ctx, &caBundleConfigMap, client.Apply, client.FieldOwner("upstream-deployment-controller")); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to apply ConfigMap %q: %w", caBundleConfigMapName, err)
}
Expand All @@ -109,7 +113,9 @@ func (r *MachineAPIControllersReconciler) Reconcile(ctx context.Context, req ctr
return ctrl.Result{}, fmt.Errorf("expected Deployment, got %s/%s", toDeploy.APIVersion, toDeploy.Kind)
}
toDeploy.Namespace = r.Namespace

if err := controllerutil.SetControllerReference(&imageCM, &toDeploy, r.Scheme); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to set controller reference: %w", err)
}
if err := r.Client.Patch(ctx, &toDeploy, client.Apply, client.FieldOwner("upstream-deployment-controller")); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to apply Deployment %q: %w", toDeploy.GetName(), err)
}
Expand Down

0 comments on commit e15bbc1

Please sign in to comment.