From be49aa289f70e0b623a995173a3704a0a7ae66a2 Mon Sep 17 00:00:00 2001 From: Christos Triantafyllidis Date: Sat, 17 Aug 2024 03:29:40 +0100 Subject: [PATCH] Added a label to ignore clusters. --- controllers/argo_cluster.go | 13 +++++++++++++ controllers/capi2argo_reconciler.go | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/controllers/argo_cluster.go b/controllers/argo_cluster.go index 087a5a3b..90efbcd8 100644 --- a/controllers/argo_cluster.go +++ b/controllers/argo_cluster.go @@ -27,6 +27,7 @@ var ( const ( clusterTakeAlongKey = "take-along-label.capi-to-argocd." clusterTakenFromClusterKey = "taken-from-cluster-label.capi-to-argocd." + clusterIgnoreKey = "ignore-cluster.capi-to-argocd" ) // GetArgoCommonLabels holds a map of labels that reconciled objects must have. @@ -107,6 +108,18 @@ func extractTakeAlongLabel(key string) (string, error) { return "", nil } +// validateClusterIgnoreLabel returns true when the cluster has the clusterIgnoreKey label +func validateClusterIgnoreLabel(cluster *clusterv1.Cluster) bool { + clusterLabels := cluster.Labels + + for k := range clusterLabels { + if k == clusterIgnoreKey { + return true + } + } + return false +} + // buildTakeAlongLabels returns a list of valid take-along labels from a cluster func buildTakeAlongLabels(cluster *clusterv1.Cluster) (map[string]string, []string) { name := cluster.Name diff --git a/controllers/capi2argo_reconciler.go b/controllers/capi2argo_reconciler.go index ee2f1768..d828c222 100644 --- a/controllers/capi2argo_reconciler.go +++ b/controllers/capi2argo_reconciler.go @@ -120,6 +120,12 @@ func (r *Capi2Argo) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resul log.Info("Failed to get Cluster object", "error", err) } + // Check if the cluster has the ignore label + if validateClusterIgnoreLabel(clusterObject) { + log.Info("The cluster has label to be ignored, skipping...") + return ctrl.Result{}, nil + } + // Construct ArgoCluster from CapiCluster and CapiSecret.Metadata. argoCluster, err := NewArgoCluster(capiCluster, &capiSecret, clusterObject) if err != nil {