Skip to content

Commit

Permalink
misc modifications
Browse files Browse the repository at this point in the history
Signed-off-by: Raghavi Shirur <[email protected]>
  • Loading branch information
raghavi101 committed Oct 10, 2023
1 parent a73caac commit e7260c1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
6 changes: 2 additions & 4 deletions controllers/argocd/argocd_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type ReconcileArgoCD struct {
ManagedNamespaces *corev1.NamespaceList
// Stores a list of SourceNamespaces as values
ManagedSourceNamespaces map[string]string
// Stores label selector to use to reconcile a subset of ArgoCD
// Stores label selector used to reconcile a subset of ArgoCD
LabelSelector string
}

Expand Down Expand Up @@ -107,8 +107,6 @@ func (r *ReconcileArgoCD) Reconcile(ctx context.Context, request ctrl.Request) (
// Error reading the object - requeue the request.
return reconcile.Result{}, err
}
//debug line
fmt.Println(r.LabelSelector)

// Fetch labelSelector from r.LabelSelector (command-line option)
labelSelector, err := labels.Parse(r.LabelSelector)
Expand All @@ -118,7 +116,7 @@ func (r *ReconcileArgoCD) Reconcile(ctx context.Context, request ctrl.Request) (
}
// Match the value of labelSelector from ReconcileArgoCD to labels from the argocd instance
if !labelSelector.Matches(labels.Set(argocd.Labels)) {
reqLogger.Info(fmt.Sprintf("the ArgoCD instance '%s' does not match the label selector '%s' and skipping for reconcillation", request.NamespacedName, r.LabelSelector))
reqLogger.Info(fmt.Sprintf("the ArgoCD instance '%s' does not match the label selector '%s' and skipping for reconciliation", request.NamespacedName, r.LabelSelector))
return reconcile.Result{}, fmt.Errorf("Error: failed to reconcile ArgoCD instance: '%s'", request.NamespacedName)
}

Expand Down
2 changes: 1 addition & 1 deletion docs/usage/environment_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The following environment variables are available in `argocd-operator`:
| `CONTROLLER_CLUSTER_ROLE` | none | Administrators can configure a common cluster role for all the managed namespaces in role bindings for the Argo CD application controller with this environment variable. Note: If this environment variable contains custom roles, the Operator doesn't create the default admin role. Instead, it uses the existing custom role for all managed namespaces. |
| `SERVER_CLUSTER_ROLE` | none | Administrators can configure a common cluster role for all the managed namespaces in role bindings for the Argo CD server with this environment variable. Note: If this environment variable contains custom roles, the Operator doesn’t create the default admin role. Instead, it uses the existing custom role for all managed namespaces. |
| `REMOVE_MANAGED_BY_LABEL_ON_ARGOCD_DELETION` | false | When an Argo CD instance is deleted, namespaces managed by that instance (via the `argocd.argoproj.io/managed-by` label ) will retain the label by default. Users can change this behavior by setting the environment variable `REMOVE_MANAGED_BY_LABEL_ON_ARGOCD_DELETION` to `true` in the Subscription. |
| `ARGOCD_LABEL_SELECTOR` | none | The argocd-operator can be labelled (eg: `export ARGOCD_LABEL_SELECTOR=foo=bar`). Follwoing this, the argocd instances can be matched with the same label like so `kubectl label argocd test1 foo=bar -n test-argocd` which will facilitate the reconciliattion of one or more argocd instances. This will enable each controller instance to be tailored to oversee only the corresponding ArgoCD instances identified by the label selector. |
| `ARGOCD_LABEL_SELECTOR` | none | The label selector can be set on argocd-opertor by exporting `ARGOCD_LABEL_SELECTOR` (eg: `export ARGOCD_LABEL_SELECTOR=foo=bar`). The labels can be added to the argocd instances using the command `kubectl label argocd test1 foo=bar -n test-argocd`. This will enable the operator instance to be tailored to oversee only the corresponding ArgoCD instances having the matching label selector. |

Custom Environment Variables are supported in `applicationSet`, `controller`, `notifications`, `repo` and `server` components. For example:

Expand Down
5 changes: 2 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ func main() {
var enableLeaderElection bool
var probeAddr string
var labelSelectorFlag string

flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&metricsAddr, "metrics-bind-address", fmt.Sprintf(":%d", common.OperatorMetricsPort), "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.StringVar(&labelSelectorFlag, "label-selector", env.StringFromEnv(common.ArgoCDLabelSelectorKey, common.ArgoCDDefaultLabelSelector), "The label selector is used to map to a subset of ArgoCD instances to reconcile")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
Expand All @@ -101,7 +100,7 @@ func main() {

// Check the label selector format eg. "foo=bar"
if _, err := labels.Parse(labelSelectorFlag); err != nil {
setupLog.Info("error parsing the labelSelector '%s'.", labelSelectorFlag)
setupLog.Error(err, "error parsing the labelSelector '%s'.", labelSelectorFlag)
os.Exit(1)
}
setupLog.Info(fmt.Sprintf("Watching labelselector \"%s\"", labelSelectorFlag))
Expand Down

0 comments on commit e7260c1

Please sign in to comment.