diff --git a/pkg/app/context.go b/pkg/app/context.go index 2c4e52eb..5aef94c5 100644 --- a/pkg/app/context.go +++ b/pkg/app/context.go @@ -75,7 +75,7 @@ func (c *appContext) CreateHelm(stop <-chan struct{}) error { default: } } - return c.output.Create(c.config.ChartDir, c.config.ChartName, c.config.Crd, c.config.CertManagerAsSubchart, c.config.CertManagerVersion , templates, filenames) + return c.output.Create(c.config.ChartDir, c.config.ChartName, c.config.Crd, c.config.CertManagerAsSubchart, c.config.CertManagerVersion, templates, filenames) } func (c *appContext) process(obj *unstructured.Unstructured) (helmify.Template, error) { diff --git a/pkg/processor/deployment/deployment.go b/pkg/processor/deployment/deployment.go index b96f7b0d..591c9a2c 100644 --- a/pkg/processor/deployment/deployment.go +++ b/pkg/processor/deployment/deployment.go @@ -98,11 +98,16 @@ func (d deployment) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstr selector = strings.Trim(selector, " \n") selector = string(yamlformat.Indent([]byte(selector), 4)) + nameCamel := strcase.ToLowerCamel(name) podLabels, err := yamlformat.Marshal(depl.Spec.Template.ObjectMeta.Labels, 8) if err != nil { return true, nil, err } - podLabels += fmt.Sprintf("\n {{- include \"%s.selectorLabels\" . | nindent 8 }}", appMeta.ChartName()) + podLabels += fmt.Sprintf("\n {{- include \"%s.selectorLabels\" . | nindent 8 }}\n {{- if .Values.%s.podLabels }}\n {{- toYaml .Values.%s.podLabels | nindent 8 }}\n {{- end }}", appMeta.ChartName(), nameCamel, nameCamel) + err = unstructured.SetNestedField(values, make(map[string]interface{}), nameCamel, "podLabels") + if err != nil { + return true, nil, err + } podAnnotations := "" if len(depl.Spec.Template.ObjectMeta.Annotations) != 0 { @@ -114,7 +119,6 @@ func (d deployment) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstr podAnnotations = "\n" + podAnnotations } - nameCamel := strcase.ToLowerCamel(name) specMap, podValues, err := pod.ProcessSpec(nameCamel, appMeta, depl.Spec.Template.Spec) if err != nil { return true, nil, err diff --git a/pkg/processor/pod/pod.go b/pkg/processor/pod/pod.go index 09979abd..52bc1dcc 100644 --- a/pkg/processor/pod/pod.go +++ b/pkg/processor/pod/pod.go @@ -71,6 +71,28 @@ func ProcessSpec(objName string, appMeta helmify.AppMetadata, spec corev1.PodSpe if err != nil { return nil, nil, err } + + err = unstructured.SetNestedField(specMap, fmt.Sprintf(`{{- toYaml .Values.%s.tolerations | nindent 8 }}`, objName), "tolerations") + if err != nil { + return nil, nil, err + } + uTolerations := make([]interface{}, 0) + for i, toleration := range spec.Tolerations { + uTolerations[i] = map[string]interface{}{ + "value": toleration.Value, + "key": toleration.Key, + "operator": toleration.Operator, + "effect": toleration.Effect, + } + + if toleration.TolerationSeconds != nil { + uTolerations[i].(map[string]interface{})["tolerationSeconds"] = *toleration.TolerationSeconds + } + } + err = unstructured.SetNestedSlice(values, uTolerations, objName, "tolerations") + if err != nil { + return nil, nil, err + } } return specMap, values, nil