From 01f204354285ef24e39f985b3b7999e8378c3dda Mon Sep 17 00:00:00 2001 From: Jacob Woffenden Date: Wed, 12 Jun 2024 08:50:59 +0000 Subject: [PATCH 1/6] chart Signed-off-by: GitHub --- .devcontainer/devcontainer-lock.json | 5 ++ .devcontainer/devcontainer.json | 1 + .github/workflows/chart-lint.yml | 33 +++++++++++++ .github/workflows/release.yml | 38 ++++++++++++++- chart/.helmignore | 23 +++++++++ chart/Chart.yaml | 14 ++++++ chart/templates/_helpers.tpl | 62 ++++++++++++++++++++++++ chart/templates/deployment.yaml | 70 +++++++++++++++++++++++++++ chart/templates/ingress.yaml | 61 +++++++++++++++++++++++ chart/templates/service.yaml | 15 ++++++ chart/templates/serviceaccount.yaml | 13 +++++ chart/templates/servicemonitor.yaml | 19 ++++++++ chart/values.yaml | 72 ++++++++++++++++++++++++++++ 13 files changed, 424 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/chart-lint.yml create mode 100644 chart/.helmignore create mode 100644 chart/Chart.yaml create mode 100644 chart/templates/_helpers.tpl create mode 100644 chart/templates/deployment.yaml create mode 100644 chart/templates/ingress.yaml create mode 100644 chart/templates/service.yaml create mode 100644 chart/templates/serviceaccount.yaml create mode 100644 chart/templates/servicemonitor.yaml create mode 100644 chart/values.yaml diff --git a/.devcontainer/devcontainer-lock.json b/.devcontainer/devcontainer-lock.json index 2d6de1d..3b79a1d 100644 --- a/.devcontainer/devcontainer-lock.json +++ b/.devcontainer/devcontainer-lock.json @@ -13,6 +13,11 @@ "ghcr.io/devcontainers/features/docker-in-docker:2" ] }, + "ghcr.io/ministryofjustice/devcontainer-feature/kubernetes:1": { + "version": "1.0.1", + "resolved": "ghcr.io/ministryofjustice/devcontainer-feature/kubernetes@sha256:0ec758e44468ba2a8b70b87613762ab04e50f7bb5eac8f2aea592cff213dbde5", + "integrity": "sha256:0ec758e44468ba2a8b70b87613762ab04e50f7bb5eac8f2aea592cff213dbde5" + }, "ghcr.io/ministryofjustice/devcontainer-feature/static-analysis:1": { "version": "1.0.0", "resolved": "ghcr.io/ministryofjustice/devcontainer-feature/static-analysis@sha256:e81d52725655c8ffb861605feac7ad155b447d51af65f6c3a03cab32d59f1e16", diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index a8ceda3..13a55f5 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -4,6 +4,7 @@ "features": { "ghcr.io/devcontainers/features/docker-in-docker:2": {}, "ghcr.io/ministryofjustice/devcontainer-feature/container-structure-test:1": {}, + "ghcr.io/ministryofjustice/devcontainer-feature/kubernetes:1": {}, "ghcr.io/ministryofjustice/devcontainer-feature/static-analysis:1": {} }, "customizations": { diff --git a/.github/workflows/chart-lint.yml b/.github/workflows/chart-lint.yml new file mode 100644 index 0000000..19f202e --- /dev/null +++ b/.github/workflows/chart-lint.yml @@ -0,0 +1,33 @@ +--- +name: Chart Lint + +on: + pull_request: + branches: + - main + +permissions: {} + +jobs: + chart-lint: + name: Chart Lint + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - name: Checkout + id: checkout + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + + - name: Set Up Helm + id: setup_helm + uses: azure/setup-helm@fe7b79cd5ee1e45176fcad797de68ecaf3ca4814 # v4.2.0 + + - name: Set Up Helm Chart Testing + id: setup_chart_testing + uses: helm/chart-testing-action@e6669bcd63d7cb57cb4380c33043eebe5d111992 # v2.6.1 + + - name: Lint Chart + id: lint_chart + run: | + make ct diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e10c4b7..9ea0822 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,8 +9,8 @@ on: permissions: {} jobs: - release: - name: Release + release-image: + name: Release Image runs-on: ubuntu-latest permissions: contents: read @@ -53,3 +53,37 @@ jobs: --certificate-oidc-issuer=https://token.actions.githubusercontent.com \ --certificate-identity=https://github.com/ministryofjustice/analytical-platform-mlflow/.github/workflows/release.yml@refs/tags/${{ github.ref_name }} \ ghcr.io/ministryofjustice/analytical-platform-mlflow@${{ steps.build_and_push.outputs.digest }} + + release-chart: + name: Release Chart + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + packages: write + steps: + - name: Checkout + id: checkout + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + + - name: Set Up Helm + id: setup_helm + uses: azure/setup-helm@fe7b79cd5ee1e45176fcad797de68ecaf3ca4814 # v4.2.0 + + - name: Log in to GitHub Container Registry + id: login_ghcr + uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Package Chart + id: package_chart + run: | + helm package chart --destination .helm-deploy + + - name: Push Chart + id: push_chart + run: | + helm push .helm-deploy/mlflow-${{ github.ref_name }}.tgz oci://ghcr.io/ministryofjustice/analytical-platform-charts diff --git a/chart/.helmignore b/chart/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/chart/.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/chart/Chart.yaml b/chart/Chart.yaml new file mode 100644 index 0000000..180869e --- /dev/null +++ b/chart/Chart.yaml @@ -0,0 +1,14 @@ +--- +apiVersion: v2 +name: mlflow +description: MLflow Tracking Server +type: application +version: 0.0.1 +appVersion: "v2.13.2" +home: https://github.com/ministryofjustice/analytical-platform-mlflow +sources: + - https://github.com/mlflow/mlflow +maintainers: + - name: Jacob Woffenden + email: jacob.woffenden@digital.justice.gov.uk + url: https://github.com/jacobwoffenden diff --git a/chart/templates/_helpers.tpl b/chart/templates/_helpers.tpl new file mode 100644 index 0000000..eb182c2 --- /dev/null +++ b/chart/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "mlflow.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 "mlflow.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 "mlflow.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "mlflow.labels" -}} +helm.sh/chart: {{ include "mlflow.chart" . }} +{{ include "mlflow.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "mlflow.selectorLabels" -}} +app.kubernetes.io/name: {{ include "mlflow.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "mlflow.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "mlflow.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml new file mode 100644 index 0000000..5c04a02 --- /dev/null +++ b/chart/templates/deployment.yaml @@ -0,0 +1,70 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "mlflow.fullname" . }} + labels: + {{- include "mlflow.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "mlflow.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "mlflow.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "mlflow.serviceAccountName" . }} + 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 }} + {{- with .Values.mlflow.environment }} + env: + {{- toYaml . | nindent 12 }} + {{- end }} + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + livenessProbe: + {{- toYaml .Values.livenessProbe | nindent 12 }} + readinessProbe: + {{- toYaml .Values.readinessProbe | nindent 12 }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.volumes }} + volumes: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- 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/chart/templates/ingress.yaml b/chart/templates/ingress.yaml new file mode 100644 index 0000000..5fef327 --- /dev/null +++ b/chart/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "mlflow.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 "mlflow.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/chart/templates/service.yaml b/chart/templates/service.yaml new file mode 100644 index 0000000..3476d0c --- /dev/null +++ b/chart/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "mlflow.fullname" . }} + labels: + {{- include "mlflow.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "mlflow.selectorLabels" . | nindent 4 }} diff --git a/chart/templates/serviceaccount.yaml b/chart/templates/serviceaccount.yaml new file mode 100644 index 0000000..ad97e6d --- /dev/null +++ b/chart/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "mlflow.serviceAccountName" . }} + labels: + {{- include "mlflow.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount }} +{{- end }} diff --git a/chart/templates/servicemonitor.yaml b/chart/templates/servicemonitor.yaml new file mode 100644 index 0000000..c4f8d4f --- /dev/null +++ b/chart/templates/servicemonitor.yaml @@ -0,0 +1,19 @@ +{{ if .Values.serviceMonitor.enabled -}} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ template "mlflow.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "mlflow.labels" . | nindent 4 }} +spec: + jobLabel: {{ template "mlflow.fullname" . }} + selector: + matchLabels: + app.kubernetes.io/name: {{ template "mlflow.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + endpoints: + - targetPort: {{ .Values.service.port }} + interval: {{ .Values.serviceMonitor.interval }} + path: {{ .Values.serviceMonitor.path }} +{{- end -}} diff --git a/chart/values.yaml b/chart/values.yaml new file mode 100644 index 0000000..a5445f6 --- /dev/null +++ b/chart/values.yaml @@ -0,0 +1,72 @@ +--- +affinity: {} + +fullnameOverride: "" + +image: + repository: ghcr.io/ministryofjustice/analytical-platform-mlflow + pullPolicy: IfNotPresent + tag: 2.13.2-rc0 + +imagePullSecrets: [] + +ingress: + enabled: false + className: "" + annotations: {} + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + +livenessProbe: + httpGet: + path: /health + port: http + +mlflow: + environment: [] + +nameOverride: "" + +nodeSelector: {} + +podAnnotations: {} + +podLabels: {} + +podSecurityContext: {} + +replicaCount: 1 + +securityContext: {} + +readinessProbe: + httpGet: + path: /health + port: http + +resources: {} + +service: + type: ClusterIP + port: 5000 + +serviceAccount: + create: true + automount: true + name: "" + annotations: {} + +serviceMonitor: + enabled: false + interval: 15s + path: /metrics + +tolerations: [] + +volumes: [] + +volumeMounts: [] From cb28113381c5c6821e6744d555ee4664370b2a83 Mon Sep 17 00:00:00 2001 From: Jacob Woffenden Date: Wed, 12 Jun 2024 08:57:19 +0000 Subject: [PATCH 2/6] Add make target Signed-off-by: GitHub --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 19ec543..065909c 100644 --- a/Makefile +++ b/Makefile @@ -13,3 +13,6 @@ build: echo "Building on $$ARCH architecture"; \ docker build --file Dockerfile --tag $(IMAGE_NAME) . ;; \ esac + +ct: + ct lint --charts chart From e70afe563e215b1dddafbf76d73e7c34b516d7ad Mon Sep 17 00:00:00 2001 From: Jacob Woffenden Date: Wed, 12 Jun 2024 09:10:43 +0000 Subject: [PATCH 3/6] remove url Signed-off-by: GitHub --- chart/Chart.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/chart/Chart.yaml b/chart/Chart.yaml index 180869e..ee34e92 100644 --- a/chart/Chart.yaml +++ b/chart/Chart.yaml @@ -11,4 +11,3 @@ sources: maintainers: - name: Jacob Woffenden email: jacob.woffenden@digital.justice.gov.uk - url: https://github.com/jacobwoffenden From 0bc0e26f3774c3825f98d748745c9c97eb9b8fc8 Mon Sep 17 00:00:00 2001 From: Jacob Woffenden Date: Wed, 12 Jun 2024 09:38:43 +0000 Subject: [PATCH 4/6] fix maintainer Signed-off-by: GitHub --- chart/Chart.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chart/Chart.yaml b/chart/Chart.yaml index ee34e92..89ca2db 100644 --- a/chart/Chart.yaml +++ b/chart/Chart.yaml @@ -9,5 +9,6 @@ home: https://github.com/ministryofjustice/analytical-platform-mlflow sources: - https://github.com/mlflow/mlflow maintainers: - - name: Jacob Woffenden + - name: jacobwoffenden email: jacob.woffenden@digital.justice.gov.uk + url: github.com/jacobwoffenden From de1e7e85e7b5a723bb5df9c25a88ea6584de9353 Mon Sep 17 00:00:00 2001 From: Jacob Woffenden Date: Wed, 12 Jun 2024 09:43:29 +0000 Subject: [PATCH 5/6] Update linting Signed-off-by: GitHub --- .github/linters/.yaml-lint.yml | 11 +++++++++++ .github/workflows/super-linter.yml | 1 + 2 files changed, 12 insertions(+) create mode 100644 .github/linters/.yaml-lint.yml diff --git a/.github/linters/.yaml-lint.yml b/.github/linters/.yaml-lint.yml new file mode 100644 index 0000000..b94203b --- /dev/null +++ b/.github/linters/.yaml-lint.yml @@ -0,0 +1,11 @@ +--- +extends: default + +ignore: + - '**/chart/templates/*.yaml' + - '**/chart/templates/tests/*.yaml' + +rules: + line-length: + max: 80 + level: warning diff --git a/.github/workflows/super-linter.yml b/.github/workflows/super-linter.yml index ba0c15d..b37d354 100644 --- a/.github/workflows/super-linter.yml +++ b/.github/workflows/super-linter.yml @@ -32,3 +32,4 @@ jobs: uses: super-linter/super-linter/slim@88ea3923a7e1f89dd485d079f6eb5f5e8f937589 # v6.6.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + VALIDATE_KUBERNETES_KUBECONFORM: false # Super-Linter doesn't support https://github.com/jtyr/kubeconform-helm From 8d874131de0d358b2ad45e2f24548948896fec50 Mon Sep 17 00:00:00 2001 From: Jacob Woffenden Date: Wed, 12 Jun 2024 09:45:10 +0000 Subject: [PATCH 6/6] prep for rc1 release Signed-off-by: GitHub --- chart/Chart.yaml | 4 ++-- chart/values.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/chart/Chart.yaml b/chart/Chart.yaml index 89ca2db..57891ad 100644 --- a/chart/Chart.yaml +++ b/chart/Chart.yaml @@ -3,8 +3,8 @@ apiVersion: v2 name: mlflow description: MLflow Tracking Server type: application -version: 0.0.1 -appVersion: "v2.13.2" +version: 2.13.2-rc1 +appVersion: 2.13.2-rc1 home: https://github.com/ministryofjustice/analytical-platform-mlflow sources: - https://github.com/mlflow/mlflow diff --git a/chart/values.yaml b/chart/values.yaml index a5445f6..8724b07 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -6,7 +6,7 @@ fullnameOverride: "" image: repository: ghcr.io/ministryofjustice/analytical-platform-mlflow pullPolicy: IfNotPresent - tag: 2.13.2-rc0 + tag: 2.13.2-rc1 imagePullSecrets: []