From d1ed69f28ddbb85574e60bb73fdf3b51351e21d9 Mon Sep 17 00:00:00 2001 From: Nicolas Takashi Date: Sun, 24 Oct 2021 16:44:40 +0100 Subject: [PATCH] [FEAT] change gitignore and add helm chart --- .gitignore | 4 +- charts/gitana/.helmignore | 23 ++++ charts/gitana/Chart.yaml | 24 ++++ charts/gitana/templates/NOTES.txt | 0 charts/gitana/templates/_helpers.tpl | 68 ++++++++++++ charts/gitana/templates/deployment.yaml | 84 ++++++++++++++ charts/gitana/templates/role.yaml | 14 +++ charts/gitana/templates/rolebind.yaml | 11 ++ charts/gitana/templates/service.yaml | 15 +++ charts/gitana/templates/serviceaccount.yaml | 12 ++ charts/gitana/templates/servicemonitor.yaml | 23 ++++ .../templates/tests/test-connection.yaml | 15 +++ charts/gitana/values.yaml | 103 ++++++++++++++++++ 13 files changed, 393 insertions(+), 3 deletions(-) create mode 100644 charts/gitana/.helmignore create mode 100644 charts/gitana/Chart.yaml create mode 100644 charts/gitana/templates/NOTES.txt create mode 100644 charts/gitana/templates/_helpers.tpl create mode 100644 charts/gitana/templates/deployment.yaml create mode 100644 charts/gitana/templates/role.yaml create mode 100644 charts/gitana/templates/rolebind.yaml create mode 100644 charts/gitana/templates/service.yaml create mode 100644 charts/gitana/templates/serviceaccount.yaml create mode 100644 charts/gitana/templates/servicemonitor.yaml create mode 100644 charts/gitana/templates/tests/test-connection.yaml create mode 100644 charts/gitana/values.yaml diff --git a/.gitignore b/.gitignore index 39853c9..0b560be 100644 --- a/.gitignore +++ b/.gitignore @@ -214,6 +214,4 @@ $RECYCLE.BIN/ # Windows shortcuts *.lnk -# End of https://www.toptal.com/developers/gitignore/api/go,linux,windows,macos,visualstudiocode,jetbrains - -gitana \ No newline at end of file +# End of https://www.toptal.com/developers/gitignore/api/go,linux,windows,macos,visualstudiocode,jetbrains \ No newline at end of file diff --git a/charts/gitana/.helmignore b/charts/gitana/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/gitana/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/gitana/Chart.yaml b/charts/gitana/Chart.yaml new file mode 100644 index 0000000..24dbe72 --- /dev/null +++ b/charts/gitana/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: gitana +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 1.0.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/charts/gitana/templates/NOTES.txt b/charts/gitana/templates/NOTES.txt new file mode 100644 index 0000000..e69de29 diff --git a/charts/gitana/templates/_helpers.tpl b/charts/gitana/templates/_helpers.tpl new file mode 100644 index 0000000..ee2c4fa --- /dev/null +++ b/charts/gitana/templates/_helpers.tpl @@ -0,0 +1,68 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "gitana.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "gitana.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "gitana.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "gitana.labels" -}} +helm.sh/chart: {{ include "gitana.chart" . }} +{{ include "gitana.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "gitana.selectorLabels" -}} +app.kubernetes.io/name: {{ include "gitana.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "gitana.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "gitana.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} + +{{- define "dashboard.labels" -}} +{{- if .Values.flags.dashboard.labels }} +{{- range .Values.flags.dashboard.labels }}{{(print .name "=" .value ) }},{{- end }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/gitana/templates/deployment.yaml b/charts/gitana/templates/deployment.yaml new file mode 100644 index 0000000..fab6db2 --- /dev/null +++ b/charts/gitana/templates/deployment.yaml @@ -0,0 +1,84 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "gitana.fullname" . }} + labels: + {{- include "gitana.labels" . | nindent 4 }} +spec: + replicas: 1 + selector: + matchLabels: + {{- include "gitana.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "gitana.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "gitana.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + args: + - sync + - --log.level={{ .Values.flags.log.level }} + - --sync-timer={{ .Values.flags.syncTimer }} + {{- if .Values.flags.kubeconfig }} + - --kubeconfig={{ .Values.flags.kubeconfig }} + {{- end }} + {{- if .Values.flags.dashboard.folderAnnotation }} + - --dashboard.folder-annotation={{ .Values.flags.dashboard.folderAnnotation }} + {{- end }} + - --dashboard.labels={{- include "dashboard.labels" . | trimSuffix "," }} + - --namespace={{ .Values.flags.namespace }} + {{- if .Values.flags.repository.auth }} + - --repository.auth.user={{ .Values.flags.repository.auth }} + - --repository.auth.user={{ .Values.flags.repository.password }} + {{- end }} + - --repository.branch={{ .Values.flags.repository.branch }} + - --repository.path=/tmp/gitana/repository + - --repository.url={{ .Values.flags.repository.url }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 9754 + protocol: TCP + livenessProbe: + httpGet: + path: /-/health + port: http + readinessProbe: + httpGet: + path: /-/ready + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - mountPath: /tmp/gitana + name: gitana + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + volumes: + - name: gitana + emptyDir: {} diff --git a/charts/gitana/templates/role.yaml b/charts/gitana/templates/role.yaml new file mode 100644 index 0000000..135e042 --- /dev/null +++ b/charts/gitana/templates/role.yaml @@ -0,0 +1,14 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: {{ include "gitana.fullname" . }} +rules: + - apiGroups: [""] + resources: + - configmaps + verbs: + - create + - delete + - get + - list + - update diff --git a/charts/gitana/templates/rolebind.yaml b/charts/gitana/templates/rolebind.yaml new file mode 100644 index 0000000..465d5ae --- /dev/null +++ b/charts/gitana/templates/rolebind.yaml @@ -0,0 +1,11 @@ +kind: RoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: {{ include "gitana.fullname" . }} +subjects: +- kind: ServiceAccount + name: {{ include "gitana.serviceAccountName" . }} +roleRef: + kind: Role + name: {{ include "gitana.fullname" . }} + apiGroup: rbac.authorization.k8s.io diff --git a/charts/gitana/templates/service.yaml b/charts/gitana/templates/service.yaml new file mode 100644 index 0000000..4bbab68 --- /dev/null +++ b/charts/gitana/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "gitana.fullname" . }} + labels: + {{- include "gitana.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "gitana.selectorLabels" . | nindent 4 }} diff --git a/charts/gitana/templates/serviceaccount.yaml b/charts/gitana/templates/serviceaccount.yaml new file mode 100644 index 0000000..ab17b67 --- /dev/null +++ b/charts/gitana/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "gitana.serviceAccountName" . }} + labels: + {{- include "gitana.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/gitana/templates/servicemonitor.yaml b/charts/gitana/templates/servicemonitor.yaml new file mode 100644 index 0000000..ae370e8 --- /dev/null +++ b/charts/gitana/templates/servicemonitor.yaml @@ -0,0 +1,23 @@ +{{- if .Values.serviceMonitor.enabled }} +kind: ServiceMonitor +apiVersion: monitoring.coreos.com/v1 +metadata: + labels: + {{- include "gitana.labels" . | nindent 4 }} + name: {{ include "gitana.fullname" . }} +spec: + endpoints: + - port: http + {{- if .Values.metrics.serviceMonitor.interval }} + interval: {{ .Values.metrics.serviceMonitor.interval }} + {{- end }} + {{- if .Values.metrics.serviceMonitor.scrapeTimeout }} + scrapeTimeout: {{ .Values.metrics.serviceMonitor.scrapeTimeout }} + {{- end }} + namespaceSelector: + matchNames: + - {{ .Release.Namespace }} + selector: + matchLabels: + {{- include "gitana.selectorLabels" . | nindent 4 }} +{{- end}} \ No newline at end of file diff --git a/charts/gitana/templates/tests/test-connection.yaml b/charts/gitana/templates/tests/test-connection.yaml new file mode 100644 index 0000000..4c8c3da --- /dev/null +++ b/charts/gitana/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "gitana.fullname" . }}-test-connection" + labels: + {{- include "gitana.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "gitana.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/charts/gitana/values.yaml b/charts/gitana/values.yaml new file mode 100644 index 0000000..ba4926d --- /dev/null +++ b/charts/gitana/values.yaml @@ -0,0 +1,103 @@ +image: + repository: ntakashi/gitana + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: 0.1.0 + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: + readOnlyRootFilesystem: true + +service: + type: ClusterIP + port: 80 + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +# Prometheus Operator ServiceMonitor configuration +serviceMonitor: + + # if `true`, creates a Prometheus Operator ServiceMonitor + enabled: false + + # Interval at which metrics should be scraped. + # ref: https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#endpoint + interval: "" + + # Timeout after which the scrape is ended + # ref: https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#endpoint + scrapeTimeout: "" + +flags: + # (optional) absolute path to the kubeconfig file + kubeconfig: "" + + # namespace that will store the dashboard config map (default "default") + namespace: gitana + + # interval to sync dashboards (default 5m) + syncTimer: 5m + + log: + # log level (default "info") + level: info + + dashboard: + # dashboard folder annotation + # ref: https://github.com/grafana/helm-charts/tree/main/charts/grafana#configuration + # sidecar.dashboards.folderAnnotation + folderAnnotation: dashboard-folder + + # dashboard label selector (default "grafana_dashboard=nil") + # ref: https://github.com/grafana/helm-charts/tree/main/charts/grafana#configuration + # sidecar.dashboards.label + # sidecar.dashboards.labelValue + labels: + - name: grafana-dashboard + value: nil + + repository: + # repository branch (default "main") + branch: main + + # repository url + url: "https://github.com/nicolastakashi/poc" + + auth: {} + # username to perform authentication + # user: "" + # password to perform authentication + # password: