Skip to content

Commit

Permalink
Merge pull request #295 from ctria/ignore_label
Browse files Browse the repository at this point in the history
Added a label to ignore clusters.
  • Loading branch information
dntosas authored Nov 18, 2024
2 parents 4b6e9a0 + be49aa2 commit 36834fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions controllers/argo_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions controllers/capi2argo_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 36834fb

Please sign in to comment.