From 9d18e6b629af9a896873d97e37b0b4f5e29d7ff7 Mon Sep 17 00:00:00 2001 From: Simon Murray Date: Tue, 18 Jun 2024 15:19:20 +0100 Subject: [PATCH] Use Common Helm Templates (#54) --- .github/workflows/pull-request.yaml | 34 +++-- .gitignore | 2 + charts/ui/Chart.yaml | 9 +- charts/ui/templates/_helpers.tpl | 121 +----------------- charts/ui/templates/deployment.yaml | 2 +- charts/ui/templates/image-pull-secret.yaml | 2 +- charts/ui/templates/ingress.yaml | 5 +- charts/ui/templates/role.yaml | 2 +- charts/ui/templates/rolebinding.yaml | 2 +- charts/ui/templates/service.yaml | 2 +- charts/ui/templates/serviceaccount.yaml | 2 +- charts/ui/values.yaml | 3 +- .../(shell)/identity/projects/+page.svelte | 2 +- 13 files changed, 41 insertions(+), 147 deletions(-) diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index 33dbb75..5e734ea 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -10,20 +10,26 @@ jobs: Lint: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 21 - cache: 'npm' - - name: Node Clean Install - run: npm ci - - name: Lint - run: make lint + - name: Checkout + uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 21 + cache: 'npm' + - name: Install Helm + uses: azure/setup-helm@v3 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Build Helm Chart + run: helm dependency update charts/ui + - name: Node Clean Install + run: npm ci + - name: Lint + run: make lint Build: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Build Images - run: make images + - name: Checkout + uses: actions/checkout@v3 + - name: Build Images + run: make images diff --git a/.gitignore b/.gitignore index 8765a40..606513a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ node_modules /build /.svelte-kit /package +/charts/kubernetes/Chart.lock +/charts/kubernetes/charts .env .env.* !.env.example diff --git a/charts/ui/Chart.yaml b/charts/ui/Chart.yaml index 6f58985..2ee7a94 100644 --- a/charts/ui/Chart.yaml +++ b/charts/ui/Chart.yaml @@ -4,7 +4,12 @@ description: A Helm chart for deploying Unikorn UI type: application -version: v0.2.4 -appVersion: v0.2.4 +version: v0.2.5 +appVersion: v0.2.5 icon: https://assets.unikorn-cloud.org/assets/images/logos/dark-on-light/icon.png + +dependencies: +- name: unikorn-common + version: v0.1.5 + repository: https://unikorn-cloud.github.io/helm-common diff --git a/charts/ui/templates/_helpers.tpl b/charts/ui/templates/_helpers.tpl index 707ff07..21cd532 100644 --- a/charts/ui/templates/_helpers.tpl +++ b/charts/ui/templates/_helpers.tpl @@ -1,79 +1,8 @@ -{{/* -Expand the name of the chart. -*/}} -{{- define "unikorn-ui.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 "unikorn-ui.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 "unikorn-ui.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} -{{- end }} - -{{/* -Common labels -*/}} -{{- define "unikorn-ui.labels" -}} -helm.sh/chart: {{ include "unikorn-ui.chart" . }} -{{ include "unikorn-ui.selectorLabels" . }} -{{- if .Chart.AppVersion }} -app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} -{{- end }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- end }} - -{{/* -Selector labels -*/}} -{{- define "unikorn-ui.selectorLabels" -}} -app.kubernetes.io/name: {{ include "unikorn-ui.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end }} - -{{/* -Create the name of the service account to use -*/}} -{{- define "unikorn-ui.serviceAccountName" -}} -{{- if .Values.serviceAccount.create }} -{{- default (include "unikorn-ui.fullname" .) .Values.serviceAccount.name }} -{{- else }} -{{- default "default" .Values.serviceAccount.name }} -{{- end }} -{{- end }} - {{/* Create the container images */}} -{{- define "unikorn-ui.defaultRepositoryPath" -}} -{{- if .Values.repository }} -{{- printf "%s/%s" .Values.repository .Values.organization }} -{{- else }} -{{- .Values.organization }} -{{- end }} -{{- end }} - {{- define "unikorn-ui.image" -}} -{{- .Values.image | default (printf "%s/unikorn-ui:%s" (include "unikorn-ui.defaultRepositoryPath" .) (.Values.tag | default .Chart.Version)) }} +{{- .Values.image | default (printf "%s/unikorn-ui:%s" (include "unikorn.defaultRepositoryPath" .) (.Values.tag | default .Chart.Version)) }} {{- end }} {{/* @@ -88,56 +17,10 @@ Create image pull secrets {{- end }} {{- end }} -{{/* -Creates predicatable Kubernetes name compatible UUIDs from name. -Note we always start with a letter (kubernetes DNS label requirement), -group 3 starts with "4" (UUIDv4 aka "random") and group 4 with "8" -(the variant aka RFC9562). -*/}} -{{ define "resource.id" -}} -{{- $sum := sha256sum . -}} -{{ printf "f%s-%s-4%s-8%s-%s" (substr 1 8 $sum) (substr 8 12 $sum) (substr 13 16 $sum) (substr 17 20 $sum) (substr 20 32 $sum) }} -{{- end }} - -{{/* -Abstractions to allow an all-in-one chart -*/}} -{{- define "unikorn.identity.host" -}} -{{- if (and .Values.global .Values.global.identity .Values.global.identity.host) -}} -{{- .Values.global.identity.host }} -{{- else }} -{{- .Values.identity.host }} -{{- end }} -{{- end }} - -{{- define "unikorn.region.host" -}} -{{- if (and .Values.global .Values.global.region .Values.global.region.host) -}} -{{- .Values.global.region.host }} -{{- else }} -{{- .Values.region.host }} -{{- end }} -{{- end }} - -{{- define "unikorn.kubernetes.host" -}} -{{- if (and .Values.global .Values.global.kubernetes .Values.global.kubernetes.host) -}} -{{- .Values.global.kubernetes.host }} -{{- else }} -{{- .Values.kubernetes.host }} -{{- end }} -{{- end }} - {{- define "unikorn.ui.host" -}} {{- if (and .Values.global .Values.global.ui .Values.global.ui.host) -}} {{- .Values.global.ui.host }} {{- else }} -{{- .Values.host }} -{{- end }} -{{- end }} - -{{- define "unikorn.ingress.clusterIssuer" -}} -{{- if (and .Values.global .Values.global.ingress .Values.global.ingress.clusterIssuer) -}} -{{- .Values.global.ingress.clusterIssuer }} -{{- else if .Values.ingress.clusterIssuer }} -{{- .Values.ingress.clusterIssuer }} +{{- .Values.ui.host }} {{- end }} {{- end }} diff --git a/charts/ui/templates/deployment.yaml b/charts/ui/templates/deployment.yaml index 083e9f0..530578d 100644 --- a/charts/ui/templates/deployment.yaml +++ b/charts/ui/templates/deployment.yaml @@ -3,7 +3,7 @@ kind: Deployment metadata: name: unikorn-ui labels: - {{- include "unikorn-ui.labels" . | nindent 4 }} + {{- include "unikorn.labels" . | nindent 4 }} spec: replicas: 1 selector: diff --git a/charts/ui/templates/image-pull-secret.yaml b/charts/ui/templates/image-pull-secret.yaml index 90edeae..b05a4d9 100644 --- a/charts/ui/templates/image-pull-secret.yaml +++ b/charts/ui/templates/image-pull-secret.yaml @@ -4,7 +4,7 @@ kind: Secret metadata: name: unikorn-ui-docker-config labels: - {{- include "unikorn-ui.labels" . | nindent 4 }} + {{- include "unikorn.labels" . | nindent 4 }} type: kubernetes.io/dockerconfigjson data: .dockerconfigjson: {{ .Values.dockerConfig }} diff --git a/charts/ui/templates/ingress.yaml b/charts/ui/templates/ingress.yaml index af6ca00..cdbc1ca 100644 --- a/charts/ui/templates/ingress.yaml +++ b/charts/ui/templates/ingress.yaml @@ -3,14 +3,11 @@ kind: Ingress metadata: name: unikorn-ui labels: - {{- include "unikorn-ui.labels" . | nindent 4 }} + {{- include "unikorn.labels" . | nindent 4 }} annotations: {{- with $clusterIssuer := ( include "unikorn.ingress.clusterIssuer" . ) }} cert-manager.io/cluster-issuer: {{ $clusterIssuer }} {{- end }} - {{- if .Values.ingress.issuer }} - cert-manager.io/issuer: {{ .Values.ingress.issuer }} - {{- end }} {{- if .Values.ingress.externalDns }} external-dns.alpha.kubernetes.io/hostname: {{ include "unikorn.ui.host" . }} {{- end }} diff --git a/charts/ui/templates/role.yaml b/charts/ui/templates/role.yaml index ad29642..b176d38 100644 --- a/charts/ui/templates/role.yaml +++ b/charts/ui/templates/role.yaml @@ -3,4 +3,4 @@ kind: Role metadata: name: unikorn-ui labels: - {{- include "unikorn-ui.labels" . | nindent 4 }} + {{- include "unikorn.labels" . | nindent 4 }} diff --git a/charts/ui/templates/rolebinding.yaml b/charts/ui/templates/rolebinding.yaml index b467e91..d658866 100644 --- a/charts/ui/templates/rolebinding.yaml +++ b/charts/ui/templates/rolebinding.yaml @@ -3,7 +3,7 @@ kind: RoleBinding metadata: name: unikorn-ui labels: - {{- include "unikorn-ui.labels" . | nindent 4 }} + {{- include "unikorn.labels" . | nindent 4 }} subjects: - kind: ServiceAccount namespace: {{ .Release.Namespace }} diff --git a/charts/ui/templates/service.yaml b/charts/ui/templates/service.yaml index 67f5a56..ebe53bb 100644 --- a/charts/ui/templates/service.yaml +++ b/charts/ui/templates/service.yaml @@ -3,7 +3,7 @@ kind: Service metadata: name: unikorn-ui labels: - {{- include "unikorn-ui.labels" . | nindent 4 }} + {{- include "unikorn.labels" . | nindent 4 }} spec: selector: app: unikorn-ui diff --git a/charts/ui/templates/serviceaccount.yaml b/charts/ui/templates/serviceaccount.yaml index 8268bda..f5bc626 100644 --- a/charts/ui/templates/serviceaccount.yaml +++ b/charts/ui/templates/serviceaccount.yaml @@ -3,7 +3,7 @@ kind: ServiceAccount metadata: name: unikorn-ui labels: - {{- include "unikorn-ui.labels" . | nindent 4 }} + {{- include "unikorn.labels" . | nindent 4 }} {{- with ( include "unikorn-ui.imagePullSecrets" . ) }} imagePullSecrets: {{ . }} diff --git a/charts/ui/values.yaml b/charts/ui/values.yaml index 395758e..8b0106b 100644 --- a/charts/ui/values.yaml +++ b/charts/ui/values.yaml @@ -23,7 +23,8 @@ imagePullSecret: image: # What DNS name I have. -host: console.unikorn-cloud.org +ui: + host: console.unikorn-cloud.org identity: # The API's hostname. diff --git a/src/routes/(shell)/identity/projects/+page.svelte b/src/routes/(shell)/identity/projects/+page.svelte index a44cc75..06c7c43 100644 --- a/src/routes/(shell)/identity/projects/+page.svelte +++ b/src/routes/(shell)/identity/projects/+page.svelte @@ -92,7 +92,7 @@ {#each resources || [] as resource}