Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Commit

Permalink
Rebasing from latest main
Browse files Browse the repository at this point in the history
  • Loading branch information
shivaani0505 committed Apr 11, 2023
1 parent 9df9964 commit 027f934
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 59 deletions.
5 changes: 0 additions & 5 deletions addons/controllers/clusterbootstrap_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,6 @@ func (r *ClusterBootstrapReconciler) patchClusterBootstrapFromTemplate(
return nil, err
}

if err := clusterBootstrapHelper.AddPackageLabelForCNIProvider(cluster.Name, updatedClusterBootstrap); err != nil {
r.Log.Error(err, fmt.Sprintf("unable to add labels to cni provider"))
return nil, err
}

r.Log.Info("updated clusterBootstrap", "clusterBootstrap", updatedClusterBootstrap)
return updatedClusterBootstrap, nil
}
Expand Down
55 changes: 1 addition & 54 deletions addons/pkg/util/clusterbootstrapclone/clusterbootstrapclone.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,7 @@ func (h *Helper) HandleExistingClusterBootstrap(clusterBootstrap *runtanzuv1alph
if err := h.AddClusterOwnerRef(cluster, providers, nil, nil); err != nil {
h.Logger.Error(err, fmt.Sprintf("unable to add cluster %s/%s as owner reference to providers", cluster.Namespace, cluster.Name))
}

if err := h.AddPackageLabelForCNIProvider(cluster.Name, clusterBootstrap); err != nil {
h.Logger.Error(err, fmt.Sprintf("unable to add labels to cni provider"))
return nil, err
}
h.Logger.Info("patched labels for cni provider.")


clusterBootstrap.OwnerReferences = []metav1.OwnerReference{
{
APIVersion: clusterapiv1beta1.GroupVersion.String(),
Expand Down Expand Up @@ -1090,31 +1084,6 @@ func (h *Helper) AddClusterOwnerRefToExistingProviders(cluster *clusterapiv1beta
return nil
}

// AddPackageLabelForCNIProvider patch the missing labels for AntreaConfig(cni config) when it's related to
// an existing clusterboostrap. To make antreaconfig works with old versions, it relies on the package label now.
func (h *Helper) AddPackageLabelForCNIProvider(clusterName string, clusterBootstrap *runtanzuv1alpha3.ClusterBootstrap) error {
cni := clusterBootstrap.Spec.CNI
if cni != nil {
providers, err := h.getListOfExistingProviders(clusterBootstrap)
if err != nil {
return err
}
for _, p := range providers {
if cni.ValuesFrom != nil && cni.ValuesFrom.ProviderRef != nil && p.GetKind() == cni.ValuesFrom.ProviderRef.Kind {
labels := p.GetLabels()
if labels == nil {
labels = map[string]string{}
}
labels[addontypes.PackageNameLabel] = util.ParseStringForLabel(cni.RefName)
labels[addontypes.ClusterNameLabel] = clusterName
return h.setLabels(labels, p)
}
}

}
return nil
}

// AddClusterOwnerRef adds cluster as an owner reference to the children with given controller and blockownerdeletion settings
func (h *Helper) AddClusterOwnerRef(cluster *clusterapiv1beta1.Cluster, children []*unstructured.Unstructured, controller, blockownerdeletion *bool) error {
ownerRef := metav1.OwnerReference{
Expand Down Expand Up @@ -1146,28 +1115,6 @@ func ownedByDifferentCluster(k8SObject *unstructured.Unstructured, cluster *clus
return ""
}

func (h *Helper) setLabels(labels map[string]string, child *unstructured.Unstructured) error {
gvr, err := h.GVRHelper.GetGVR(child.GroupVersionKind().GroupKind())
if err != nil {
h.Logger.Error(err, fmt.Sprintf("unable to get GVR of %s/%s", child.GetNamespace(), child.GetName()))
return err
}

patchObj := unstructured.Unstructured{}
patchObj.SetLabels(labels)
patchData, err := patchObj.MarshalJSON()
if err != nil {
h.Logger.Error(err, fmt.Sprintf("unable to patch provider %s/%s", child.GetNamespace(), child.GetName()), "gvr", gvr)
return err
}
_, err = h.DynamicClient.Resource(*gvr).Namespace(child.GetNamespace()).Patch(h.Ctx, child.GetName(), types.MergePatchType, patchData, metav1.PatchOptions{})
if err != nil {
h.Logger.Error(err, fmt.Sprintf("unable to patch provider %s/%s", child.GetNamespace(), child.GetName()), "gvr", gvr)
}
return err

}

func (h *Helper) setOwnerRef(ownerRef *metav1.OwnerReference, children []*unstructured.Unstructured) error {
for _, child := range children {
gvr, err := h.GVRHelper.GetGVR(child.GroupVersionKind().GroupKind())
Expand Down

0 comments on commit 027f934

Please sign in to comment.