Skip to content

Commit

Permalink
Add OwnerRef to clusterResourceSetBinding on each reconcile
Browse files Browse the repository at this point in the history
Signed-off-by: killianmuldoon <[email protected]>
  • Loading branch information
killianmuldoon committed Jul 28, 2022
1 parent d761e1b commit 4f4e23d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ func (r *ClusterResourceSetReconciler) ApplyClusterResourceSet(ctx context.Conte
}
}()

// Ensure that the owner references are set on the ClusterResourceSetBinding.
clusterResourceSetBinding.OwnerReferences = ensureOwnerRefs(clusterResourceSetBinding, clusterResourceSet, cluster)

errList := []error{}
resourceSetBinding := clusterResourceSetBinding.GetOrCreateBinding(clusterResourceSet)

Expand Down
23 changes: 16 additions & 7 deletions exp/addons/internal/controllers/clusterresourceset_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,8 @@ func (r *ClusterResourceSetReconciler) getOrCreateClusterResourceSetBinding(ctx

clusterResourceSetBinding.Name = cluster.Name
clusterResourceSetBinding.Namespace = cluster.Namespace
clusterResourceSetBinding.OwnerReferences = util.EnsureOwnerRef(clusterResourceSetBinding.OwnerReferences, metav1.OwnerReference{
APIVersion: clusterv1.GroupVersion.String(),
Kind: "Cluster",
Name: cluster.Name,
UID: cluster.UID,
})
clusterResourceSetBinding.OwnerReferences = util.EnsureOwnerRef(clusterResourceSetBinding.OwnerReferences, *metav1.NewControllerRef(clusterResourceSet, clusterResourceSet.GroupVersionKind()))

clusterResourceSetBinding.OwnerReferences = ensureOwnerRefs(clusterResourceSetBinding, clusterResourceSet, cluster)

clusterResourceSetBinding.Spec.Bindings = []*addonsv1.ResourceSetBinding{}
if err := r.Client.Create(ctx, clusterResourceSetBinding); err != nil {
Expand All @@ -146,6 +141,20 @@ func (r *ClusterResourceSetReconciler) getOrCreateClusterResourceSetBinding(ctx
return clusterResourceSetBinding, nil
}

// ensureOwnerRefs ensures Cluster and ClusterResourceSet owner references are set on the ClusterResourceSetBinding
func ensureOwnerRefs(clusterResourceSetBinding *addonsv1.ClusterResourceSetBinding, clusterResourceSet *addonsv1.ClusterResourceSet, cluster *clusterv1.Cluster) []metav1.OwnerReference {
clusterResourceSetBinding.Name = cluster.Name
clusterResourceSetBinding.Namespace = cluster.Namespace
clusterResourceSetBinding.OwnerReferences = util.EnsureOwnerRef(clusterResourceSetBinding.OwnerReferences, metav1.OwnerReference{
APIVersion: clusterv1.GroupVersion.String(),
Kind: "Cluster",
Name: cluster.Name,
UID: cluster.UID,
})
clusterResourceSetBinding.OwnerReferences = util.EnsureOwnerRef(clusterResourceSetBinding.OwnerReferences, *metav1.NewControllerRef(clusterResourceSet, clusterResourceSet.GroupVersionKind()))
return clusterResourceSetBinding.OwnerReferences
}

// getConfigMap retrieves any ConfigMap from the given name and namespace.
func getConfigMap(ctx context.Context, c client.Client, configmapName types.NamespacedName) (*corev1.ConfigMap, error) {
configMap := &corev1.ConfigMap{}
Expand Down

0 comments on commit 4f4e23d

Please sign in to comment.