Skip to content

Commit

Permalink
handle empty replicas
Browse files Browse the repository at this point in the history
  • Loading branch information
arttor committed Oct 20, 2021
1 parent 6233e66 commit e4c0916
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions pkg/processor/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ var deploymentGVC = schema.GroupVersionKind{
var deploymentTempl, _ = template.New("deployment").Parse(
`{{- .Meta }}
spec:
replicas: {{ .Replicas }}
{{- if .Replicas }}
{{ .Replicas }}
{{- end }}
selector:
{{ .Selector }}
template:
Expand Down Expand Up @@ -68,7 +70,7 @@ func (d deployment) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstr
values := helmify.Values{}

name := appMeta.TrimName(obj.GetName())
replicas, err := values.Add(int64(*depl.Spec.Replicas), name, "replicas")
replicas, err := processReplicas(name, &depl, &values)
if err != nil {
return true, nil, err
}
Expand Down Expand Up @@ -164,6 +166,22 @@ func (d deployment) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstr
}, nil
}

func processReplicas(name string, deployment *appsv1.Deployment, values *helmify.Values) (string, error) {
if deployment.Spec.Replicas == nil {
return "", nil
}
replicasTpl, err := values.Add(int64(*deployment.Spec.Replicas), name, "replicas")
if err != nil {
return "", err
}
replicas, err := yamlformat.Marshal(map[string]interface{}{"replicas": replicasTpl}, 2)
if err != nil {
return "", err
}
replicas = strings.ReplaceAll(replicas, "'", "")
return replicas, nil
}

func processPodSpec(name string, appMeta helmify.AppMetadata, pod *corev1.PodSpec) (helmify.Values, error) {
values := helmify.Values{}
for i, c := range pod.Containers {
Expand Down

0 comments on commit e4c0916

Please sign in to comment.