Skip to content

Commit

Permalink
further work on the test chart
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 3, 2024
1 parent d691ffc commit ee08902
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 57 deletions.
27 changes: 17 additions & 10 deletions charts/k8s-monitoring-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ A Helm chart for testing the Kubernetes Monitoring Helm chart

## Values

### Test settings

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| attempts | int | `3` | Number of times to retry the test on failure. |
| delay | int | `60` | Delay, in seconds, between test runs. |
| initialDelay | int | `0` | Initial delay, in seconds, before starting the first test run. |

### General settings

| Key | Type | Default | Description |
Expand All @@ -30,27 +38,26 @@ A Helm chart for testing the Kubernetes Monitoring Helm chart

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| image.image | string | `"grafana/k8s-monitoring-test"` | Test job image repository. |
| image.pullSecrets | list | `[]` | Optional set of image pull secrets. |
| image.registry | string | `"ghcr.io"` | Test job image registry. |
| image.tag | string | `""` | Test job image tag. Default is the chart version. |
| image.registry | string | `"ghcr.io"` | Test pod image registry. |
| image.repository | string | `"grafana/k8s-monitoring-test"` | Test pod image repository. |
| image.tag | string | `""` | Test pod image tag. Default is the chart version. |

### Job settings

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| job.attempts | int | `10` | How many times to attempt the test job. |
| job.extraAnnotations | object | `{}` | Extra annotations to add to the test job. |
| job.extraLabels | object | `{}` | Extra labels to add to the test job. |
| job.nodeSelector | object | `{"kubernetes.io/os":"linux"}` | nodeSelector to apply to the test job. |
| job.serviceAccount | object | `{"name":""}` | Service Account to use for the test job. |
| job.tolerations | list | `[]` | Tolerations to apply to the test job. |
| pod.extraAnnotations | object | `{}` | Extra annotations to add to the test runner pods. |
| pod.extraLabels | object | `{}` | Extra labels to add to the test runner pods. |
| pod.nodeSelector | object | `{"kubernetes.io/os":"linux"}` | nodeSelector to apply to the test runner pods. |
| pod.serviceAccount | object | `{"name":""}` | Service Account to use for the test runner pods. |
| pod.tolerations | list | `[]` | Tolerations to apply to the test runner pods. |

### Tests

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| tests | list | `[]` | The tests to run |
| tests | list | `[]` | The tests to run. Each should contain an "env" object and a "queries" list. |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.14.2](https://github.com/norwoodj/helm-docs/releases/v1.14.2)
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ metadata:
app.kubernetes.io/instance: {{ $.Release.Name | quote }}
app.kubernetes.io/version: {{ $.Chart.AppVersion }}
helm.sh/chart: "{{ $.Chart.Name }}-{{ $.Chart.Version }}"
{{- range $key, $val := $.Values.job.extraLabels }}
{{- range $key, $val := $.Values.pod.extraLabels }}
{{ $key }}: {{ $val | quote }}
{{- end}}
annotations:
"helm.sh/hook": test
"helm.sh/hook-delete-policy": before-hook-creation
"helm.sh/hook-weight": "0"
{{- range $key, $val := $.Values.job.extraAnnotations }}
{{- range $key, $val := $.Values.pod.extraAnnotations }}
{{ $key }}: {{ $val | quote }}
{{- end}}
spec:
{{- if $.Values.job.serviceAccount.name }}
serviceAccountName: {{ $.Values.job.serviceAccount.name }}
{{- if $.Values.pod.serviceAccount.name }}
serviceAccountName: {{ $.Values.pod.serviceAccount.name }}
{{- end }}
{{- if or $.Values.global.image.pullSecrets $.Values.image.pullSecrets }}
imagePullSecrets:
Expand All @@ -33,18 +33,34 @@ spec:
{{- end }}
{{- end }}
restartPolicy: Never
{{- with $.Values.job.nodeSelector }}
{{- with $.Values.pod.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with $.Values.job.tolerations }}
{{- with $.Values.pod.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if $.Values.initialDelay }}
initContainers:
- name: wait
image: "{{ $.Values.global.image.registry | default $.Values.image.registry }}/{{ $.Values.image.repository }}:{{ $.Values.image.tag | default $.Chart.Version }}"
command: ["bash", "-c", "sleep {{ $.Values.initialDelay | int }}"]
{{- end }}
containers:
- name: query-test
image: "{{ $.Values.global.image.registry | default $.Values.image.registry }}/{{ $.Values.image.image }}:{{ $.Values.image.tag | default $.Chart.Version }}"
command: ["bash", "-c", "/etc/bin/query-test.sh /etc/test/queries.json"]
image: "{{ $.Values.global.image.registry | default $.Values.image.registry }}/{{ $.Values.image.repository }}:{{ $.Values.image.tag | default $.Chart.Version }}"
command:
- bash
- -c
- |
for i in $(seq 1 {{ $.Values.attempts | int }}); do
echo "Running test... ($i/{{ $.Values.attempts | int }})"
if /etc/bin/query-test.sh /etc/test/queries.json; then
exit 0
fi
sleep {{ $.Values.delay | int }}
done
envFrom:
- secretRef:
name: {{ include "k8s-monitoring-test.fullname" $ }}-{{ $i }}
Expand Down
6 changes: 3 additions & 3 deletions charts/k8s-monitoring-test/tests/single_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ suite: Single test
templates:
- configmap.yaml
- secret.yaml
- tests/test-job.yaml
- tests/test-pod.yaml
tests:
- it: creates a single test Job with a ConfigMap and a Secret
- it: creates a single test Pod with a ConfigMap and a Secret
set:
tests:
- env:
Expand Down Expand Up @@ -47,6 +47,6 @@ tests:
equal:
path: stringData["PROMETHEUS_PASSWORD"]
value: prompassword
- template: tests/test-job.yaml
- template: tests/test-pod.yaml
hasDocuments:
count: 1
6 changes: 3 additions & 3 deletions charts/k8s-monitoring-test/tests/two_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ suite: Two tests
templates:
- configmap.yaml
- secret.yaml
- tests/test-job.yaml
- tests/test-pod.yaml
tests:
- it: creates two tests Jobs, each with a ConfigMap and a Secret
- it: creates two tests Pods, each with a ConfigMap and a Secret
set:
tests:
- env:
Expand Down Expand Up @@ -113,6 +113,6 @@ tests:
path: stringData["PROMETHEUS_PASSWORD"]
value: my-password

- template: tests/test-job.yaml
- template: tests/test-pod.yaml
hasDocuments:
count: 2
26 changes: 16 additions & 10 deletions charts/k8s-monitoring-test/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
"$schema": "http://json-schema.org/schema#",
"type": "object",
"properties": {
"attempts": {
"type": "integer"
},
"delay": {
"type": "integer"
},
"fullnameOverride": {
"type": "string"
},
Expand All @@ -24,26 +30,29 @@
"image": {
"type": "object",
"properties": {
"image": {
"type": "string"
},
"pullSecrets": {
"type": "array"
},
"registry": {
"type": "string"
},
"repository": {
"type": "string"
},
"tag": {
"type": "string"
}
}
},
"job": {
"initialDelay": {
"type": "integer"
},
"nameOverride": {
"type": "string"
},
"pod": {
"type": "object",
"properties": {
"attempts": {
"type": "integer"
},
"extraAnnotations": {
"type": "object"
},
Expand Down Expand Up @@ -71,9 +80,6 @@
}
}
},
"nameOverride": {
"type": "string"
},
"tests": {
"type": "array"
}
Expand Down
39 changes: 23 additions & 16 deletions charts/k8s-monitoring-test/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,60 @@ nameOverride: ""
# @section -- General settings
fullnameOverride: ""

# -- The tests to run
# -- The tests to run. Each should contain an "env" object and a "queries" list.
# @section -- Tests
tests: []

job:
# -- How many times to attempt the test job.
# @section -- Job settings
attempts: 10
# -- Initial delay, in seconds, before starting the first test run.
# @section -- Test settings
initialDelay: 0

# -- Number of times to retry the test on failure.
# @section -- Test settings
attempts: 3

# -- Delay, in seconds, between test runs.
# @section -- Test settings
delay: 60

# -- nodeSelector to apply to the test job.
pod:
# -- nodeSelector to apply to the test runner pods.
# @section -- Job settings
nodeSelector:
kubernetes.io/os: linux

# -- Extra annotations to add to the test job.
# -- Extra annotations to add to the test runner pods.
# @section -- Job settings
extraAnnotations: {}

# -- Extra labels to add to the test job.
# -- Extra labels to add to the test runner pods.
# @section -- Job settings
extraLabels: {}

# -- Tolerations to apply to the test job.
# -- Tolerations to apply to the test runner pods.
# @section -- Job settings
tolerations: []

# -- Service Account to use for the test job.
# -- Service Account to use for the test runner pods.
# @section -- Job settings
serviceAccount:
name: ""

image:
# -- Test job image registry.
# -- Test pod image registry.
# @section -- Image settings
registry: ghcr.io
# -- Test job image repository.
# -- Test pod image repository.
# @section -- Image settings
image: grafana/k8s-monitoring-test
# -- Test job image tag. Default is the chart version.
repository: grafana/k8s-monitoring-test
# -- Test pod image tag. Default is the chart version.
# @section -- Image settings
tag: ""
# -- Optional set of image pull secrets.
# @section -- Image settings
pullSecrets: []

## Global properties for image pulling override the values defined under `image.registry` and `configReloader.image.registry`.
## If you want to override only one image registry, use the specific fields but if you want to override them all, use `global.image.registry`
## Global properties for overriding the image registry and pull secrets.
global:
image:
# -- Global image registry to use if it needs to be overridden for some specific use cases (e.g local registries, custom images, ...)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
tests:
- env:
PROMETHEUS_URL: https://prometheus-server.prometheus.svc:9090/api/v1/query
PROMETHEUS_USERNAME: promuser
PROMETHEUS_PASSWORD: prometheuspassword
PROMETHEUS_USER: promuser
PROMETHEUS_PASS: prometheuspassword
LOKI_URL: http://loki.loki.svc:3100/loki/api/v1/query
LOKI_TENANTID: 1
LOKI_USERNAME: loki
LOKI_PASSWORD: lokipassword
LOKI_USER: loki
LOKI_PASS: lokipassword
queries:
- query: kubernetes_build_info{cluster="cluster-monitoring-feature-test", job="integrations/kubernetes/kubelet"}
type: promql
Expand All @@ -16,9 +16,12 @@ tests:
- query: count(kube_node_info{cluster="cluster-monitoring-feature-test", job="integrations/kubernetes/kube-state-metrics"})
type: promql
expect:
value: 2
value: 1
- query: node_exporter_build_info{cluster="cluster-monitoring-feature-test", job="integrations/node-exporter"}
type: promql

- query: count_over_time({cluster="cluster-monitoring-feature-test", job="integrations/kubernetes/eventhandler"}[1h])
type: logql

attempts: 3
delay: 30
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ destinations:
tenantId: "1"
auth:
type: basic
username: loki
password: lokipassword
username: promuser
password: prometheuspassword
tls:
insecureSkipVerify: true
- name: localLoki
type: loki
url: http://loki.loki.svc:3100/loki/api/v1/push
Expand Down

0 comments on commit ee08902

Please sign in to comment.