Skip to content

Commit

Permalink
Merge pull request #1 from lablabs/dev
Browse files Browse the repository at this point in the history
feat(helm): add helm chart for bitbucket runners
  • Loading branch information
katapultcloud authored Oct 15, 2024
2 parents 2f74077 + 2007021 commit aaa26a9
Show file tree
Hide file tree
Showing 25 changed files with 811 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/helm-lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
check-latest: true

- name: Set up chart-testing
uses: helm/chart-testing-action@v2.4.0
uses: helm/chart-testing-action@v2.6.0

- name: Run chart-testing (list-changed)
id: list-changed
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# <$chart-name> Helm chart
# bitbucket-runner-autoscaler Helm chart

[<img src="https://lablabs.io/static/ll-logo.png" width=350px>](https://lablabs.io/)

Expand All @@ -7,9 +7,9 @@ We help companies build, run, deploy and scale software and infrastructure by em
---

## Description
<$chart-name> Helm chart.
[bitbucket-runner-autoscaler](https://bitbucket.org/bitbucketpipelines/runners-autoscaler/src/master/) Helm chart.

Check out [charts/<$chart-name>/README.md](charts/<$chart-name>/README.md) for more details about the chart.
Check out [charts/bitbucket-runner-autoscaler/README.md](charts/bitbucket-runner-autoscaler/README.md) for more details about the chart.

## Contributing and reporting issues
Feel free to create an issue in this repository if you have questions, suggestions or feature requests.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
apiVersion: v2
name: chart-name
description: chart-description
name: bitbucket-runner-autoscaler
description: Chart for deploying Bitbucket Runner Autoscaler.

type: application

version: 0.1.0

# Set appVersion if relevant for your chart
appVersion: "0.1.0"
appVersion: 3.7.0

maintainers:
- name: Labyrinth Labs
Expand Down
97 changes: 97 additions & 0 deletions charts/bitbucket-runner-autoscaler/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# bitbucket-runner-autoscaler

Chart for deploying Bitbucket Runner Autoscaler.

![Version: 0.1.0](https://img.shields.io/badge/Version-0.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 3.7.0](https://img.shields.io/badge/AppVersion-3.7.0-informational?style=flat-square)

## About
bitbucket-runner-autoscaler Helm chart

## Values

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| cleaner.affinity | object | `{}` | |
| cleaner.create | bool | `true` | |
| cleaner.image.pullPolicy | string | `"IfNotPresent"` | |
| cleaner.image.registry | string | `"docker.io"` | |
| cleaner.image.repository | string | `"bitbucketpipelines/runners-autoscaler"` | |
| cleaner.image.tag | string | `"3.7.0"` | |
| cleaner.nodeSelector | object | `{}` | |
| cleaner.pdb.enabled | bool | `false` | |
| cleaner.pdb.minAvailable | int | `1` | |
| cleaner.podLabels | object | `{}` | |
| cleaner.priorityClassName | string | `""` | |
| cleaner.replicas | int | `1` | |
| cleaner.tolerations | list | `[]` | |
| cleaner.topologySpreadConstraints | list | `[]` | |
| controller.affinity | object | `{}` | |
| controller.create | bool | `true` | |
| controller.image.pullPolicy | string | `"IfNotPresent"` | |
| controller.image.registry | string | `"docker.io"` | |
| controller.image.repository | string | `"bitbucketpipelines/runners-autoscaler"` | |
| controller.image.tag | string | `"3.7.0"` | |
| controller.nodeSelector | object | `{}` | |
| controller.pdb.enabled | bool | `false` | |
| controller.pdb.minAvailable | int | `1` | |
| controller.podLabels | object | `{}` | |
| controller.priorityClassName | string | `""` | |
| controller.replicas | int | `1` | |
| controller.tolerations | list | `[]` | |
| controller.topologySpreadConstraints | list | `[]` | |
| credentialsSecret.bitbucketAppPassword | string | `""` | |
| credentialsSecret.bitbucketUsername | string | `""` | |
| credentialsSecret.create | bool | `true` | |
| credentialsSecret.name | string | `""` | |
| extraManifests | list | `[]` | |
| fullnameOverride | string | `""` | |
| global.commonLabels | object | `{}` | |
| global.nodeSelector | object | `{}` | |
| global.tolerations | list | `[]` | |
| nameOverride | string | `""` | |
| rbac.create | bool | `true` | |
| runner.affinity | object | `{}` | |
| runner.config.constants.default_sleep_time_runner_delete | int | `5` | |
| runner.config.constants.default_sleep_time_runner_setup | int | `10` | |
| runner.config.constants.runner_api_polling_interval | int | `600` | |
| runner.config.constants.runner_cool_down_period | int | `300` | |
| runner.config.groups[0].labels[0] | string | `"my.group"` | |
| runner.config.groups[0].name | string | `"default"` | |
| runner.config.groups[0].namespace | string | `"bitbucket-runner"` | |
| runner.config.groups[0].parameters.max | int | `10` | |
| runner.config.groups[0].parameters.min | int | `1` | |
| runner.config.groups[0].parameters.scale_down_multiplier | float | `0.5` | |
| runner.config.groups[0].parameters.scale_down_threshold | float | `0.2` | |
| runner.config.groups[0].parameters.scale_up_multiplier | float | `1.5` | |
| runner.config.groups[0].parameters.scale_up_threshold | float | `0.5` | |
| runner.config.groups[0].strategy | string | `"percentageRunnersIdle"` | |
| runner.config.groups[0].workspace | string | `""` | |
| runner.dind.image.pullPolicy | string | `"IfNotPresent"` | |
| runner.dind.image.registry | string | `"docker.io"` | |
| runner.dind.image.repository | string | `"docker"` | |
| runner.dind.image.tag | string | `"dind"` | |
| runner.image.pullPolicy | string | `"IfNotPresent"` | |
| runner.image.registry | string | `"docker-public.packages.atlassian.com"` | |
| runner.image.repository | string | `"sox/atlassian/bitbucket-pipelines-runner"` | |
| runner.image.tag | string | `"1"` | |
| runner.nodeSelector | object | `{}` | |
| runner.priorityClassName | string | `""` | |
| runner.serviceAccount.annotations | object | `{}` | |
| runner.serviceAccount.create | bool | `true` | |
| runner.serviceAccount.name | string | `""` | |
| runner.template.job | string | `"apiVersion: batch/v1\nkind: Job\nmetadata:\n name: runner-<%runner_uuid%> # mandatory, don't modify\nspec:\n template:\n metadata:\n labels:\n customer: shared\n account_uuid: <%account_uuid%> # mandatory, don't modify\n runner_uuid: <%runner_uuid%> # mandatory, don't modify\n {%- if repository_uuid %}\n repository_uuid: <%repository_uuid%> # mandatory, don't modify\n {%- endif %}\n runner_namespace: <%runner_namespace%> # mandatory, don't modify\n spec:\n tolerations: {{ include \"bitbucketRunnerAutoscaler.runnerTolerations\" . | nindent 16 }}\n nodeSelector: {{ include \"bitbucketRunnerAutoscaler.runnerNodeSelector\" . | nindent 16 }}\n topologySpreadConstraints: {{ .Values.runner.topologySpreadConstraints | toYaml | nindent 16 }}\n affinity: {{ .Values.runner.affinity | toYaml | nindent 16 }}\n priorityClassName: {{ .Values.runner.priorityClassName }}\n serviceAccountName: {{ include \"bitbucketRunnerAutoscaler.fullname\" . }}-runner\n containers:\n - name: runner\n image: {{ include \"bitbucketRunnerAutoscaler.runnerImage\" . }} # This autoscaler needs the runner image to run, you can use the latest or pin any version you want.\n imagePullPolicy: {{ .Values.runner.image.pullPolicy }}\n resources: # This is memory and cpu resources section that you can configure via config map settings file.\n requests:\n memory: \"<%requests_memory%>\" # mandatory, don't modify\n cpu: \"<%requests_cpu%>\" # mandatory, don't modify\n limits:\n memory: \"<%limits_memory%>\" # mandatory, don't modify\n cpu: \"<%limits_cpu%>\" # mandatory, don't modify\n env:\n - name: ACCOUNT_UUID # mandatory, don't modify\n value: \"{<%account_uuid%>}\" # mandatory, don't modify\n {%- if repository_uuid %}\n - name: REPOSITORY_UUID # mandatory, don't modify\n value: \"{<%repository_uuid%>}\" # mandatory, don't modify\n {%- endif %}\n - name: RUNNER_UUID # mandatory, don't modify\n value: \"{<%runner_uuid%>}\" # mandatory, don't modify\n - name: OAUTH_CLIENT_ID\n valueFrom:\n secretKeyRef:\n name: runner-oauth-credentials-<%runner_uuid%>\n key: oauth_client_id\n - name: OAUTH_CLIENT_SECRET\n valueFrom:\n secretKeyRef:\n name: runner-oauth-credentials-<%runner_uuid%>\n key: oauth_client_secret\n - name: WORKING_DIRECTORY\n value: \"/tmp\"\n volumeMounts:\n - name: tmp\n mountPath: /tmp\n - name: docker-containers\n mountPath: /var/lib/docker/containers\n readOnly: true\n - name: var-run\n mountPath: /var/run\n - name: docker\n image: {{ include \"bitbucketRunnerAutoscaler.dindImage\" . }}\n imagePullPolicy: {{ .Values.runner.dind.image.pullPolicy }}\n securityContext:\n privileged: true\n volumeMounts:\n - name: tmp\n mountPath: /tmp\n - name: docker-containers\n mountPath: /var/lib/docker/containers\n - name: var-run\n mountPath: /var/run\n restartPolicy: OnFailure\n volumes:\n - name: tmp\n - name: docker-containers\n - name: var-run\n backoffLimit: 6\n completions: 1\n parallelism: 1\n"` | |
| runner.template.secret | string | `"apiVersion: v1\nkind: Secret\nmetadata:\n name: runner-oauth-credentials-<%runner_uuid%> # mandatory, don't modify\n labels:\n account_uuid: <%account_uuid%> # mandatory, don't modify\n{%- if repository_uuid %}\n repository_uuid: <%repository_uuid%> # mandatory, don't modify\n{%- endif %}\n runner_uuid: <%runner_uuid%> # mandatory, don't modify\n runner_namespace: <%runner_namespace%> # mandatory, don't modify\ndata:\n oauth_client_id: <%oauth_client_id_base64%>\n oauth_client_secret: <%oauth_client_secret_base64%>\n"` | |
| runner.tolerations | list | `[]` | |
| runner.topologySpreadConstraints | list | `[]` | |
| serviceAccount.annotations | object | `{}` | |
| serviceAccount.create | bool | `true` | |
| serviceAccount.name | string | `""` | |

## Maintainers

| Name | Email | Url |
| ---- | ------ | --- |
| Labyrinth Labs | <[email protected]> | <https://lablabs.io> |

----------------------------------------------
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 @@ -5,7 +5,7 @@
{{ template "chart.badgesSection" . }}

## About
<$chart-name> Helm chart
bitbucket-runner-autoscaler Helm chart

{{ template "chart.valuesSection" . }}

Expand Down
196 changes: 196 additions & 0 deletions charts/bitbucket-runner-autoscaler/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "bitbucketRunnerAutoscaler.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 "bitbucketRunnerAutoscaler.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 "bitbucketRunnerAutoscaler.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{- define "bitbucketRunnerAutoscaler.labels" -}}
{{- $name := include "bitbucketRunnerAutoscaler.name" . -}}
{{- $labels := dict -}}
{{- $labels = merge $labels (dict "app.kubernetes.io/name" $name) -}}
{{- $labels = merge $labels (dict "app.kubernetes.io/instance" .Release.Name) -}}
{{- $labels = merge $labels (dict "app.kubernetes.io/managed-by" .Release.Service) -}}
{{- if .Chart.AppVersion }}
{{- $labels = merge $labels (dict "app.kubernetes.io/version" .Chart.AppVersion) -}}
{{- end }}
{{- if .Values.global.commonLabels }}
{{- $labels = merge $labels .Values.global.commonLabels -}}
{{- end }}
{{- toYaml $labels -}}
{{- end }}

{{- define "bitbucketRunnerAutoscaler.podLabels" -}}
{{- $component := .component -}}
{{- $context := .context -}}
{{- $labels := include "bitbucketRunnerAutoscaler.labels" $context | fromYaml -}}
{{- $labels = merge $labels (dict "app.kubernetes.io/component" $component) -}}
{{- $componentValues := index $context.Values $component -}}
{{- if $componentValues.podLabels }}
{{- $labels = merge $labels $componentValues.podLabels -}}
{{- end }}
{{- toYaml $labels }}
{{- end }}

{{- define "bitbucketRunnerAutoscaler.selectorLabels" -}}
{{- $component := .component -}}
{{- $context := .context -}}
{{- $labels := dict -}}
{{- $labels = merge $labels (dict "app.kubernetes.io/name" (include "bitbucketRunnerAutoscaler.name" $context)) -}}
{{- $labels = merge $labels (dict "app.kubernetes.io/instance" $context.Release.Name) -}}
{{- $labels = merge $labels (dict "app.kubernetes.io/component" $component) -}}
{{- toYaml $labels -}}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "bitbucketRunnerAutoscaler.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "bitbucketRunnerAutoscaler.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Create the name of the bitbucket secret to use
*/}}
{{- define "bitbucketRunnerAutoscaler.secretName" -}}
{{- if .Values.credentialsSecret.create }}
{{- default (include "bitbucketRunnerAutoscaler.fullname" .) .Values.credentialsSecret.name }}
{{- else }}
{{- default "default" .Values.credentialsSecret.name }}
{{- end }}
{{- end }}

{{/*
Define tolerations to be used for cleaner service
*/}}
{{- define "bitbucketRunnerAutoscaler.cleanerTolerations" -}}
{{- $tolerations := .Values.cleaner.tolerations | default .Values.global.tolerations | default (list) }}
{{- toYaml $tolerations }}
{{- end }}

{{/*
Define node selector for cleanup service
*/}}
{{- define "bitbucketRunnerAutoscaler.cleanerNodeSelector" -}}
{{- $nodeSelector := .Values.cleaner.nodeSelector | default .Values.global.nodeSelector | default (dict) }}
{{- toYaml $nodeSelector }}
{{- end }}

{{/*
Define tolerations to be used for controller service
*/}}
{{- define "bitbucketRunnerAutoscaler.controllerTolerations" -}}
{{- $tolerations := .Values.controller.tolerations | default .Values.global.tolerations | default (list) }}
{{- toYaml $tolerations }}
{{- end }}

{{/*
Define node selector for controller service
*/}}
{{- define "bitbucketRunnerAutoscaler.controllerNodeSelector" -}}
{{- $nodeSelector := .Values.controller.nodeSelector | default .Values.global.nodeSelector | default (dict) }}
{{- toYaml $nodeSelector }}
{{- end }}

{{/*
Define runner tolerations
*/}}
{{- define "bitbucketRunnerAutoscaler.runnerTolerations" -}}
{{- $tolerations := .Values.runner.tolerations | default (list) }}
{{- toYaml $tolerations }}
{{- end }}

{{/*
Define runner node selector
*/}}
{{- define "bitbucketRunnerAutoscaler.runnerNodeSelector" -}}
{{- $nodeSelector := .Values.runner.nodeSelector | default (dict) }}
{{- toYaml $nodeSelector }}
{{- end }}

{{/*
Return the controller image name
*/}}
{{- define "bitbucketRunnerAutoscaler.controllerImage" -}}
{{- $registryName := .Values.controller.image.registry -}}
{{- $repositoryName := .Values.controller.image.repository -}}
{{- $tag := .Values.controller.image.tag | toString -}}
{{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
{{- end -}}

{{/*
Return the cleaner image name
*/}}
{{- define "bitbucketRunnerAutoscaler.cleanerImage" -}}
{{- $registryName := .Values.cleaner.image.registry -}}
{{- $repositoryName := .Values.cleaner.image.repository -}}
{{- $tag := .Values.cleaner.image.tag | toString -}}
{{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
{{- end -}}

{{/*
Return the runner image name
*/}}
{{- define "bitbucketRunnerAutoscaler.runnerImage" -}}
{{- $registryName := .Values.runner.image.registry -}}
{{- $repositoryName := .Values.runner.image.repository -}}
{{- $tag := .Values.runner.image.tag | toString -}}
{{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
{{- end -}}

{{/*
Return the dind image name
*/}}
{{- define "bitbucketRunnerAutoscaler.dindImage" -}}
{{- $registryName := .Values.runner.dind.image.registry -}}
{{- $repositoryName := .Values.runner.dind.image.repository -}}
{{- $tag := .Values.runner.dind.image.tag | toString -}}
{{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
{{- end -}}

{{- define "bitbucketRunnerAutoscaler.pdbName" -}}
{{- $component := .component -}}
{{- $context := .context -}}
{{- printf "%s-%s-pdb" (include "bitbucketRunnerAutoscaler.fullname" $context) $component -}}
{{- end }}

{{- define "bitbucketRunnerAutoscaler.runnerNamespaces" -}}
{{- $allNamespaces := list }}
{{- range .Values.runner.config.groups }}
{{- if eq .namespace $.Release.Namespace }}
{{- fail (printf "Runner namespace '%s' cannot be the same as the operator namespace '%s'" .namespace $.Release.Namespace) }}
{{- end }}
{{- $allNamespaces = append $allNamespaces .namespace -}}
{{- end }}
{{- $uniqueNamespaces := uniq $allNamespaces }}
{{- $_ := set . "RunnerNamespaces" $uniqueNamespaces }}
{{- end }}
Loading

0 comments on commit aaa26a9

Please sign in to comment.