@@ -120,18 +120,11 @@ func (r *ClusterResourceSetReconciler) getOrCreateClusterResourceSetBinding(ctx
120
120
if ! apierrors .IsNotFound (err ) {
121
121
return nil , err
122
122
}
123
-
124
123
clusterResourceSetBinding .Name = cluster .Name
125
124
clusterResourceSetBinding .Namespace = cluster .Namespace
126
- clusterResourceSetBinding .OwnerReferences = util .EnsureOwnerRef (clusterResourceSetBinding .OwnerReferences , metav1.OwnerReference {
127
- APIVersion : clusterv1 .GroupVersion .String (),
128
- Kind : "Cluster" ,
129
- Name : cluster .Name ,
130
- UID : cluster .UID ,
131
- })
132
- clusterResourceSetBinding .OwnerReferences = util .EnsureOwnerRef (clusterResourceSetBinding .OwnerReferences , * metav1 .NewControllerRef (clusterResourceSet , clusterResourceSet .GroupVersionKind ()))
133
-
125
+ clusterResourceSetBinding .OwnerReferences = ensureOwnerRefs (clusterResourceSetBinding , clusterResourceSet , cluster )
134
126
clusterResourceSetBinding .Spec .Bindings = []* addonsv1.ResourceSetBinding {}
127
+
135
128
if err := r .Client .Create (ctx , clusterResourceSetBinding ); err != nil {
136
129
if apierrors .IsAlreadyExists (err ) {
137
130
if err = r .Client .Get (ctx , clusterResourceSetBindingKey , clusterResourceSetBinding ); err != nil {
@@ -142,10 +135,29 @@ func (r *ClusterResourceSetReconciler) getOrCreateClusterResourceSetBinding(ctx
142
135
return nil , errors .Wrapf (err , "failed to create clusterResourceSetBinding for cluster: %s/%s" , cluster .Namespace , cluster .Name )
143
136
}
144
137
}
145
-
146
138
return clusterResourceSetBinding , nil
147
139
}
148
140
141
+ // ensureOwnerRefs ensures Cluster and ClusterResourceSet owner references are set on the ClusterResourceSetBinding.
142
+ func ensureOwnerRefs (clusterResourceSetBinding * addonsv1.ClusterResourceSetBinding , clusterResourceSet * addonsv1.ClusterResourceSet , cluster * clusterv1.Cluster ) []metav1.OwnerReference {
143
+ ownerRefs := make ([]metav1.OwnerReference , len (clusterResourceSetBinding .GetOwnerReferences ()))
144
+ copy (ownerRefs , clusterResourceSetBinding .GetOwnerReferences ())
145
+ ownerRefs = util .EnsureOwnerRef (ownerRefs , metav1.OwnerReference {
146
+ APIVersion : clusterv1 .GroupVersion .String (),
147
+ Kind : "Cluster" ,
148
+ Name : cluster .Name ,
149
+ UID : cluster .UID ,
150
+ })
151
+ ownerRefs = util .EnsureOwnerRef (ownerRefs ,
152
+ metav1.OwnerReference {
153
+ APIVersion : clusterResourceSet .GroupVersionKind ().String (),
154
+ Kind : clusterResourceSet .GroupVersionKind ().Kind ,
155
+ Name : clusterResourceSet .Name ,
156
+ UID : clusterResourceSet .UID ,
157
+ })
158
+ return ownerRefs
159
+ }
160
+
149
161
// getConfigMap retrieves any ConfigMap from the given name and namespace.
150
162
func getConfigMap (ctx context.Context , c client.Client , configmapName types.NamespacedName ) (* corev1.ConfigMap , error ) {
151
163
configMap := & corev1.ConfigMap {}
0 commit comments