Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helm chart test for Alerts plugin #405

Merged
merged 19 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
2 changes: 1 addition & 1 deletion alerts/charts/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ maintainers:
name: alerts
sources:
- https://github.com/cloudoperators/greenhouse-extensions
version: 0.12.4
version: 0.12.5
ibakshay marked this conversation as resolved.
Show resolved Hide resolved
keywords:
- prometheus-alertmanager
dependencies:
Expand Down
62 changes: 62 additions & 0 deletions alerts/charts/templates/tests/test-alerts-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{- if .Values.testFramework.enabled -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-test
namespace: {{ .Release.Namespace }}
labels:
type: integration-test
annotations:
"helm.sh/hook": test
"helm.sh/hook-weight": "-5" # Installed and upgraded before the test pod
"helm.sh/hook-delete-policy": "before-hook-creation,hook-succeeded"
data:
run.sh: |-

#!/usr/bin/env bats

load "/usr/lib/bats/bats-detik/utils"
load "/usr/lib/bats/bats-detik/detik"

DETIK_CLIENT_NAME="kubectl"

@test "Verify successful deployment, service and running status of the {{ .Release.Name }}-operator pod" {
verify "there is 1 deployment named '{{ .Release.Name }}-operator'"
verify "there is 1 service named '{{ .Release.Name }}-operator'"
try "at most 2 times every 5s to get pods named '{{ .Release.Name }}-operator.*' and verify that '.status.phase' is 'running'"
}
@test "Verify that alertmanager is available and reconciled" {
try "at most 5 times every 5s to get alertmanagers named '{{ .Release.Name }}' and verify that '.status.conditions[0].status' is 'True'"
try "at most 5 times every 5s to get alertmanagers named '{{ .Release.Name }}' and verify that '.status.conditions[1].status' is 'True'"
}

{{- if .Values.alerts.alertmanager.ingress.enabled }}
@test "Verify that secret '{{ .Release.Namespace }}-monitoring-ca' is created when ingress is enabled" {
verify "there is 1 secret named '{{ .Release.Namespace }}-monitoring-ca'"
}
{{- end -}}

{{- if .Values.alerts.alertmanager.ingress.enabled }}
{{- if .Capabilities.APIVersions.Has "cert-manager.io/v1" }}
@test "Verify that issuer and certificate are created when ingress is enabled and cert-manager crd is available" {
verify "there is 1 issuer named '{{ .Release.Namespace }}-monitoring-issuer'"
verify "there is 1 certificate named '{{ .Release.Namespace }}-prometheus-auth'"
}
{{- end }}
{{- end }}

{{- if .Values.alerts.crds.enabled }}
@test "Verify creation of required custom resource definitions (CRDs) for {{ .Release.Name }}" {
verify "there is 1 customresourcedefinition named 'alertmanagerconfigs'"
verify "there is 1 customresourcedefinition named 'alertmanagers'"
verify "there is 1 customresourcedefinition named 'podmonitors'"
verify "there is 1 customresourcedefinition named 'probes'"
verify "there is 1 customresourcedefinition named 'prometheuses'"
verify "there is 1 customresourcedefinition named 'prometheusrules'"
verify "there is 1 customresourcedefinition named 'prometheusagents'"
verify "there is 1 customresourcedefinition named 'servicemonitors'"
verify "there is 1 customresourcedefinition named 'scrapeconfigs'"
verify "there is 1 customresourcedefinition named 'thanosrulers'"
}
{{- end }}
{{- end -}}
28 changes: 28 additions & 0 deletions alerts/charts/templates/tests/test-alerts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.testFramework.enabled -}}
apiVersion: v1
kind: Pod
metadata:
name: {{ .Release.Name }}-test
namespace: {{ .Release.Namespace }}
labels:
type: integration-test
annotations:
"helm.sh/hook": test
"helm.sh/hook-delete-policy": "before-hook-creation,hook-succeeded"
spec:
serviceAccountName: {{ .Release.Name }}-test
containers:
- name: bats-test
image: "{{ .Values.testFramework.image.registry}}/{{ .Values.testFramework.image.repository}}:{{ .Values.testFramework.image.tag }}"
imagePullPolicy: {{ .Values.testFramework.image.pullPolicy }}
command: ["bats", "-t", "/tests/run.sh"]
volumeMounts:
- name: tests
mountPath: /tests
readOnly: true
volumes:
- name: tests
configMap:
name: {{ .Release.Name }}-test
restartPolicy: Never
{{- end -}}
97 changes: 97 additions & 0 deletions alerts/charts/templates/tests/test-permissions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{{- if .Values.testFramework.enabled -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Release.Name }}-test
namespace: {{ .Release.Namespace }}
labels:
type: integration-test
{{- include "kube-prometheus-stack.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
"helm.sh/hook-weight": "-5"
"helm.sh/hook-delete-policy": "before-hook-creation,hook-succeeded"
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ .Release.Name }}-test
namespace: {{ .Release.Namespace }}
labels:
type: integration-test
{{- include "kube-prometheus-stack.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
"helm.sh/hook-weight": "-5"
"helm.sh/hook-delete-policy": "before-hook-creation,hook-succeeded"
rules:
- apiGroups: ["apps"]
resources: ["deployments", "statefulsets"]
verbs: ["get", "list"]
- apiGroups: [""]
resources: ["pods", "persistentvolumeclaims", "services", "secrets"]
verbs: ["get", "list"]
- apiGroups: ["monitoring.coreos.com"]
resources: ["prometheuses", "podmonitors", "alertmanagers"]
verbs: ["get", "list"]
- apiGroups: ["cert-manager.io"]
resources: ["issuers", "certificates"]
verbs: ["get", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ .Release.Name }}-test
namespace: {{ .Release.Namespace }}
labels:
type: integration-test
{{- include "kube-prometheus-stack.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
"helm.sh/hook-weight": "-5"
"helm.sh/hook-delete-policy": "before-hook-creation,hook-succeeded"
subjects:
- kind: ServiceAccount
name: {{ .Release.Name }}-test
namespace: {{ .Release.Namespace }}
roleRef:
kind: Role
name: {{ .Release.Name }}-test
apiGroup: rbac.authorization.k8s.io
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ .Release.Name }}-test
labels:
type: integration-test
{{- include "kube-prometheus-stack.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
"helm.sh/hook-weight": "-5"
"helm.sh/hook-delete-policy": "before-hook-creation,hook-succeeded"
rules:
- apiGroups: ["apiextensions.k8s.io"]
resources: ["customresourcedefinitions"]
verbs: ["get", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ .Release.Name }}-test
labels:
type: integration-test
{{- include "kube-prometheus-stack.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
"helm.sh/hook-weight": "-5"
"helm.sh/hook-delete-policy": "before-hook-creation,hook-succeeded"
subjects:
- kind: ServiceAccount
name: {{ .Release.Name }}-test
namespace: {{ .Release.Namespace }}
roleRef:
kind: ClusterRole
name: {{ .Release.Name }}-test
apiGroup: rbac.authorization.k8s.io
{{- end -}}
8 changes: 8 additions & 0 deletions alerts/charts/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,11 @@ alerts:
# matchers:
# - name: alertname
# matchType: "=~"

testFramework:
enabled: true
image:
registry: ghcr.io
repository: cloudoperators/greenhouse-extensions-integration-test
tag: main
imagePullPolicy: IfNotPresent
16 changes: 16 additions & 0 deletions alerts/ci/test-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
ibakshay marked this conversation as resolved.
Show resolved Hide resolved
# SPDX-License-Identifier: Apache-2.0

# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors


alerts:
alertmanager:

ingress:
enabled: true
hosts:
- dummy-host



ibakshay marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions alerts/plugindefinition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ kind: PluginDefinition
metadata:
name: alerts
spec:
version: 2.0.3
version: 2.0.4
ibakshay marked this conversation as resolved.
Show resolved Hide resolved
weight: 0
displayName: Alerts
description: The Alerts Plugin consists of both Prometheus Alertmanager and Supernova, the holistic alert management UI
Expand All @@ -15,7 +15,7 @@ spec:
helmChart:
name: alerts
repository: oci://ghcr.io/cloudoperators/greenhouse-extensions/charts
version: 0.12.4
version: 0.12.5
ibakshay marked this conversation as resolved.
Show resolved Hide resolved
uiApplication:
name: supernova
version: "latest"
Expand Down
Loading