diff --git a/.dockerignore b/.dockerignore index 1f9c9352..44e96d03 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,4 +4,4 @@ vendor/ /pkg/workflows/workflow/ .DS_Store draft -langtest \ No newline at end of file +langtest diff --git a/Dockerfile b/Dockerfile index 7b2d1b67..1f556309 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,4 +20,4 @@ COPY . ./ RUN make go-generate RUN go mod download -ENTRYPOINT ["go"] \ No newline at end of file +ENTRYPOINT ["go"] diff --git a/pkg/config/draftconfig.go b/pkg/config/draftconfig.go index fc7c57e3..5c648e2c 100644 --- a/pkg/config/draftconfig.go +++ b/pkg/config/draftconfig.go @@ -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 } diff --git a/pkg/osutil/osutil.go b/pkg/osutil/osutil.go index 4d83f11b..98a9ff9e 100644 --- a/pkg/osutil/osutil.go +++ b/pkg/osutil/osutil.go @@ -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 diff --git a/pkg/osutil/osutil_test.go b/pkg/osutil/osutil_test.go index 33ce8b70..1837492b 100644 --- a/pkg/osutil/osutil_test.go +++ b/pkg/osutil/osutil_test.go @@ -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 }{ @@ -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, }, @@ -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, }, @@ -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, }, @@ -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, }, diff --git a/template/deployments/helm/charts/templates/configmap.yaml b/template/deployments/helm/charts/templates/configmap.yaml new file mode 100644 index 00000000..44d10f52 --- /dev/null +++ b/template/deployments/helm/charts/templates/configmap.yaml @@ -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 }} \ No newline at end of file diff --git a/template/deployments/helm/charts/templates/deployment.yaml b/template/deployments/helm/charts/templates/deployment.yaml index dd1537e0..1d58acbb 100644 --- a/template/deployments/helm/charts/templates/deployment.yaml +++ b/template/deployments/helm/charts/templates/deployment.yaml @@ -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 }} diff --git a/template/deployments/helm/charts/values.yaml b/template/deployments/helm/charts/values.yaml index 321227f8..14331e03 100644 --- a/template/deployments/helm/charts/values.yaml +++ b/template/deployments/helm/charts/values.yaml @@ -60,4 +60,7 @@ tolerations: [] affinity: {} -generatorLabel: {{.GENERATORLABEL}} \ No newline at end of file +generatorLabel: {{.GENERATORLABEL}} + +# environment variables will be read from the configmap.yaml +envVariables: {{.ENVVARIABLES}} \ No newline at end of file diff --git a/template/deployments/helm/draft.yaml b/template/deployments/helm/draft.yaml index eaae9017..55a92db8 100644 --- a/template/deployments/helm/draft.yaml +++ b/template/deployments/helm/draft.yaml @@ -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" \ No newline at end of file diff --git a/template/deployments/kustomize/base/configmap.yaml b/template/deployments/kustomize/base/configmap.yaml new file mode 100644 index 00000000..0063413f --- /dev/null +++ b/template/deployments/kustomize/base/configmap.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: envvars-configmap +data: + {{ .ENVVARIABLES }} + diff --git a/template/deployments/kustomize/base/deployment.yaml b/template/deployments/kustomize/base/deployment.yaml index 4e07bd64..57ee63f0 100644 --- a/template/deployments/kustomize/base/deployment.yaml +++ b/template/deployments/kustomize/base/deployment.yaml @@ -21,4 +21,7 @@ spec: image: {{.IMAGENAME}}:{{.IMAGETAG}} imagePullPolicy: Always ports: - - containerPort: {{.PORT}} \ No newline at end of file + - containerPort: {{.PORT}} + envFrom: + - configMapRef: + name: envvars-configmap \ No newline at end of file diff --git a/template/deployments/kustomize/base/kustomization.yaml b/template/deployments/kustomize/base/kustomization.yaml index ca1d88ef..b04efeef 100644 --- a/template/deployments/kustomize/base/kustomization.yaml +++ b/template/deployments/kustomize/base/kustomization.yaml @@ -2,4 +2,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: - deployment.yaml - - service.yaml \ No newline at end of file + - service.yaml + - configmap.yaml \ No newline at end of file diff --git a/template/deployments/kustomize/draft.yaml b/template/deployments/kustomize/draft.yaml index d8b79d0d..8e3e8db4 100644 --- a/template/deployments/kustomize/draft.yaml +++ b/template/deployments/kustomize/draft.yaml @@ -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" \ No newline at end of file diff --git a/template/deployments/kustomize/overlays/production/configmap.yaml b/template/deployments/kustomize/overlays/production/configmap.yaml new file mode 100644 index 00000000..5d99e8c5 --- /dev/null +++ b/template/deployments/kustomize/overlays/production/configmap.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: envvars-configmap +data: + {{ .ENVVARIABLES }} diff --git a/template/deployments/kustomize/overlays/production/deployment.yaml b/template/deployments/kustomize/overlays/production/deployment.yaml index 0929b145..73861e1f 100644 --- a/template/deployments/kustomize/overlays/production/deployment.yaml +++ b/template/deployments/kustomize/overlays/production/deployment.yaml @@ -14,4 +14,7 @@ spec: spec: containers: - name: {{.APPNAME}} - image: {{.IMAGENAME}}:{{.IMAGETAG}} \ No newline at end of file + image: {{.IMAGENAME}}:{{.IMAGETAG}} + envFrom: + - configMapRef: + name: envvars-configmap \ No newline at end of file diff --git a/template/deployments/kustomize/overlays/production/kustomization.yaml b/template/deployments/kustomize/overlays/production/kustomization.yaml index d13c9cee..1cf6ad84 100644 --- a/template/deployments/kustomize/overlays/production/kustomization.yaml +++ b/template/deployments/kustomize/overlays/production/kustomization.yaml @@ -4,4 +4,5 @@ resources: - ../../base patchesStrategicMerge: - deployment.yaml - - service.yaml \ No newline at end of file + - service.yaml + - configmap.yaml \ No newline at end of file diff --git a/template/deployments/manifests/draft.yaml b/template/deployments/manifests/draft.yaml index 168794ad..6f4f329a 100644 --- a/template/deployments/manifests/draft.yaml +++ b/template/deployments/manifests/draft.yaml @@ -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" \ No newline at end of file diff --git a/template/deployments/manifests/manifests/configmap.yaml b/template/deployments/manifests/manifests/configmap.yaml new file mode 100644 index 00000000..fd7c2619 --- /dev/null +++ b/template/deployments/manifests/manifests/configmap.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: envvars-configmap +data: + {{ .ENVVARIABLES }} \ No newline at end of file diff --git a/template/deployments/manifests/manifests/deployment.yaml b/template/deployments/manifests/manifests/deployment.yaml index 4e07bd64..57ee63f0 100644 --- a/template/deployments/manifests/manifests/deployment.yaml +++ b/template/deployments/manifests/manifests/deployment.yaml @@ -21,4 +21,7 @@ spec: image: {{.IMAGENAME}}:{{.IMAGETAG}} imagePullPolicy: Always ports: - - containerPort: {{.PORT}} \ No newline at end of file + - containerPort: {{.PORT}} + envFrom: + - configMapRef: + name: envvars-configmap \ No newline at end of file