Skip to content

Commit db73ef4

Browse files
committed
fix duplicate topologySpreadConstraints
1 parent 0294e6b commit db73ef4

File tree

10 files changed

+31
-174
lines changed

10 files changed

+31
-174
lines changed

examples/app/templates/deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ spec:
8181
- containerPort: 8443
8282
name: https
8383
resources: {}
84+
nodeSelector: {{- toYaml .Values.myapp.nodeSelector | nindent 8 }}
8485
securityContext:
8586
runAsNonRoot: true
8687
terminationGracePeriodSeconds: 10

examples/app/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ myapp:
5353
requests:
5454
cpu: 100m
5555
memory: 20Mi
56+
nodeSelector:
57+
region: east
58+
type: user-node
5659
proxySidecar:
5760
image:
5861
repository: gcr.io/kubebuilder/kube-rbac-proxy

examples/operator/templates/deployment.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ spec:
100100
name: secret-volume
101101
imagePullSecrets:
102102
- name: {{ include "operator.fullname" . }}-secret-registry-credentials
103+
nodeSelector: {{- toYaml .Values.controllerManager.nodeSelector | nindent 8 }}
103104
securityContext:
104105
runAsNonRoot: true
105106
serviceAccountName: {{ include "operator.fullname" . }}-controller-manager
@@ -114,7 +115,4 @@ spec:
114115
name: manager-config
115116
- name: secret-volume
116117
secret:
117-
secretName: {{ include "operator.fullname" . }}-secret-ca
118-
{{- if .Values.topologySpreadConstraints }}
119-
topologySpreadConstraints: {{- include "tplvalues.render" (dict "value" .Values.topologySpreadConstraints "context" $) | nindent 8 }}
120-
{{- end }}
118+
secretName: {{ include "operator.fullname" . }}-secret-ca

examples/operator/values.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ controllerManager:
2020
requests:
2121
cpu: 100m
2222
memory: 20Mi
23+
nodeSelector:
24+
region: east
25+
type: user-node
2326
replicas: 1
24-
topologySpreadConstraints:
25-
- maxSkew: 1
26-
topologyKey: kubernetes.io/hostname
27-
whenUnsatisfiable: DoNotSchedule
2827
kubernetesClusterDomain: cluster.local
2928
managerConfig:
3029
controllerManagerConfigYaml:

pkg/helm/init.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,6 @@ Create the name of the service account to use
9999
{{- default "default" .Values.serviceAccount.name }}
100100
{{- end }}
101101
{{- end }}
102-
103-
{{/*
104-
Renders a value that contains template.
105-
Usage:
106-
{{ include "tplvalues.render" ( dict "value" .Values.path.to.the.Value "context" $) }}
107-
*/}}
108-
{{- define "tplvalues.render" -}}
109-
{{- if typeIs "string" .value }}
110-
{{- tpl .value .context }}
111-
{{- else }}
112-
{{- tpl (.value | toYaml) .context }}
113-
{{- end }}
114-
{{- end -}}
115102
`
116103

117104
const defaultChartfile = `apiVersion: v2

pkg/processor/constraints/constraint.go

Lines changed: 0 additions & 67 deletions
This file was deleted.

pkg/processor/constraints/constraint_test.go

Lines changed: 0 additions & 83 deletions
This file was deleted.

pkg/processor/deployment/deployment.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/arttor/helmify/pkg/cluster"
1010
"github.com/arttor/helmify/pkg/processor"
11-
"github.com/arttor/helmify/pkg/processor/constraints"
1211
"github.com/arttor/helmify/pkg/processor/imagePullSecrets"
1312

1413
"github.com/arttor/helmify/pkg/helmify"
@@ -51,7 +50,6 @@ const selectorTempl = `%[1]s
5150
const imagePullPolicyTemplate = "{{ .Values.%[1]s.%[2]s.imagePullPolicy }}"
5251
const envValue = "{{ .Values.%[1]s.%[2]s.%[3]s.%[4]s }}"
5352

54-
5553
// New creates processor for k8s Deployment resource.
5654
func New() helmify.Processor {
5755
return &deployment{}
@@ -165,7 +163,22 @@ func (d deployment) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstr
165163
imagePullSecrets.ProcessSpecMap(specMap, &values)
166164
}
167165

168-
spec := constraints.ProcessSpecMap(nameCamel, specMap, &values, appMeta.Config().GenerateDefaults)
166+
// process nodeSelector if presented:
167+
if len(depl.Spec.Template.Spec.NodeSelector) != 0 {
168+
err = unstructured.SetNestedField(specMap, fmt.Sprintf(`{{- toYaml .Values.%s.nodeSelector | nindent 8 }}`, nameCamel), "nodeSelector")
169+
if err != nil {
170+
return true, nil, err
171+
}
172+
err = unstructured.SetNestedStringMap(values, depl.Spec.Template.Spec.NodeSelector, nameCamel, "nodeSelector")
173+
if err != nil {
174+
return true, nil, err
175+
}
176+
}
177+
178+
spec, err := yamlformat.Marshal(specMap, 6)
179+
if err != nil {
180+
return true, nil, err
181+
}
169182
spec = strings.ReplaceAll(spec, "'", "")
170183

171184
return true, &result{

test_data/k8s-operator-kustomize.output

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,9 @@ spec:
667667
allowPrivilegeEscalation: false
668668
securityContext:
669669
runAsNonRoot: true
670+
nodeSelector:
671+
region: east
672+
type: user-node
670673
serviceAccountName: my-operator-controller-manager
671674
terminationGracePeriodSeconds: 10
672675
volumes:

test_data/sample-app.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ spec:
7979
name: https
8080
securityContext:
8181
runAsNonRoot: true
82+
nodeSelector:
83+
region: east
84+
type: user-node
8285
terminationGracePeriodSeconds: 10
8386
volumes:
8487
- configMap:

0 commit comments

Comments
 (0)