Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding the configmap template to the helm deployment template #382

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ vendor/
/pkg/workflows/workflow/
.DS_Store
draft
langtest
langtest
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ COPY . ./
RUN make go-generate

RUN go mod download
ENTRYPOINT ["go"]
ENTRYPOINT ["go"]
4 changes: 2 additions & 2 deletions pkg/config/draftconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ func (d *DraftConfig) GetVariableExampleValues() map[string][]string {
}

// Returns a map of variable names to values used in Gotemplate
func (d *DraftConfig) GetVariableMap() map[string]string {
variableMap := make(map[string]string)
func (d *DraftConfig) GetVariableMap() map[string]interface{} {
variableMap := make(map[string]interface{})
for _, variable := range d.Variables {
variableMap[variable.Name] = variable.Value
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/osutil/osutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func CopyDirWithTemplates(
return nil
}

func replaceGoTemplateVariables(fileSys fs.FS, srcPath string, variableMap map[string]string) ([]byte, error) {
func replaceGoTemplateVariables(fileSys fs.FS, srcPath string, variableMap map[string]interface{}) ([]byte, error) {
file, err := fs.ReadFile(fileSys, srcPath)
if err != nil {
return nil, err
Expand Down
10 changes: 5 additions & 5 deletions pkg/osutil/osutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func TestReplaceGoTemplateVariables(t *testing.T) {
name string
fileSys fs.FS
srcPath string
variableMap map[string]string
variableMap map[string]interface{}
expected string
expectedError bool
}{
Expand All @@ -227,7 +227,7 @@ func TestReplaceGoTemplateVariables(t *testing.T) {
"template.txt": &fstest.MapFile{Data: []byte("Hello, {{.Name}}!")},
},
srcPath: "template.txt",
variableMap: map[string]string{"Name": "Joe"},
variableMap: map[string]interface{}{"Name": "Joe"},
expected: "Hello, Joe!",
expectedError: false,
},
Expand All @@ -237,7 +237,7 @@ func TestReplaceGoTemplateVariables(t *testing.T) {
"template.txt": &fstest.MapFile{Data: []byte("Hello, {{.Name}}!")},
},
srcPath: "template.txt",
variableMap: map[string]string{},
variableMap: map[string]interface{}{},
expected: "",
expectedError: true,
},
Expand All @@ -247,7 +247,7 @@ func TestReplaceGoTemplateVariables(t *testing.T) {
"template.txt": &fstest.MapFile{Data: []byte("Hello, {{.Name}}!")},
},
srcPath: "nonexistent.txt",
variableMap: map[string]string{"Name": "Joe"},
variableMap: map[string]interface{}{"Name": "Joe"},
expected: "",
expectedError: true,
},
Expand All @@ -257,7 +257,7 @@ func TestReplaceGoTemplateVariables(t *testing.T) {
"template.txt": &fstest.MapFile{Data: []byte("Hello, {{.Name}} and {{.Place}}!")},
},
srcPath: "template.txt",
variableMap: map[string]string{"Name": "Joe"},
variableMap: map[string]interface{}{"Name": "Joe"},
expected: "",
expectedError: true,
},
Expand Down
13 changes: 13 additions & 0 deletions template/deployments/helm/charts/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: envvars-configmap
data:
{{- if .Values.envVariables }}
{{- range $key, $value := .Values.envVariables }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
{{- else }}
# No environment variables provided
{{- end }}
3 changes: 3 additions & 0 deletions template/deployments/helm/charts/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ spec:
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
envFrom:
- configMapRef:
name: envvars-configmap
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
5 changes: 4 additions & 1 deletion template/deployments/helm/charts/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ tolerations: []

affinity: {}

generatorLabel: {{.GENERATORLABEL}}
generatorLabel: {{.GENERATORLABEL}}

# environment variables will be read from the configmap.yaml
envVariables: {{.ENVVARIABLES}}
4 changes: 4 additions & 0 deletions template/deployments/helm/draft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ variables:
disablePrompt: true
value: "draft"
description: "the label to identify who generated the resource"
- name: "ENVVARIABLES"
type: "map"
kind: "environmentVariables"
description: "environment variables for the application"
7 changes: 7 additions & 0 deletions template/deployments/kustomize/base/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: envvars-configmap
data:
Vidya2606 marked this conversation as resolved.
Show resolved Hide resolved
{{ .ENVVARIABLES }}

5 changes: 4 additions & 1 deletion template/deployments/kustomize/base/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ spec:
image: {{.IMAGENAME}}:{{.IMAGETAG}}
imagePullPolicy: Always
ports:
- containerPort: {{.PORT}}
- containerPort: {{.PORT}}
envFrom:
- configMapRef:
name: envvars-configmap
3 changes: 2 additions & 1 deletion template/deployments/kustomize/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yaml
- service.yaml
- service.yaml
- configmap.yaml
4 changes: 4 additions & 0 deletions template/deployments/kustomize/draft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ variables:
disablePrompt: true
value: "draft"
description: "the label to identify who generated the resource"
- name: "ENVVARIABLES"
type: "map"
kind: "environmentVariables"
description: "environment variables for the application"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: envvars-configmap
data:
Vidya2606 marked this conversation as resolved.
Show resolved Hide resolved
{{ .ENVVARIABLES }}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ spec:
spec:
containers:
- name: {{.APPNAME}}
image: {{.IMAGENAME}}:{{.IMAGETAG}}
image: {{.IMAGENAME}}:{{.IMAGETAG}}
envFrom:
- configMapRef:
name: envvars-configmap
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ resources:
- ../../base
patchesStrategicMerge:
- deployment.yaml
- service.yaml
- service.yaml
- configmap.yaml
4 changes: 4 additions & 0 deletions template/deployments/manifests/draft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ variables:
disablePrompt: true
value: "draft"
description: "the label to identify who generated the resource"
- name: "ENVVARIABLES"
type: "map"
kind: "environmentVariables"
description: "environment variables for the application"
6 changes: 6 additions & 0 deletions template/deployments/manifests/manifests/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: envvars-configmap
data:
Vidya2606 marked this conversation as resolved.
Show resolved Hide resolved
{{ .ENVVARIABLES }}
5 changes: 4 additions & 1 deletion template/deployments/manifests/manifests/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ spec:
image: {{.IMAGENAME}}:{{.IMAGETAG}}
imagePullPolicy: Always
ports:
- containerPort: {{.PORT}}
- containerPort: {{.PORT}}
envFrom:
- configMapRef:
name: envvars-configmap
Loading