devops

Grafana 헬름 차트 분석하기 본문

DevOps/Opensource

Grafana 헬름 차트 분석하기

vata500 2023. 7. 9. 23:06
반응형

Prometheus 헬름 차트에 이어 이번에는 helm test 옵션이 있는 grafana 헬름 차트를 분석해보려고 한다.

Grafana Helm chart

# grafana helm repo

Chart.yaml
values.yaml
README.md
templates
  - NOTES.txt
  - _helpers.tpl
  - deployment.yaml
  - statefulset.yaml
  - clusterrole.yaml
  - tests (directory)

Grafana의 template에는 tests라는 디렉토리가 있다.

grafana helm chart의 template에 있는 tests 디렉토리

이 tests는 마치 헬스체크처럼 kubernetes cluster에 grafana가 정 작동하는지를 헬스체를 한다. 아래와 같이 여러 yaml 파일이 생성되어 있다.

tests 디렉토리의 yaml 파일들

이 테스트를 위해서는 배포 테스트를 위해 아래와 같은 명령어를 진행한다.

$ helm test { release name }

그럼 위 tests의 디렉토리의 yaml이 배포되어 test를 위한 pod가 생성된다. 이 pod는 grafana pod에 헬스체크하고는 바로 삭제된다. 뒤이어 helm test의 결과가 위 명령어에 이어서 터미널에 표시된다.

tests/test.yaml

{{- if .Values.testFramework.enabled }}
{{- $root := . }}
apiVersion: v1
kind: Pod
metadata:
  name: {{ include "grafana.fullname" . }}-test
  labels:
    {{- include "grafana.labels" . | nindent 4 }}
  annotations:
    "helm.sh/hook": test-success
    "helm.sh/hook-delete-policy": "before-hook-creation,hook-succeeded"
  namespace: {{ include "grafana.namespace" . }}
spec:
  serviceAccountName: {{ include "grafana.serviceAccountNameTest" . }}
  {{- with .Values.testFramework.securityContext }}
  securityContext:
    {{- toYaml . | nindent 4 }}
  {{- end }}
 ...
 
  containers:
    - name: {{ .Release.Name }}-test
      image: "{{ .Values.testFramework.image}}:{{ .Values.testFramework.tag }}"
      imagePullPolicy: "{{ .Values.testFramework.imagePullPolicy}}"
      command: ["/opt/bats/bin/bats", "-t", "/tests/run.sh"]
 ...

{{- if .Values.testFramework.enabled }}
- values.yaml에 testFrameworkf의 enabled가 true가 되면 helm install되면 tests의 yaml 파일들 모두 배포되는 것을 의미한다.

  annotations:
    "helm.sh/hook": test-success
- helm.sh/hook이 test-success로 annotation이 설정되면 helm install할 때 함께 배포되지 않고 helm test { release name } 을 통해서만 배포가 된다. test-success로 입력되어있나, 이는 이전 버전이며 현재 test만 설정해도 된다.

 

 

반응형
Comments