Skip to content

Commit ea0fc31

Browse files
Adding Configmap handling to deployments (#419)
Co-authored-by: David Gamero <[email protected]>
1 parent ee68ec6 commit ea0fc31

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+805
-110
lines changed

.github/workflows/integration-linux.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ jobs:
444444
npm install -g [email protected]
445445
ajv validate -s test/update_dry_run_schema.json -d test/temp/update_dry_run.json
446446
- run: ./draft -v update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
447+
- name: print manifests
448+
run: cat ./langtest/manifests/*
447449
- name: start minikube
448450
id: minikube
449451
uses: medyagh/setup-minikube@master
@@ -2238,7 +2240,7 @@ jobs:
22382240
- run: mkdir ./langtest
22392241
- uses: actions/checkout@v3
22402242
with:
2241-
repository: OliverMKing/ruby-hello-world
2243+
repository: davidgamero/sinatra-hello-world
22422244
path: ./langtest
22432245
- name: Execute Dry Run with config file
22442246
run: |
@@ -2273,7 +2275,7 @@ jobs:
22732275
- run: mkdir ./langtest
22742276
- uses: actions/checkout@v3
22752277
with:
2276-
repository: OliverMKing/ruby-hello-world
2278+
repository: davidgamero/sinatra-hello-world
22772279
path: ./langtest
22782280
- run: rm -rf ./langtest/manifests && rm -f ./langtest/Dockerfile ./langtest/.dockerignore
22792281
- run: ./draft -v create -c ./test/integration/ruby/helm.yaml -d ./langtest/
@@ -2379,7 +2381,7 @@ jobs:
23792381
- run: mkdir ./langtest
23802382
- uses: actions/checkout@v3
23812383
with:
2382-
repository: OliverMKing/ruby-hello-world
2384+
repository: davidgamero/sinatra-hello-world
23832385
path: ./langtest
23842386
- name: Execute Dry Run with config file
23852387
run: |
@@ -2414,7 +2416,7 @@ jobs:
24142416
- run: mkdir ./langtest
24152417
- uses: actions/checkout@v3
24162418
with:
2417-
repository: OliverMKing/ruby-hello-world
2419+
repository: davidgamero/sinatra-hello-world
24182420
path: ./langtest
24192421
- run: rm -rf ./langtest/manifests && rm -f ./langtest/Dockerfile ./langtest/.dockerignore
24202422
- run: ./draft -v create -c ./test/integration/ruby/kustomize.yaml -d ./langtest/
@@ -2511,7 +2513,7 @@ jobs:
25112513
- run: mkdir ./langtest
25122514
- uses: actions/checkout@v3
25132515
with:
2514-
repository: OliverMKing/ruby-hello-world
2516+
repository: davidgamero/sinatra-hello-world
25152517
path: ./langtest
25162518
- name: Execute Dry Run with config file
25172519
run: |
@@ -2546,7 +2548,7 @@ jobs:
25462548
- run: mkdir ./langtest
25472549
- uses: actions/checkout@v3
25482550
with:
2549-
repository: OliverMKing/ruby-hello-world
2551+
repository: davidgamero/sinatra-hello-world
25502552
path: ./langtest
25512553
- run: rm -rf ./langtest/manifests && rm -f ./langtest/Dockerfile ./langtest/.dockerignore
25522554
- run: ./draft -v create -c ./test/integration/ruby/manifest.yaml -d ./langtest/

.github/workflows/integration-windows.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ jobs:
551551
- run: mkdir ./langtest
552552
- uses: actions/checkout@v3
553553
with:
554-
repository: OliverMKing/ruby-hello-world
554+
repository: davidgamero/sinatra-hello-world
555555
path: ./langtest
556556
- run: Remove-Item ./langtest/manifests -Recurse -Force -ErrorAction Ignore
557557
- run: Remove-Item ./langtest/Dockerfile -ErrorAction Ignore
@@ -601,7 +601,7 @@ jobs:
601601
- run: mkdir ./langtest
602602
- uses: actions/checkout@v3
603603
with:
604-
repository: OliverMKing/ruby-hello-world
604+
repository: davidgamero/sinatra-hello-world
605605
path: ./langtest
606606
- run: Remove-Item ./langtest/manifests -Recurse -Force -ErrorAction Ignore
607607
- run: Remove-Item ./langtest/Dockerfile -ErrorAction Ignore

pkg/cmdhelpers/workflow_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func setDeploymentContainerImage(filePath, productionImage string) error {
8080

8181
printer := printers.YAMLPrinter{}
8282

83-
out, err := os.OpenFile(filePath, os.O_RDWR, 0755)
83+
out, err := os.OpenFile(filePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
8484
if err != nil {
8585
return nil
8686
}

pkg/config/draftconfig.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
const draftConfigFile = "draft.yaml"
1717

1818
type VariableValidator func(string) error
19-
type VariableTransformer func(string) (string, error)
19+
type VariableTransformer func(string) (any, error)
2020

2121
type DraftConfig struct {
2222
TemplateName string `yaml:"templateName"`
@@ -99,7 +99,7 @@ func (d *DraftConfig) GetVariable(name string) (*BuilderVar, error) {
9999
return nil, fmt.Errorf("variable %s not found", name)
100100
}
101101

102-
func (d *DraftConfig) GetVariableValue(name string) (string, error) {
102+
func (d *DraftConfig) GetVariableValue(name string) (any, error) {
103103
for _, variable := range d.Variables {
104104
if variable.Name == name {
105105
if variable.Value == "" {

pkg/config/draftconfig_template_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,19 @@ var validVariableKinds = map[string]bool{
4040
"containerImageVersion": true,
4141
"dirPath": true,
4242
"dockerFileName": true,
43+
"envVarMap": true,
4344
"filePath": true,
4445
"flag": true,
4546
"helmChartOverrides": true,
4647
"ingressHostName": true,
4748
"kubernetesNamespace": true,
49+
"kubernetesProbePeriod": true,
50+
"kubernetesProbeTimeout": true,
51+
"kubernetesProbeThreshold": true,
52+
"kubernetesProbeDelay": true,
53+
"kubernetesResourceLimit": true,
4854
"kubernetesResourceName": true,
55+
"kubernetesResourceRequest": true,
4956
"label": true,
5057
"port": true,
5158
"repositoryBranch": true,
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
package transformers
22

3-
func GetTransformer(variableKind string) func(string) (string, error) {
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
)
7+
8+
func GetTransformer(variableKind string) func(string) (any, error) {
49
switch variableKind {
10+
case "envVarMap":
11+
return EnvironmentVariableMapTransformer
512
default:
613
return DefaultTransformer
714
}
815
}
916

10-
func DefaultTransformer(inputVar string) (string, error) {
17+
func EnvironmentVariableMapTransformer(inputVar string) (any, error) {
18+
var inputVarMap map[string]string
19+
if err := json.Unmarshal([]byte(inputVar), &inputVarMap); err != nil {
20+
return "", fmt.Errorf("failed to unmarshal variable as map[string]string: %s", err)
21+
}
22+
return inputVarMap, nil
23+
}
24+
25+
func DefaultTransformer(inputVar string) (any, error) {
1126
return inputVar, nil
1227
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
package validators
22

3+
import (
4+
"encoding/json"
5+
"fmt"
6+
)
7+
38
func GetValidator(variableKind string) func(string) error {
49
switch variableKind {
10+
case "envVarMap":
11+
return KeyValueMapValidator
512
default:
613
return DefaultValidator
714
}
815
}
916

17+
func KeyValueMapValidator(input string) error {
18+
if err := json.Unmarshal([]byte(input), &map[string]string{}); err != nil {
19+
return fmt.Errorf("failed to unmarshal variable as map[string]string: %s", err)
20+
}
21+
return nil
22+
}
23+
1024
func DefaultValidator(input string) error {
1125
return nil
1226
}

pkg/fixtures/deployments/helm/charts/templates/_helpers.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
{{- define "testapp.labels" -}}
2727
helm.sh/chart: {{ include "testapp.chart" . }}
2828
{{ include "testapp.selectorLabels" . }}
29+
kubernetes.azure.com/generator: {{ .Values.generatorLabel }}
2930
{{- if .Chart.AppVersion }}
3031
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
3132
{{- end }}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ include "testapp.fullname" . }}-config
5+
labels:
6+
{{- include "testapp.labels" . | nindent 4 }}
7+
namespace: {{ .Values.namespace }}
8+
data:
9+
{{- range $key, $value := .Values.envVars }}
10+
{{ $key }}: {{ $value }}
11+
{{- end }}

pkg/fixtures/deployments/helm/charts/templates/deployment.yaml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ metadata:
44
name: {{ include "testapp.fullname" . }}
55
labels:
66
{{- include "testapp.labels" . | nindent 4 }}
7-
kubernetes.azure.com/generator: {{ .Values.generatorLabel }}
87
namespace: {{ .Values.namespace }}
98
spec:
109
{{- if not .Values.autoscaling.enabled }}
@@ -40,15 +39,14 @@ spec:
4039
containerPort: {{ .Values.containerPort }}
4140
protocol: TCP
4241
livenessProbe:
43-
httpGet:
44-
path: /
45-
port: http
42+
{{- toYaml .Values.livenessProbe | nindent 12 }}
4643
readinessProbe:
47-
httpGet:
48-
path: /
49-
port: http
44+
{{- toYaml .Values.readinessProbe | nindent 12 }}
5045
resources:
5146
{{- toYaml .Values.resources | nindent 12 }}
47+
envFrom:
48+
- configMapRef:
49+
name: {{ include "testapp.fullname" . }}-config
5250
{{- with .Values.nodeSelector }}
5351
nodeSelector:
5452
{{- toYaml . | nindent 8 }}
@@ -57,6 +55,10 @@ spec:
5755
affinity:
5856
{{- toYaml . | nindent 8 }}
5957
{{- end }}
58+
{{- with .Values.topologySpreadConstraints }}
59+
topologySpreadConstraints:
60+
{{- toYaml . | nindent 8 }}
61+
{{- end }}
6062
{{- with .Values.tolerations }}
6163
tolerations:
6264
{{- toYaml . | nindent 8 }}

0 commit comments

Comments
 (0)