Skip to content

Commit e4c0916

Browse files
committed
handle empty replicas
1 parent 6233e66 commit e4c0916

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

pkg/processor/deployment/deployment.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ var deploymentGVC = schema.GroupVersionKind{
2828
var deploymentTempl, _ = template.New("deployment").Parse(
2929
`{{- .Meta }}
3030
spec:
31-
replicas: {{ .Replicas }}
31+
{{- if .Replicas }}
32+
{{ .Replicas }}
33+
{{- end }}
3234
selector:
3335
{{ .Selector }}
3436
template:
@@ -68,7 +70,7 @@ func (d deployment) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstr
6870
values := helmify.Values{}
6971

7072
name := appMeta.TrimName(obj.GetName())
71-
replicas, err := values.Add(int64(*depl.Spec.Replicas), name, "replicas")
73+
replicas, err := processReplicas(name, &depl, &values)
7274
if err != nil {
7375
return true, nil, err
7476
}
@@ -164,6 +166,22 @@ func (d deployment) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstr
164166
}, nil
165167
}
166168

169+
func processReplicas(name string, deployment *appsv1.Deployment, values *helmify.Values) (string, error) {
170+
if deployment.Spec.Replicas == nil {
171+
return "", nil
172+
}
173+
replicasTpl, err := values.Add(int64(*deployment.Spec.Replicas), name, "replicas")
174+
if err != nil {
175+
return "", err
176+
}
177+
replicas, err := yamlformat.Marshal(map[string]interface{}{"replicas": replicasTpl}, 2)
178+
if err != nil {
179+
return "", err
180+
}
181+
replicas = strings.ReplaceAll(replicas, "'", "")
182+
return replicas, nil
183+
}
184+
167185
func processPodSpec(name string, appMeta helmify.AppMetadata, pod *corev1.PodSpec) (helmify.Values, error) {
168186
values := helmify.Values{}
169187
for i, c := range pod.Containers {

0 commit comments

Comments
 (0)