Skip to content

Commit 2511d7b

Browse files
committed
Added OLM scenario for label-selector kuttl tests and some minor changes
Signed-off-by: Raghavi Shirur <rshirur@redhat.com>
1 parent 8283fa2 commit 2511d7b

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

common/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const (
3232
// Default console plugin installation OCP version
3333
DefaultDynamicPluginStartOCPVersion = "4.15.0"
3434
// Label Selector is an env variable for ArgoCD instance reconcilliation.
35-
LabelSelector = "LABEL_SELECTOR"
35+
ArgoCDLabelSelector = "ARGOCD_LABEL_SELECTOR"
3636
// Default Label Selector is used when the Label Selector is not mentioned/empty.
3737
DefaultLabelSelector = ""
3838
)

config/default/manager_auth_proxy_patch.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ spec:
4646
- "--health-probe-bind-address=:8081"
4747
- "--metrics-bind-address=127.0.0.1:8080"
4848
- "--leader-elect"
49-
- "--label-selector"
5049
volumes:
5150
# Secret created by the service CA operator.
5251
# We assume that the Kubernetes service exposing the application's pods has the

main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"go.uber.org/zap/zapcore"
3030
_ "k8s.io/client-go/plugin/pkg/client/auth"
3131

32+
"k8s.io/apimachinery/pkg/labels"
3233
"k8s.io/apimachinery/pkg/runtime"
3334
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3435

@@ -88,7 +89,7 @@ func main() {
8889
var labelSelectorFlag string
8990
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
9091
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
91-
flag.StringVar(&labelSelectorFlag, "label-selector", env.StringFromEnv(common.LabelSelector, common.DefaultLabelSelector), "The label selector is used to map to a subset of ArgoCD instances to reconcile")
92+
flag.StringVar(&labelSelectorFlag, "label-selector", env.StringFromEnv(common.ArgoCDLabelSelector, common.DefaultLabelSelector), "The label selector is used to map to a subset of ArgoCD instances to reconcile")
9293
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
9394
"Enable leader election for controller manager. "+
9495
"Enabling this will ensure there is only one active controller manager.")
@@ -182,6 +183,12 @@ func main() {
182183
setupLog.Error(err, "unable to create controller", "controller", "Argo CD metrics")
183184
os.Exit(1)
184185
}
186+
// Check the label selector format eg. "foo=bar"
187+
if _, err := labels.Parse(labelSelectorFlag); err != nil {
188+
setupLog.Info("error parsing the labelSelector '%s'.", labelSelectorFlag)
189+
os.Exit(1)
190+
}
191+
setupLog.Info(fmt.Sprintf("Watching label-selector \"%s\"", labelSelectorFlag))
185192

186193
if err = (&argocdprovisioner.ReconcileArgoCD{
187194
Client: mgr.GetClient(),

test/openshift/e2e/sequential/1-105_validate_label_selector/01-add-label-selector.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ kind: TestStep
33
commands:
44
# patches the subscription to add label selector in argocd-operator
55
- script: |
6-
oc set env deployment openshift-gitops-operator-controller-manager -n openshift-gitops-operator ARGOCD_LABEL_SELECTOR=foo=bar -c manager
7-
- script: sleep 10
6+
if ! [ -z $NON_OLM ]; then
7+
oc set env deployment openshift-gitops-operator-controller-manager -n openshift-gitops-operator ARGOCD_LABEL_SELECTOR=foo=bar -c manager
8+
9+
elif [ -z $CI ]; then
810
11+
oc patch -n openshift-gitops-operator subscription openshift-gitops-operator \
12+
--type merge --patch '{"spec": {"config": {"env": [{"name": "ARGOCD_LABEL_SELECTOR", "value": "foo=bar"}]}}}'
13+
14+
else
15+
16+
oc patch -n openshift-gitops-operator subscription `subscription=gitops-operator- && oc get subscription --all-namespaces | grep $subscription | head -1 | awk '{print $2}'` \
17+
--type merge --patch '{"spec": {"config": {"env": [{"name": "ARGOCD_LABEL_SELECTOR", "value": "foo=bar"}]}}}'
18+
fi
19+
- script: sleep 120

test/openshift/e2e/sequential/1-105_validate_label_selector/07-remove-label-selector.yaml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,17 @@ kind: TestStep
33
commands:
44
# patches the subscription to remove label-selector from argocd-operator
55
- script: |
6-
oc set env deployment openshift-gitops-operator-controller-manager -n openshift-gitops-operator ARGOCD_LABEL_SELECTOR- -c manager
7-
- script: sleep 10
6+
if ! [ -z $NON_OLM ]; then
7+
8+
oc set env deployment openshift-gitops-operator-controller-manager -n openshift-gitops-operator ARGOCD_LABEL_SELECTOR- -c manager
9+
10+
elif [ -z $CI ]; then
11+
12+
oc patch -n openshift-gitops-operator subscription openshift-gitops-operator \
13+
--type json --patch '[{"op": "remove", "path": "/spec/config"}]'
14+
else
15+
16+
oc patch -n openshift-gitops-operator subscription `subscription=gitops-operator- && oc get subscription --all-namespaces | grep $subscription | head -1 | awk '{print $2}'` \
17+
--type json --patch '[{"op": "remove", "path": "/spec/config"}]'
18+
fi
19+
- script: sleep 120

0 commit comments

Comments
 (0)