Skip to content

Commit

Permalink
feat: added fix
Browse files Browse the repository at this point in the history
Signed-off-by: RealAnna <[email protected]>
  • Loading branch information
RealAnna committed Feb 16, 2023
1 parent f066f13 commit 3180a6b
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions pkg/processor/probes/probes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 {
Expand Down

0 comments on commit 3180a6b

Please sign in to comment.