Skip to content

Commit

Permalink
Use Common Helm Templates (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
spjmurray authored Jun 18, 2024
1 parent c84cded commit 9d18e6b
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 147 deletions.
34 changes: 20 additions & 14 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ node_modules
/build
/.svelte-kit
/package
/charts/kubernetes/Chart.lock
/charts/kubernetes/charts
.env
.env.*
!.env.example
Expand Down
9 changes: 7 additions & 2 deletions charts/ui/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
121 changes: 2 additions & 119 deletions charts/ui/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -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 }}

{{/*
Expand All @@ -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 }}
2 changes: 1 addition & 1 deletion charts/ui/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion charts/ui/templates/image-pull-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
5 changes: 1 addition & 4 deletions charts/ui/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion charts/ui/templates/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ kind: Role
metadata:
name: unikorn-ui
labels:
{{- include "unikorn-ui.labels" . | nindent 4 }}
{{- include "unikorn.labels" . | nindent 4 }}
2 changes: 1 addition & 1 deletion charts/ui/templates/rolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion charts/ui/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion charts/ui/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
{{ . }}
Expand Down
3 changes: 2 additions & 1 deletion charts/ui/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/routes/(shell)/identity/projects/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
{#each resources || [] as resource}
<ShellListItem
metadata={resource.metadata}
href="identity/projects/view/{resource.metadata.id}"
href="/identity/projects/view/{resource.metadata.id}"
>
<button on:click={() => remove(resource)} on:keypress={() => remove(resource)}>
<iconify-icon icon="mdi:close" />
Expand Down

0 comments on commit 9d18e6b

Please sign in to comment.