Skip to content

Commit

Permalink
Merge pull request #24 from cloudkite-io/add-services-for-containers
Browse files Browse the repository at this point in the history
add services for each container
  • Loading branch information
kirill-cloudkite authored Feb 13, 2024
2 parents 01e5008 + 284cfb2 commit a0c82af
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 15 deletions.
2 changes: 2 additions & 0 deletions standard-app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# 0.3.0
* implemented services, ports, readiness probe, volume mounts and resources configuration support at the container level in deployments
2 changes: 1 addition & 1 deletion standard-app/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: standard-app
description: A Helm chart library by Cloudkite
type: application
version: 0.2.0
version: 0.3.0
maintainters:
- email: [email protected]
name: cloudkite
52 changes: 46 additions & 6 deletions standard-app/templates/configs/externalsecret.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,46 @@
# deployment secret
{{- if .Values.externalSecret }}

# deployment secrets
{{- range $appName, $appConfig := .Values.apps }}

# deployment container secret
{{- range $containerName, $containerConfig := $appConfig.containers -}}
{{- if $containerConfig.secrets }}
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
name: {{ $containerName }}
labels:
app: {{ $appName }}
product: {{ $.Release.Name }}
{{- with $.Values.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
refreshInterval: 1m
secretStoreRef:
kind: ClusterSecretStore
name: {{ $.Values.externalSecret.secretStoreName }}
target:
name: {{ $containerName }}
creationPolicy: Owner
data:
{{- range $secret := $containerConfig.secrets }}
- secretKey: {{ $secret.secretKey }}
remoteRef:
{{- if eq $.Values.externalSecret.type "gcp" }}
key: {{ $.Release.Name | upper }}_{{ $secret }}
{{- end }}
{{- if eq $.Values.externalSecret.type "vault" }}
key: {{ $.Values.externalSecret.secretPath }}/{{ $.Release.Name }}
property: {{ $secret.property | default $secret.secretKey }}
{{- end }}
{{- end }}
---
{{- end }}
{{- end }}

# deployment global secret
{{- if $appConfig.secrets }}
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
Expand All @@ -10,7 +50,7 @@ metadata:
app: {{ if $.Values.pr }}{{ $.Release.Name }}-{{ $appName | trimPrefix $.Release.Name | trimPrefix "-" }}{{ else }}{{ $appName }}{{ end }}
product: {{ $.Release.Name }}
{{- with $.Values.labels }}
{{- toYaml . | nindent 4 }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
refreshInterval: {{ $.Values.externalSecret.refreshInterval | default "1m" }}
Expand All @@ -24,13 +64,13 @@ spec:
{{- range $secret := $appConfig.secrets }}
- secretKey: {{ $secret.secretKey }}
remoteRef:
{{- if eq $.Values.externalSecret.type "gcp" }}
{{- if eq $.Values.externalSecret.type "gcp" }}
key: {{ $.Release.Name | upper }}_{{ $secret }}
{{- end }}
{{- if eq $.Values.externalSecret.type "vault" }}
{{- end }}
{{- if eq $.Values.externalSecret.type "vault" }}
key: {{ $.Values.externalSecret.secretPath }}/{{ $.Release.Name }}
property: {{ $secret.property | default $secret.secretKey }}
{{- end }}
{{- end }}
{{- end }}
---
{{- end }}
Expand Down
35 changes: 33 additions & 2 deletions standard-app/templates/network/service.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# deployment services
{{ range $appName, $appConfig := .Values.apps }}
{{- if $appConfig.service }}

# deployment container service
{{- if $appConfig.containers }}
{{- range $containerName, $containerConfig := $appConfig.containers }}
{{- if $containerConfig.service }}
apiVersion: v1
kind: Service
metadata:
name: {{ $containerName }}
labels:
app: {{ if $.Values.pr }}{{ $.Release.Name }}-{{ $appName | trimPrefix $.Release.Name | trimPrefix "-" }}{{ else }}{{ $appName }}{{ end }}
product: {{ $.Release.Name }}
{{- with $.Values.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
type: {{ $containerConfig.service.type | default "ClusterIP" }}
ports:
- port: {{ $containerConfig.service.port }}
targetPort: {{ $containerConfig.service.targetPort }}
protocol: {{ $containerConfig.service.protocol }}
selector:
app: {{ if $.Values.pr }}{{ $.Release.Name }}-{{ $appName | trimPrefix $.Release.Name | trimPrefix "-" }}{{ else }}{{ $appName }}{{ end }}
{{- end }}
{{- end }}

# deployment global service
{{- else if $appConfig.service }}
apiVersion: v1
kind: Service
metadata:
Expand All @@ -18,7 +46,11 @@ spec:
protocol: {{ $appConfig.service.protocol }}
selector:
app: {{ if $.Values.pr }}{{ $.Release.Name }}-{{ $appName | trimPrefix $.Release.Name | trimPrefix "-" }}{{ else }}{{ $appName }}{{ end }}
{{- end }}
---

# rollout services
# rollout global service
{{- if $appConfig.rollout }}
apiVersion: v1
kind: Service
Expand All @@ -40,5 +72,4 @@ spec:
app: {{ if $.Values.pr }}{{ $.Release.Name }}-{{ $appName | trimPrefix $.Chart.Name | trimPrefix "-" }}{{ else }}{{ $appName }}{{ end }}
---
{{- end }}
{{- end }}
{{- end }}
57 changes: 51 additions & 6 deletions standard-app/templates/workloads/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,32 @@ spec:
- {{ . | quote }}
{{- end }}
{{- end }}
{{- if $containerConfig.args }}
args:
{{- range $containerConfig.args }}
- {{ . | quote -}}
{{ end }}
{{- if $appConfig.volumes }}
volumeMounts:
{{- range $appConfig.volumes }}
- mountPath: {{ .mountPath }}
name: {{ .name }}
{{ end }}
{{- if $containerConfig.service }}
ports:
- name: {{ $containerConfig.service.name }}
containerPort: {{ $containerConfig.service.port }}
protocol: {{ $containerConfig.service.protocol }}
{{- else if $appConfig.service }}
ports:
- name: {{ $appConfig.service.name }}
containerPort: {{ $appConfig.service.port }}
protocol: {{ $appConfig.service.protocol }}
{{- end }}
{{- if $containerConfig.readinessProbe }}
readinessProbe:
{{- with $containerConfig.readinessProbe }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- else if $appConfig.readinessProbe }}
readinessProbe:
{{- with $appConfig.readinessProbe }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
env:
Expand All @@ -121,12 +138,40 @@ spec:
- secretRef:
name: {{ $containerName }}
{{- end }}
{{- if $appConfig.secrets }}
- secretRef:
name: {{ $appName }}
{{- end }}
{{- if $.Values.secrets }}
- secretRef:
name: {{ $.Release.Name }}
{{- end }}
{{- if $containerConfig.resources }}
resources:
{{- with $containerConfig.resources }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- else if $appConfig.resources }}
resources:
{{- with $appConfig.resources }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
{{- if $containerConfig.volumes }}
volumeMounts:
{{- range $containerConfig.volumes }}
- mountPath: {{ .mountPath }}
name: {{ .name }}
{{- end }}
{{- else if $appConfig.volumes }}
volumeMounts:
{{- range $appConfig.volumes }}
- mountPath: {{ .mountPath }}
name: {{ .name }}
{{- end }}
{{- end }}
{{- else }}
{{- end }}
{{- else }}
- name: {{ $appName }}
image: "{{- $appConfig.image | default $.Values.image }}:{{- $appConfig.tag | default $.Values.tag }}"
imagePullPolicy: "{{- $appConfig.imagePullPolicy | default $.Values.imagePullPolicy }}"
Expand Down

0 comments on commit a0c82af

Please sign in to comment.