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

Commit

Permalink
Matches addons config to cluster by owner reference
Browse files Browse the repository at this point in the history
allowing the name of addons config to be anything

controllers changed in this patch

- Calico CNI
- Antrea CNI
- Kapp controller
- CPI
- CSI
  • Loading branch information
Adolfo Duarte committed Nov 4, 2022
1 parent d0c3040 commit 83053ca
Show file tree
Hide file tree
Showing 47 changed files with 2,728 additions and 268 deletions.
2 changes: 1 addition & 1 deletion addons/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ metadata:
name: my-cluster
namespace: my-ns
annotations:
tkg.tanzu.vmware.com/add-missing-fields-from-tkr:v1.22.4
tkg.tanzu.vmware.com/add-missing-fields-from-tkr: v1.22.4
spec:
cni:
refName: calico*
Expand Down
29 changes: 13 additions & 16 deletions addons/controllers/antrea/antreaconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/source"

cutil "github.com/vmware-tanzu/tanzu-framework/addons/controllers/utils"
addonconfig "github.com/vmware-tanzu/tanzu-framework/addons/pkg/config"
"github.com/vmware-tanzu/tanzu-framework/addons/pkg/constants"
"github.com/vmware-tanzu/tanzu-framework/addons/pkg/util"
Expand Down Expand Up @@ -64,28 +65,24 @@ func (r *AntreaConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request
return ctrl.Result{}, err
}

annotations := antreaConfig.GetAnnotations()
if _, ok := annotations[constants.TKGAnnotationTemplateConfig]; ok {
log.Info(fmt.Sprintf("resource '%v' is a config template. Skipping reconciling", req.NamespacedName))
return ctrl.Result{}, nil // TODO (adduarte) this should return err not nil to use backoff algorithms.
}

// deep copy AntreaConfig to avoid issues if in the future other controllers where interacting with the same copy
antreaConfig = antreaConfig.DeepCopy()

// get the parent cluster name from owner reference
// if the owner reference doesn't exist, use the same name as config CRD
clusterNamespacedName := req.NamespacedName
cluster := &clusterapiv1beta1.Cluster{}
for _, owner := range antreaConfig.OwnerReferences {
if owner.Kind == constants.ClusterKind {
clusterNamespacedName.Name = owner.Name
break
}
}
cluster, err := cutil.GetOwnerCluster(ctx, r.Client, antreaConfig, req.Namespace, constants.AntreaDefaultRefName)

// verify that the cluster related to config is present
if err := r.Client.Get(ctx, clusterNamespacedName, cluster); err != nil {
if apierrors.IsNotFound(err) {
log.Info(fmt.Sprintf("Cluster '%s'not found in '%s'", clusterNamespacedName.Name, clusterNamespacedName.Namespace))
if err != nil {
if apierrors.IsNotFound(err) && cluster != nil {
log.Info(fmt.Sprintf("'%s/%s' is listed as owner reference but could not be found",
cluster.Namespace, cluster.Name))
return ctrl.Result{}, nil
}

log.Error(err, fmt.Sprintf("unable to fetch cluster '%s' in '%s'", clusterNamespacedName.Name, clusterNamespacedName.Namespace))
log.Error(err, "could not determine owner cluster")
return ctrl.Result{}, err
}

Expand Down
Loading

0 comments on commit 83053ca

Please # to comment.