Skip to content

Commit

Permalink
Fix test chart when not using envFrom
Browse files Browse the repository at this point in the history
Signed-off-by: Pete Wall <pete.wall@grafana.com>
  • Loading branch information
petewall committed Oct 29, 2024
1 parent 4100339 commit 33889be
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 1 deletion.
14 changes: 14 additions & 0 deletions charts/k8s-monitoring-test/schema-mods/test-definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@
"PROFILECLI_PASS": {"type": "string"}
}
},
"envFrom": {
"type": "array",
"items": {
"type": "object",
"properties": {
"secretKeyRef": {
"type": "object",
"properties": {
"name": {"type": "string"}
}
}
}
}
},
"queries": {
"type": "array",
"items": {"$ref": "#/definitions/query"}
Expand Down
4 changes: 3 additions & 1 deletion charts/k8s-monitoring-test/templates/tests/test-pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ spec:
done
exit 1
envFrom:
{{ (index $test "envFrom") | toYaml | indent 8 }}
{{- if hasKey $test "env" }}
- secretRef:
name: {{ include "k8s-monitoring-test.fullname" $ }}-{{ $i }}
{{- end }}
{{- if hasKey $test "envFrom" }}
{{ (index $test "envFrom") | toYaml | indent 8 }}
{{- end }}
volumeMounts:
- name: queries
Expand Down
80 changes: 80 additions & 0 deletions charts/k8s-monitoring-test/tests/secret_sources_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# yamllint disable rule:document-start rule:line-length rule:trailing-spaces
suite: Various methods for loading secrets
templates:
- secret.yaml
- tests/test-pod.yaml
tests:
- it: creates its own secret when env is set
set:
tests:
- env:
PROMETHEUS_URL: http://prometheus.monitoring.svc.cluster.local:9090
PROMETHEUS_USER: prometheus
PROMETHEUS_PASSWORD: prompassword
queries:
- query: kube_node_info
type: promql
asserts:
- template: secret.yaml
isKind:
of: Secret
- template: secret.yaml
equal:
path: stringData["PROMETHEUS_URL"]
value: http://prometheus.monitoring.svc.cluster.local:9090
- template: tests/test-pod.yaml
hasDocuments:
count: 1
- template: tests/test-pod.yaml
equal:
path: spec.containers[0].envFrom[0].secretRef.name
value: RELEASE-NAME-k8s-monitoring-test-0
- it: does not create a secret when only using envFrom
set:
tests:
- envFrom:
- secretRef:
name: grafana-cloud-credentials
queries:
- query: kube_node_info
type: promql
asserts:
- template: tests/test-pod.yaml
hasDocuments:
count: 1
- template: tests/test-pod.yaml
equal:
path: spec.containers[0].envFrom[0].secretRef.name
value: grafana-cloud-credentials
- it: uses both
set:
tests:
- env:
PROMETHEUS_URL: http://prometheus.monitoring.svc.cluster.local:9090
PROMETHEUS_USER: prometheus
PROMETHEUS_PASSWORD: prompassword
envFrom:
- secretRef:
name: grafana-cloud-credentials
queries:
- query: kube_node_info
type: promql
asserts:
- template: secret.yaml
isKind:
of: Secret
- template: secret.yaml
equal:
path: stringData["PROMETHEUS_URL"]
value: http://prometheus.monitoring.svc.cluster.local:9090
- template: tests/test-pod.yaml
hasDocuments:
count: 1
- template: tests/test-pod.yaml
equal:
path: spec.containers[0].envFrom[0].secretRef.name
value: RELEASE-NAME-k8s-monitoring-test-0
- template: tests/test-pod.yaml
equal:
path: spec.containers[0].envFrom[1].secretRef.name
value: grafana-cloud-credentials
16 changes: 16 additions & 0 deletions charts/k8s-monitoring-test/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,22 @@
}
}
},
"envFrom": {
"type": "array",
"items": {
"type": "object",
"properties": {
"secretKeyRef": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
}
}
}
},
"queries": {
"type": "array",
"items": {
Expand Down

0 comments on commit 33889be

Please sign in to comment.