Skip to content

Commit

Permalink
fix duplicate topologySpreadConstraints
Browse files Browse the repository at this point in the history
  • Loading branch information
arttor committed Mar 13, 2023
1 parent 0294e6b commit db73ef4
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 174 deletions.
1 change: 1 addition & 0 deletions examples/app/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ spec:
- containerPort: 8443
name: https
resources: {}
nodeSelector: {{- toYaml .Values.myapp.nodeSelector | nindent 8 }}
securityContext:
runAsNonRoot: true
terminationGracePeriodSeconds: 10
Expand Down
3 changes: 3 additions & 0 deletions examples/app/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ myapp:
requests:
cpu: 100m
memory: 20Mi
nodeSelector:
region: east
type: user-node
proxySidecar:
image:
repository: gcr.io/kubebuilder/kube-rbac-proxy
Expand Down
6 changes: 2 additions & 4 deletions examples/operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ spec:
name: secret-volume
imagePullSecrets:
- name: {{ include "operator.fullname" . }}-secret-registry-credentials
nodeSelector: {{- toYaml .Values.controllerManager.nodeSelector | nindent 8 }}
securityContext:
runAsNonRoot: true
serviceAccountName: {{ include "operator.fullname" . }}-controller-manager
Expand All @@ -114,7 +115,4 @@ spec:
name: manager-config
- name: secret-volume
secret:
secretName: {{ include "operator.fullname" . }}-secret-ca
{{- if .Values.topologySpreadConstraints }}
topologySpreadConstraints: {{- include "tplvalues.render" (dict "value" .Values.topologySpreadConstraints "context" $) | nindent 8 }}
{{- end }}
secretName: {{ include "operator.fullname" . }}-secret-ca
7 changes: 3 additions & 4 deletions examples/operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ controllerManager:
requests:
cpu: 100m
memory: 20Mi
nodeSelector:
region: east
type: user-node
replicas: 1
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
kubernetesClusterDomain: cluster.local
managerConfig:
controllerManagerConfigYaml:
Expand Down
13 changes: 0 additions & 13 deletions pkg/helm/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,6 @@ Create the name of the service account to use
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
{{/*
Renders a value that contains template.
Usage:
{{ include "tplvalues.render" ( dict "value" .Values.path.to.the.Value "context" $) }}
*/}}
{{- define "tplvalues.render" -}}
{{- if typeIs "string" .value }}
{{- tpl .value .context }}
{{- else }}
{{- tpl (.value | toYaml) .context }}
{{- end }}
{{- end -}}
`

const defaultChartfile = `apiVersion: v2
Expand Down
67 changes: 0 additions & 67 deletions pkg/processor/constraints/constraint.go

This file was deleted.

83 changes: 0 additions & 83 deletions pkg/processor/constraints/constraint_test.go

This file was deleted.

19 changes: 16 additions & 3 deletions pkg/processor/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/arttor/helmify/pkg/cluster"
"github.com/arttor/helmify/pkg/processor"
"github.com/arttor/helmify/pkg/processor/constraints"
"github.com/arttor/helmify/pkg/processor/imagePullSecrets"

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


// New creates processor for k8s Deployment resource.
func New() helmify.Processor {
return &deployment{}
Expand Down Expand Up @@ -165,7 +163,22 @@ func (d deployment) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstr
imagePullSecrets.ProcessSpecMap(specMap, &values)
}

spec := constraints.ProcessSpecMap(nameCamel, specMap, &values, appMeta.Config().GenerateDefaults)
// process nodeSelector if presented:
if len(depl.Spec.Template.Spec.NodeSelector) != 0 {
err = unstructured.SetNestedField(specMap, fmt.Sprintf(`{{- toYaml .Values.%s.nodeSelector | nindent 8 }}`, nameCamel), "nodeSelector")
if err != nil {
return true, nil, err
}
err = unstructured.SetNestedStringMap(values, depl.Spec.Template.Spec.NodeSelector, nameCamel, "nodeSelector")
if err != nil {
return true, nil, err
}
}

spec, err := yamlformat.Marshal(specMap, 6)
if err != nil {
return true, nil, err
}
spec = strings.ReplaceAll(spec, "'", "")

return true, &result{
Expand Down
3 changes: 3 additions & 0 deletions test_data/k8s-operator-kustomize.output
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,9 @@ spec:
allowPrivilegeEscalation: false
securityContext:
runAsNonRoot: true
nodeSelector:
region: east
type: user-node
serviceAccountName: my-operator-controller-manager
terminationGracePeriodSeconds: 10
volumes:
Expand Down
3 changes: 3 additions & 0 deletions test_data/sample-app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ spec:
name: https
securityContext:
runAsNonRoot: true
nodeSelector:
region: east
type: user-node
terminationGracePeriodSeconds: 10
volumes:
- configMap:
Expand Down

0 comments on commit db73ef4

Please sign in to comment.