Skip to content

Commit

Permalink
ROX-26065: Observability subchart teardown (#2075)
Browse files Browse the repository at this point in the history
  • Loading branch information
kovayur authored Oct 17, 2024
1 parent 4ca077d commit 7213056
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -425,5 +425,5 @@
}
]
},
"generated_at": "2024-10-14T07:07:48Z"
"generated_at": "2024-10-17T08:34:41Z"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.customResourceEnabled }}
apiVersion: observability.redhat.com/v1
kind: Observability
metadata:
Expand Down Expand Up @@ -101,3 +102,4 @@ spec:
resources:
requests:
storage: {{ .Values.prometheus.resources.requests.storage | quote }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
57 changes: 57 additions & 0 deletions dp-terraform/test/helm_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
})
}
}

0 comments on commit 7213056

Please sign in to comment.