@@ -14,6 +14,7 @@ import (
14
14
"k8s.io/apimachinery/pkg/runtime"
15
15
ctrl "sigs.k8s.io/controller-runtime"
16
16
"sigs.k8s.io/controller-runtime/pkg/client"
17
+ "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
17
18
"sigs.k8s.io/controller-runtime/pkg/log"
18
19
)
19
20
@@ -85,6 +86,9 @@ func (r *MachineAPIControllersReconciler) Reconcile(ctx context.Context, req ctr
85
86
},
86
87
},
87
88
}
89
+ if err := controllerutil .SetControllerReference (& imageCM , & caBundleConfigMap , r .Scheme ); err != nil {
90
+ return ctrl.Result {}, fmt .Errorf ("failed to set controller reference: %w" , err )
91
+ }
88
92
if err := r .Client .Patch (ctx , & caBundleConfigMap , client .Apply , client .FieldOwner ("upstream-deployment-controller" )); err != nil {
89
93
return ctrl.Result {}, fmt .Errorf ("failed to apply ConfigMap %q: %w" , caBundleConfigMapName , err )
90
94
}
@@ -109,7 +113,9 @@ func (r *MachineAPIControllersReconciler) Reconcile(ctx context.Context, req ctr
109
113
return ctrl.Result {}, fmt .Errorf ("expected Deployment, got %s/%s" , toDeploy .APIVersion , toDeploy .Kind )
110
114
}
111
115
toDeploy .Namespace = r .Namespace
112
-
116
+ if err := controllerutil .SetControllerReference (& imageCM , & toDeploy , r .Scheme ); err != nil {
117
+ return ctrl.Result {}, fmt .Errorf ("failed to set controller reference: %w" , err )
118
+ }
113
119
if err := r .Client .Patch (ctx , & toDeploy , client .Apply , client .FieldOwner ("upstream-deployment-controller" )); err != nil {
114
120
return ctrl.Result {}, fmt .Errorf ("failed to apply Deployment %q: %w" , toDeploy .GetName (), err )
115
121
}
0 commit comments