diff --git a/.secrets.baseline b/.secrets.baseline index b841f0a1f..971a16d50 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -250,7 +250,7 @@ "filename": "dp-terraform/helm/rhacs-terraform/charts/observability/templates/01-operator-06-cr.yaml", "hashed_secret": "3e513f12b341ed3327bea645a728401b5d0f9ddb", "is_verified": false, - "line_number": 21 + "line_number": 22 } ], "dp-terraform/helm/rhacs-terraform/charts/secured-cluster/init-bundle.yaml": [ @@ -425,5 +425,5 @@ } ] }, - "generated_at": "2024-10-14T07:07:48Z" + "generated_at": "2024-10-17T08:34:41Z" } diff --git a/dp-terraform/helm/rhacs-terraform/charts/observability/templates/01-operator-01-namespace.yaml b/dp-terraform/helm/rhacs-terraform/charts/observability/templates/01-operator-01-namespace.yaml index 23ad47594..2b8b68256 100644 --- a/dp-terraform/helm/rhacs-terraform/charts/observability/templates/01-operator-01-namespace.yaml +++ b/dp-terraform/helm/rhacs-terraform/charts/observability/templates/01-operator-01-namespace.yaml @@ -2,3 +2,8 @@ apiVersion: v1 kind: Namespace metadata: name: {{ include "observability.namespace" . }} + annotations: + # Keep the namespace to retain PVCs after uninstall + helm.sh/resource-policy: keep + labels: + argocd.argoproj.io/managed-by: openshift-gitops diff --git a/dp-terraform/helm/rhacs-terraform/charts/observability/templates/01-operator-06-cr.yaml b/dp-terraform/helm/rhacs-terraform/charts/observability/templates/01-operator-06-cr.yaml index babb3858b..ef8cdac96 100644 --- a/dp-terraform/helm/rhacs-terraform/charts/observability/templates/01-operator-06-cr.yaml +++ b/dp-terraform/helm/rhacs-terraform/charts/observability/templates/01-operator-06-cr.yaml @@ -1,3 +1,4 @@ +{{- if .Values.customResourceEnabled }} apiVersion: observability.redhat.com/v1 kind: Observability metadata: @@ -101,3 +102,4 @@ spec: resources: requests: storage: {{ .Values.prometheus.resources.requests.storage | quote }} +{{- end }} diff --git a/dp-terraform/helm/rhacs-terraform/charts/observability/values.yaml b/dp-terraform/helm/rhacs-terraform/charts/observability/values.yaml index 3cbb434c8..f36de5f49 100644 --- a/dp-terraform/helm/rhacs-terraform/charts/observability/values.yaml +++ b/dp-terraform/helm/rhacs-terraform/charts/observability/values.yaml @@ -6,6 +6,7 @@ # https://github.com/redhat-developer/observability-operator/releases observabilityOperatorVersion: "v4.2.1" +customResourceEnabled: true github: repository: "https://api.github.com/repos/stackrox/rhacs-observability-resources/contents" tag: "master" diff --git a/dp-terraform/test/helm_template_test.go b/dp-terraform/test/helm_template_test.go index f095a540f..5fc6bf846 100644 --- a/dp-terraform/test/helm_template_test.go +++ b/dp-terraform/test/helm_template_test.go @@ -6,10 +6,12 @@ import ( "github.com/gruntwork-io/terratest/modules/helm" "github.com/gruntwork-io/terratest/modules/k8s" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) func TestHelmTemplate_FleetshardSyncDeployment_ServiceAccountTokenAuthType(t *testing.T) { @@ -277,3 +279,58 @@ func TestHelmTemplate_ObservabilityCR_blackboxExporterEnabled(t *testing.T) { }) } } + +func TestHelmTemplate_ObservabilityCR_enabled(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + enabled string + wantErr string + }{ + { + name: "should enable CR by default", + enabled: "true", + }, + { + name: "should not install CR when the value is disabled", + enabled: "false", + wantErr: "could not find template", + }, + { + name: "should install CR when the value is enabled", + enabled: "true", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + values := map[string]string{ + "secured-cluster.enabled": "false", + "fleetshardSync.managedDB.enabled": "false", + } + if tt.enabled != "" { + values["observability.customResourceEnabled"] = tt.enabled + } + + releaseName := "rhacs-terraform" + namespaceName := "rhacs" + helmChartPath, err := filepath.Abs("../helm/rhacs-terraform") + require.NoError(t, err) + + options := &helm.Options{ + SetValues: values, + KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), + } + + output, err := helm.RenderTemplateE(t, options, helmChartPath, releaseName, []string{"charts/observability/templates/01-operator-06-cr.yaml"}) + if tt.wantErr != "" { + assert.ErrorContainsf(t, err, tt.wantErr, "error = %v, wantErr = %q", err, tt.wantErr) + } else { + require.NoError(t, err) + var observability unstructured.Unstructured + helm.UnmarshalK8SYaml(t, output, &observability) // also asserts that there's no error + } + }) + } +}