Skip to content

Commit

Permalink
fix(DEVOPS-1803): Improve config variable loading in chart
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstojda committed Aug 16, 2023
1 parent 3728c78 commit 9673288
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 204 deletions.
16 changes: 16 additions & 0 deletions chart/templates/_configData.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{/*
Config ENV Vars for the application
*/}}
{{- define "joy-generator.config" }}
JOY_PLUGIN_TOKEN: "{{ required "pluginToken is required" .Values.applicationConfig.pluginToken }}"
JOY_REPO_URL: "{{ required "repoUrl is required" .Values.applicationConfig.repoUrl }}"
{{- if .Values.applicationConfig.githubApp }}
JOY_GITHUB_APP_ID: "{{ .Values.applicationConfig.githubApp.appId }}"
JOY_GITHUB_APP_INSTALLATION_ID: "{{ .Values.applicationConfig.githubApp.installationId }}"
{{- else if .Values.applicationConfig.githubUser }}
JOY_GITHUB_USER: "{{ .Values.applicationConfig.githubUser.username }}"
JOY_GITHUB_TOKEN: "{{ .Values.applicationConfig.githubUser.token }}"
{{- else }}
{{- fail "one of githubUser or githubAuth is required" }}
{{- end }}
{{- end }}
22 changes: 2 additions & 20 deletions chart/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,11 @@ metadata:
name: {{ include "joy-generator.fullname" . }}-config
{{- if eq .Values.secretType "secret" }}
stringData:
JOY_PLUGIN_TOKEN: "{{ required "pluginToken is required" .Values.applicationConfig.pluginToken }}"
JOY_REPO_URL: "{{ required "repoUrl is required" .Values.applicationConfig.repoUrl }}"
{{- if .Values.applicationConfig.githubApp }}
JOY_GITHUB_APP_ID: "{{ .Values.applicationConfig.githubApp.appId }}"
JOY_GITHUB_APP_INSTALLATION_ID: "{{ .Values.applicationConfig.githubApp.installationId }}"
{{- else if .Values.applicationConfig.githubToken }}
JOY_GITHUB_TOKEN: "{{ .Values.applicationConfig.githubToken }}"
{{- else }}
{{- fail "either a github token or github app is required" }}
{{- end }}
{{- include "joy-generator.config" . | indent 2 }}
{{- else if eq .Values.secretType "sealedSecret" }}
spec:
encryptedData:
JOY_PLUGIN_TOKEN: "{{ required "pluginToken is required" .Values.applicationConfig.pluginToken }}"
JOY_REPO_URL: "{{ required "repoUrl is required" .Values.applicationConfig.repoUrl }}"
{{- if .Values.applicationConfig.githubApp }}
JOY_GITHUB_APP_ID: "{{ .Values.applicationConfig.githubApp.appId }}"
JOY_GITHUB_APP_INSTALLATION_ID: "{{ .Values.applicationConfig.githubApp.installationId }}"
{{- else if .Values.applicationConfig.githubToken }}
JOY_GITHUB_TOKEN: "{{ .Values.applicationConfig.githubToken }}"
{{- else }}
{{- fail "either a github token or github app is required" }}
{{- end }}
{{- include "joy-generator.config" . | indent 4 }}
{{- end }}

---
Expand Down
10 changes: 5 additions & 5 deletions chart/tests/with-github-app-and-sealed-secrets/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ kind: Service
metadata:
name: my-release-joy-generator
labels:
helm.sh/chart: joy-generator-0.0.2
helm.sh/chart: joy-generator-0.0.3
app.kubernetes.io/name: joy-generator
app.kubernetes.io/instance: my-release
app.kubernetes.io/version: "0.0.2"
app.kubernetes.io/version: "0.0.3"
app.kubernetes.io/managed-by: Helm
spec:
type: ClusterIP
Expand All @@ -36,10 +36,10 @@ kind: Deployment
metadata:
name: my-release-joy-generator
labels:
helm.sh/chart: joy-generator-0.0.2
helm.sh/chart: joy-generator-0.0.3
app.kubernetes.io/name: joy-generator
app.kubernetes.io/instance: my-release
app.kubernetes.io/version: "0.0.2"
app.kubernetes.io/version: "0.0.3"
app.kubernetes.io/managed-by: Helm
spec:
replicas: 1
Expand Down Expand Up @@ -101,7 +101,7 @@ kind: SealedSecret
metadata:
name: my-release-joy-generator-config
spec:
encryptedData:
encryptedData:
JOY_PLUGIN_TOKEN: "@very!l0ngands3curet0ken"
JOY_REPO_URL: "https://github.com/example/foobar.git"
JOY_GITHUB_APP_ID: "123456"
Expand Down
58 changes: 1 addition & 57 deletions chart/tests/with-github-app-and-sealed-secrets/values.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# Default values for joy-generator.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

secretType: 'sealedSecret'

# Configuration settings for the joy-generator instance
applicationConfig:
pluginToken: "@very!l0ngands3curet0ken"
# The HTTPS Git URL of your joy catalog
Expand All @@ -20,56 +13,7 @@ applicationConfig:
privateKey: |
FOOBARLOREMISPUM
replicaCount: 1
secretType: 'sealedSecret'

image:
repository: ghcr.io/nestoca/joy-generator
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: 0.1.2

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

podAnnotations: {}

podSecurityContext: {}
# fsGroup: 2000

securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000

service:
type: ClusterIP
port: 80

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:
enabled: false
minReplicas: 1
maxReplicas: 100
targetCPUUtilizationPercentage: 80
# targetMemoryUtilizationPercentage: 80

nodeSelector: {}

tolerations: []

affinity: {}
10 changes: 5 additions & 5 deletions chart/tests/with-github-app/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: v1
kind: Secret
metadata:
name: my-release-joy-generator-config
stringData:
stringData:
JOY_PLUGIN_TOKEN: "@very!l0ngands3curet0ken"
JOY_REPO_URL: "https://github.com/example/foobar.git"
JOY_GITHUB_APP_ID: "123456"
Expand Down Expand Up @@ -34,10 +34,10 @@ kind: Service
metadata:
name: my-release-joy-generator
labels:
helm.sh/chart: joy-generator-0.0.2
helm.sh/chart: joy-generator-0.0.3
app.kubernetes.io/name: joy-generator
app.kubernetes.io/instance: my-release
app.kubernetes.io/version: "0.0.2"
app.kubernetes.io/version: "0.0.3"
app.kubernetes.io/managed-by: Helm
spec:
type: ClusterIP
Expand All @@ -56,10 +56,10 @@ kind: Deployment
metadata:
name: my-release-joy-generator
labels:
helm.sh/chart: joy-generator-0.0.2
helm.sh/chart: joy-generator-0.0.3
app.kubernetes.io/name: joy-generator
app.kubernetes.io/instance: my-release
app.kubernetes.io/version: "0.0.2"
app.kubernetes.io/version: "0.0.3"
app.kubernetes.io/managed-by: Helm
spec:
replicas: 1
Expand Down
55 changes: 0 additions & 55 deletions chart/tests/with-github-app/values.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Default values for joy-generator.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

# Configuration settings for the joy-generator instance
applicationConfig:
pluginToken: "@very!l0ngands3curet0ken"
Expand All @@ -18,56 +14,5 @@ applicationConfig:
privateKey: |
FOOBARLOREMISPUM
replicaCount: 1

image:
repository: ghcr.io/nestoca/joy-generator
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: 0.1.2

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

podAnnotations: {}

podSecurityContext: {}
# fsGroup: 2000

securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000

service:
type: ClusterIP
port: 80

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:
enabled: false
minReplicas: 1
maxReplicas: 100
targetCPUUtilizationPercentage: 80
# targetMemoryUtilizationPercentage: 80

nodeSelector: {}

tolerations: []

affinity: {}
11 changes: 6 additions & 5 deletions chart/tests/with-github-token/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ apiVersion: v1
kind: Secret
metadata:
name: my-release-joy-generator-config
stringData:
stringData:
JOY_PLUGIN_TOKEN: "@very!l0ngands3curet0ken"
JOY_REPO_URL: "https://github.com/example/foobar.git"
JOY_GITHUB_USER: "username"
JOY_GITHUB_TOKEN: "12312312312312"
---
# Source: joy-generator/templates/argocd-config.yaml
Expand All @@ -24,10 +25,10 @@ kind: Service
metadata:
name: my-release-joy-generator
labels:
helm.sh/chart: joy-generator-0.0.2
helm.sh/chart: joy-generator-0.0.3
app.kubernetes.io/name: joy-generator
app.kubernetes.io/instance: my-release
app.kubernetes.io/version: "0.0.2"
app.kubernetes.io/version: "0.0.3"
app.kubernetes.io/managed-by: Helm
spec:
type: ClusterIP
Expand All @@ -46,10 +47,10 @@ kind: Deployment
metadata:
name: my-release-joy-generator
labels:
helm.sh/chart: joy-generator-0.0.2
helm.sh/chart: joy-generator-0.0.3
app.kubernetes.io/name: joy-generator
app.kubernetes.io/instance: my-release
app.kubernetes.io/version: "0.0.2"
app.kubernetes.io/version: "0.0.3"
app.kubernetes.io/managed-by: Helm
spec:
replicas: 1
Expand Down
55 changes: 3 additions & 52 deletions chart/tests/with-github-token/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,58 +7,9 @@ applicationConfig:
pluginToken: "@very!l0ngands3curet0ken"
# The HTTPS Git URL of your joy catalog
repoUrl: "https://github.com/example/foobar.git"
githubToken: "12312312312312"

replicaCount: 1
githubUser:
token: "12312312312312"
username: "username"

image:
repository: ghcr.io/nestoca/joy-generator
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: 0.1.2

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

podAnnotations: {}

podSecurityContext: {}
# fsGroup: 2000

securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000

service:
type: ClusterIP
port: 80

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:
enabled: false
minReplicas: 1
maxReplicas: 100
targetCPUUtilizationPercentage: 80
# targetMemoryUtilizationPercentage: 80

nodeSelector: {}

tolerations: []

affinity: {}
16 changes: 11 additions & 5 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
# Configuration settings for the joy-generator instance
applicationConfig:
# The shared token that ArgoCD will use to call the joy-generator plugin API
# This should be some long random string
# This should be some long and secure random string
pluginToken: ""
# The HTTPS Git URL of your joy catalog
repoUrl: ""
# The GitHub token to use to access the repo
githubToken: ""
# The GitHub app configuration.
# Required if githubToken is not set.

# joy-generator supports authenticating with GitHub using either a personal access token or a GitHub App
# Provide either the githubUser or githubApp section, but not both

# githubUser:
# # The GitHub username to use for the joy-generator instance
# username: ""
# # The GitHub personal access token to use for the joy-generator instance
# token: ""

# githubApp:
# # The GitHub application ID
# appId: ""
Expand Down

0 comments on commit 9673288

Please sign in to comment.