diff --git a/charts/bitbucket-bot/Chart.yaml b/charts/bitbucket-bot/Chart.yaml new file mode 100644 index 0000000..dcc5d91 --- /dev/null +++ b/charts/bitbucket-bot/Chart.yaml @@ -0,0 +1,17 @@ +apiVersion: v2 +description: A Helm chart to deploy Bitbucket Bot for Google Chats (Spaces) +type: application +maintainers: + - name: ialejandro + email: hello@ialejandro.rocks + url: https://ialejandro.rocks +name: bitbucket-bot +sources: + - https://github.com/devops-ia/bitbucket-bot +version: 1.0.0 +appVersion: "1.0.0" +home: https://github.com/devops-ia/bitbucket-bot +keywords: +- bitbucket +- bitbucket-bot +- google-chat diff --git a/charts/bitbucket-bot/README.md b/charts/bitbucket-bot/README.md new file mode 100644 index 0000000..aab9921 --- /dev/null +++ b/charts/bitbucket-bot/README.md @@ -0,0 +1,76 @@ +# bitbucket-bot + +A Helm chart to deploy Bitbucket Bot for Google Chats (Spaces) + +## Maintainers + +| Name | Email | Url | +| ---- | ------ | --- | +| ialejandro | | | + +## Prerequisites + +* Helm 3+ + +## Add repository + +```console +helm repo add devops-ia https://devops-ia.github.io/helm-charts +helm repo update +``` + +## Install Helm chart + +```console +helm install [RELEASE_NAME] devops-ia/bitbucket-bot +``` + +This install all the Kubernetes components associated with the chart and creates the release. + +_See [helm install](https://helm.sh/docs/helm/helm_install/) for command documentation._ + +## Uninstall Helm chart + +```console +# Helm +helm uninstall [RELEASE_NAME] +``` + +This removes all the Kubernetes components associated with the chart and deletes the release. + +_See [helm uninstall](https://helm.sh/docs/helm/helm_uninstall/) for command documentation._ + +## Configuration + +See [Customizing the chart before installing](https://helm.sh/docs/intro/using_helm/#customizing-the-chart-before-installing). To see all configurable options with comments: + +```console +helm show values devops-ia/bitbucket-bot +``` + +## Values + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| affinity | object | `{}` | Affinity for pod assignment | +| autoscaling | object | `{"enabled":false,"maxReplicas":100,"minReplicas":1,"targetCPUUtilizationPercentage":80}` | Autoscaling with CPU or memory utilization percentage | +| config | object | `{}` | Bitbucket Bot config | +| containerArgs | list | `[]` | Bitbucket Bot container arguments | +| fullnameOverride | string | `""` | String to fully override bitbucket-bot.fullname template | +| image | object | `{"pullPolicy":"IfNotPresent","repository":"devopsiaci/bitbucket-bot","tag":""}` | Image registry | +| imagePullSecrets | list | `[]` | Global Docker registry secret names as an array | +| ingress | object | `{"annotations":{},"className":"","enabled":false,"hosts":[{"host":"chart-example.local","paths":[{"path":"/","pathType":"ImplementationSpecific"}]}],"tls":[]}` | Ingress configuration to expose app | +| nameOverride | string | `""` | String to partially override bitbucket-bot.fullname template (will maintain the release name) | +| nodeSelector | object | `{}` | Node labels for pod assignment | +| podAnnotations | object | `{}` | Pod annotations | +| podSecurityContext | object | `{}` | To specify security settings for a Pod | +| replicaCount | int | `1` | Number of replicas | +| resources | object | `{}` | The resources limits and requested | +| securityContext | object | `{}` | Defines privilege and access control settings for a Pod or Container | +| service | object | `{"port":80,"targetPort":80,"type":"ClusterIP"}` | Kubernetes servide to expose Pod | +| service.port | int | `80` | Kubernetes Service port | +| service.targetPort | int | `80` | Pod expose port | +| service.type | string | `"ClusterIP"` | Kubernetes Service type. Allowed values: NodePort, LoadBalancer or ClusterIP | +| serviceAccount | object | `{"annotations":{},"create":true,"name":""}` | Enable creation of ServiceAccount | +| testConnection | bool | `false` | Enable livenessProbe and readinessProbe | +| tolerations | list | `[]` | Tolerations for pod assignment | \ No newline at end of file diff --git a/charts/bitbucket-bot/README.md.gotmpl b/charts/bitbucket-bot/README.md.gotmpl new file mode 100644 index 0000000..c5d3cff --- /dev/null +++ b/charts/bitbucket-bot/README.md.gotmpl @@ -0,0 +1,49 @@ +# {{ template "chart.name" . }} + +{{ template "chart.description" . }} + +{{ template "chart.maintainersSection" . }} + +## Prerequisites + +* Helm 3+ + +{{ template "chart.requirementsSection" . }} + +## Add repository + +```console +helm repo add devops-ia https://devops-ia.github.io/helm-charts +helm repo update +``` + +## Install Helm chart + +```console +helm install [RELEASE_NAME] devops-ia/{{ template "chart.name" . }} +``` + +This install all the Kubernetes components associated with the chart and creates the release. + +_See [helm install](https://helm.sh/docs/helm/helm_install/) for command documentation._ + +## Uninstall Helm chart + +```console +# Helm +helm uninstall [RELEASE_NAME] +``` + +This removes all the Kubernetes components associated with the chart and deletes the release. + +_See [helm uninstall](https://helm.sh/docs/helm/helm_uninstall/) for command documentation._ + +## Configuration + +See [Customizing the chart before installing](https://helm.sh/docs/intro/using_helm/#customizing-the-chart-before-installing). To see all configurable options with comments: + +```console +helm show values devops-ia/{{ template "chart.name" . }} +``` + +{{ template "chart.valuesSection" . }} \ No newline at end of file diff --git a/charts/bitbucket-bot/templates/NOTES.txt b/charts/bitbucket-bot/templates/NOTES.txt new file mode 100644 index 0000000..b0b14a1 --- /dev/null +++ b/charts/bitbucket-bot/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "bitbucket-bot.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "bitbucket-bot.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "bitbucket-bot.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "bitbucket-bot.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/charts/bitbucket-bot/templates/_helpers.tpl b/charts/bitbucket-bot/templates/_helpers.tpl new file mode 100644 index 0000000..81940fa --- /dev/null +++ b/charts/bitbucket-bot/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "bitbucket-bot.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 "bitbucket-bot.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 "bitbucket-bot.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "bitbucket-bot.labels" -}} +helm.sh/chart: {{ include "bitbucket-bot.chart" . }} +{{ include "bitbucket-bot.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "bitbucket-bot.selectorLabels" -}} +app.kubernetes.io/name: {{ include "bitbucket-bot.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "bitbucket-bot.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "bitbucket-bot.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/bitbucket-bot/templates/deployment.yaml b/charts/bitbucket-bot/templates/deployment.yaml new file mode 100644 index 0000000..b2a8ad0 --- /dev/null +++ b/charts/bitbucket-bot/templates/deployment.yaml @@ -0,0 +1,73 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "bitbucket-bot.fullname" . }} + labels: + {{- include "bitbucket-bot.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "bitbucket-bot.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "bitbucket-bot.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + args: + {{- if .Values.containerArgs }} + {{- range .Values.containerArgs }} + - {{ . }} + {{- end }} + {{- end }} + - -e + - URL={{ .Values.config.url }} + - -e + - TOKEN={{ .Values.config.token }} + ports: + - name: http + containerPort: {{ .Values.service.targetPort | default .Values.service.port }} + protocol: TCP + {{- if .Values.testConnection }} + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + {{- end }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/bitbucket-bot/templates/hpa.yaml b/charts/bitbucket-bot/templates/hpa.yaml new file mode 100644 index 0000000..53e6c62 --- /dev/null +++ b/charts/bitbucket-bot/templates/hpa.yaml @@ -0,0 +1,28 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "bitbucket-bot.fullname" . }} + labels: + {{- include "bitbucket-bot.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "bitbucket-bot.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/charts/bitbucket-bot/templates/ingress.yaml b/charts/bitbucket-bot/templates/ingress.yaml new file mode 100644 index 0000000..7653692 --- /dev/null +++ b/charts/bitbucket-bot/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "bitbucket-bot.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "bitbucket-bot.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/bitbucket-bot/templates/service.yaml b/charts/bitbucket-bot/templates/service.yaml new file mode 100644 index 0000000..db12c6b --- /dev/null +++ b/charts/bitbucket-bot/templates/service.yaml @@ -0,0 +1,31 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "bitbucket-bot.fullname" . }} + {{- with .Values.service.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} + labels: + {{- include "bitbucket-bot.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + {{- with .Values.service.clusterIP }} + clusterIP: {{ . }} + {{- end }} + {{- if eq "LoadBalancer" .Values.service.type }} + {{- with .Values.service.loadBalancerIP }} + loadBalancerIP: {{ . }} + {{- end }} + {{- with .Values.service.loadBalancerSourceRanges }} + loadBalancerSourceRanges: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- end }} + ports: + - port: {{ .Values.service.port }} + targetPort: {{ .Values.service.targetPort | default .Values.service.port }} + protocol: TCP + name: http + selector: + {{- include "bitbucket-bot.selectorLabels" . | nindent 4 }} diff --git a/charts/bitbucket-bot/templates/serviceaccount.yaml b/charts/bitbucket-bot/templates/serviceaccount.yaml new file mode 100644 index 0000000..6a24d80 --- /dev/null +++ b/charts/bitbucket-bot/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "bitbucket-bot.serviceAccountName" . }} + labels: + {{- include "bitbucket-bot.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/bitbucket-bot/templates/tests/test-connection.yaml b/charts/bitbucket-bot/templates/tests/test-connection.yaml new file mode 100644 index 0000000..4a42dfc --- /dev/null +++ b/charts/bitbucket-bot/templates/tests/test-connection.yaml @@ -0,0 +1,17 @@ +{{- if .Values.testConnection }} +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "bitbucket-bot.fullname" . }}-test-connection" + labels: + {{- include "bitbucket-bot.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "bitbucket-bot.fullname" . }}:{{ .Values.service.targetPort | default .Values.service.port }}'] + restartPolicy: Never +{{- end }} \ No newline at end of file diff --git a/charts/bitbucket-bot/values.yaml b/charts/bitbucket-bot/values.yaml new file mode 100644 index 0000000..94a52ff --- /dev/null +++ b/charts/bitbucket-bot/values.yaml @@ -0,0 +1,113 @@ +# -- Number of replicas +replicaCount: 1 + +# -- Image registry +image: + repository: devopsiaci/bitbucket-bot + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +# -- String to partially override bitbucket-bot.fullname template (will maintain the release name) +nameOverride: "" + +# -- String to fully override bitbucket-bot.fullname template +fullnameOverride: "" + +# -- Global Docker registry secret names as an array +imagePullSecrets: [] + +# -- Enable creation of ServiceAccount +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: "" + +# -- Pod annotations +podAnnotations: {} + +# -- To specify security settings for a Pod +podSecurityContext: {} + # fsGroup: 2000 + +# -- Defines privilege and access control settings for a Pod or Container +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +# -- Bitbucket Bot container arguments +containerArgs: [] + # - '--bind=0.0.0.0:8080' + # - '--log-level=info' + +# -- Bitbucket Bot config +config: {} + # url: https://google-space-endpoint + # token: mysecrettoken + +# -- Kubernetes servide to expose Pod +service: + # -- Kubernetes Service type. Allowed values: NodePort, LoadBalancer or ClusterIP + type: ClusterIP + # -- Kubernetes Service port + port: 80 + # -- Pod expose port + targetPort: 80 + +# -- Enable livenessProbe and readinessProbe +testConnection: false + +# -- Ingress configuration to expose app +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +# -- The resources limits and requested +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 + +# -- Autoscaling with CPU or memory utilization percentage +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +# -- Node labels for pod assignment +nodeSelector: {} + +# -- Tolerations for pod assignment +tolerations: [] + +# -- Affinity for pod assignment +affinity: {}