Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions controllers/argocd_metrics_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,23 @@ func (r *ArgoCDMetricsReconciler) Reconcile(ctx context.Context, request reconci
}

const clusterMonitoringLabel = "openshift.io/cluster-monitoring"
labelVal, exists := namespace.Labels[clusterMonitoringLabel]
const userDefinedMonitoringLabel = "openshift.io/user-monitoring"
var labelVal, monitoringLabel string
var exists bool
if strings.HasPrefix(namespace.Name, "openshift-") {
labelVal, exists = namespace.Labels[clusterMonitoringLabel]
monitoringLabel = clusterMonitoringLabel
} else {
labelVal, exists = namespace.Labels[userDefinedMonitoringLabel]
monitoringLabel = userDefinedMonitoringLabel
}

if argocd.Spec.Monitoring.DisableMetrics == nil || !*argocd.Spec.Monitoring.DisableMetrics {
if !exists || labelVal != "true" {
if namespace.Labels == nil {
namespace.Labels = make(map[string]string)
}
namespace.Labels[clusterMonitoringLabel] = "true"
namespace.Labels[monitoringLabel] = "true"
err = r.Client.Update(ctx, &namespace)
if err != nil {
reqLogger.Error(err, "Error updating namespace",
Expand Down Expand Up @@ -178,7 +187,7 @@ func (r *ArgoCDMetricsReconciler) Reconcile(ctx context.Context, request reconci
}
} else {
if exists {
namespace.Labels[clusterMonitoringLabel] = "false"
namespace.Labels[monitoringLabel] = "false"
err = r.Client.Update(ctx, &namespace)
if err != nil {
reqLogger.Error(err, "Error updating namespace",
Expand Down
17 changes: 10 additions & 7 deletions controllers/argocd_metrics_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,19 @@ func newMetricsReconciler(t *testing.T, namespace, name string, disableMetrics *

func TestReconcile_add_namespace_label(t *testing.T) {
testCases := []struct {
instanceName string
namespace string
instanceName string
namespace string
expectedLabel string
}{
{
instanceName: argoCDInstanceName,
namespace: "openshift-gitops",
instanceName: argoCDInstanceName,
namespace: "openshift-gitops",
expectedLabel: "openshift.io/cluster-monitoring",
},
{
instanceName: "instance-two",
namespace: "namespace-two",
instanceName: "instance-two",
namespace: "namespace-two",
expectedLabel: "openshift.io/user-monitoring",
},
}
for _, tc := range testCases {
Expand All @@ -102,7 +105,7 @@ func TestReconcile_add_namespace_label(t *testing.T) {
ns := corev1.Namespace{}
err = r.Client.Get(context.TODO(), types.NamespacedName{Name: tc.namespace}, &ns)
assert.NilError(t, err)
value := ns.Labels["openshift.io/cluster-monitoring"]
value := ns.Labels[tc.expectedLabel]
assert.Equal(t, value, "true")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ commands:
- script: |
api_server=$(oc get routes -n openshift-gitops --field-selector metadata.name=openshift-gitops-server -o jsonpath="{.items[*]['spec.host']}")
password=$(oc get secret openshift-gitops-cluster -n openshift-gitops -o jsonpath='{.data.admin\.password}' | base64 -d)
output=$(argocd login $api_server --username admin --password $password --insecure)
output=$(argocd login $api_server --username admin --password $password --insecure --skip-test-tls))

if ! [[ "${output}" =~ "'admin:login' logged in successfully" ]]; then
if [[ "${output}" == *"rpc error: code = Unknown desc = server.secretkey is missing" ]]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ commands:
api_server=$(oc get routes -n openshift-gitops --field-selector metadata.name=openshift-gitops-server -o jsonpath="{.items[*]['spec.host']}")
password=$(oc get secret openshift-gitops-cluster -n openshift-gitops -o jsonpath='{.data.admin\.password}' | base64 -d)

output=$(argocd login $api_server --username admin --password $password --insecure)
output=$(argocd login $api_server --username admin --password $password --insecure --skip-test-tls)

if ! [[ "${output}" =~ "'admin:login' logged in successfully" ]]; then
exit 1
Expand Down