diff --git a/pkg/processor/probes/probes.go b/pkg/processor/probes/probes.go index a956fc1..894d531 100644 --- a/pkg/processor/probes/probes.go +++ b/pkg/processor/probes/probes.go @@ -32,6 +32,15 @@ func ProcessSpecMap(name string, specMap map[string]interface{}, values *helmify return err } + err = templateContainers(name, cs, pspec, strContainers, values) + if err != nil { + return err + } + return unstructured.SetNestedSlice(specMap, strContainers, "containers") + +} + +func templateContainers(name string, cs []interface{}, pspec corev1.PodSpec, strContainers []interface{}, values *helmify.Values) error { for i := range cs { containerName := strcase.ToLowerCamel(pspec.Containers[i].Name) @@ -49,29 +58,27 @@ func ProcessSpecMap(name string, specMap map[string]interface{}, values *helmify return err } } - return unstructured.SetNestedSlice(specMap, strContainers, "containers") - + return nil } func setProbesTemplates(name string, container *corev1.Container, strContainers *interface{}, containerName string) error { - err := templateProbe(name, container.LivenessProbe, strContainers, containerName, livenessProbe) - if err != nil { - return err + if container.LivenessProbe != nil { + live, err := yamlformat.Marshal(container.LivenessProbe, 1) + if err != nil { + return err + } + *strContainers = (*strContainers).(string) + fmt.Sprintf(livenessProbe, name, containerName, live) } - return templateProbe(name, container.ReadinessProbe, strContainers, containerName, readinessProbe) - -} - -func templateProbe(name string, probe *corev1.Probe, strContainers *interface{}, containerName string, template string) error { - if probe != nil { - live, err := yamlformat.Marshal(probe, 1) + if container.ReadinessProbe != nil { + ready, err := yamlformat.Marshal(container.ReadinessProbe, 1) if err != nil { return err } - *strContainers = (*strContainers).(string) + fmt.Sprintf(template, name, containerName, live) + *strContainers = (*strContainers).(string) + fmt.Sprintf(readinessProbe, name, containerName, ready) } return nil + } func setProbeField(name string, c *corev1.Container, values *helmify.Values) error {