Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/app/templates/cron-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ spec:
name: hello
resources: {}
nodeSelector: {{- toYaml .Values.cronJob.nodeSelector | nindent 12 }}
priorityClassName: {{ .Values.cronJob.priorityClassName }}
restartPolicy: OnFailure
serviceAccountName: {{ include "app.serviceAccountName" . }}
tolerations: {{- toYaml .Values.cronJob.tolerations | nindent 12 }}
Expand Down
1 change: 1 addition & 0 deletions examples/app/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ spec:
name: varlibdockercontainers
readOnly: true
nodeSelector: {{- toYaml .Values.fluentdElasticsearch.nodeSelector | nindent 8 }}
priorityClassName: {{ .Values.fluentdElasticsearch.priorityClassName }}
serviceAccountName: {{ include "app.serviceAccountName" . }}
terminationGracePeriodSeconds: 30
tolerations: {{- toYaml .Values.fluentdElasticsearch.tolerations | nindent 8 }}
Expand Down
1 change: 1 addition & 0 deletions examples/app/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ spec:
name: init-container
resources: {}
nodeSelector: {{- toYaml .Values.myapp.nodeSelector | nindent 8 }}
priorityClassName: {{ .Values.myapp.priorityClassName }}
securityContext: {{- toYaml .Values.myapp.podSecurityContext | nindent 8 }}
serviceAccountName: {{ include "app.serviceAccountName" . }}
terminationGracePeriodSeconds: 10
Expand Down
1 change: 1 addition & 0 deletions examples/app/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ spec:
- mountPath: /usr/share/nginx/html
name: www
nodeSelector: {{- toYaml .Values.web.nodeSelector | nindent 8 }}
priorityClassName: {{ .Values.web.priorityClassName }}
serviceAccountName: {{ include "app.serviceAccountName" . }}
tolerations: {{- toYaml .Values.web.tolerations | nindent 8 }}
topologySpreadConstraints: {{- toYaml .Values.web.topologySpreadConstraints |
Expand Down
4 changes: 4 additions & 0 deletions examples/app/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ cronJob:
tag: "1.28"
imagePullPolicy: IfNotPresent
nodeSelector: {}
priorityClassName: low-priority
schedule: '* * * * *'
tolerations: []
topologySpreadConstraints: []
Expand All @@ -29,6 +30,7 @@ fluentdElasticsearch:
cpu: 100m
memory: 200Mi
nodeSelector: {}
priorityClassName: system-node-critical
tolerations:
- effect: NoSchedule
key: node-role.kubernetes.io/master
Expand Down Expand Up @@ -99,6 +101,7 @@ myapp:
fsGroup: 20000
runAsNonRoot: true
runAsUser: 65532
priorityClassName: system-cluster-critical
proxySidecar:
args:
- --secure-listen-address=0.0.0.0:8443
Expand Down Expand Up @@ -152,6 +155,7 @@ web:
repository: registry.k8s.io/nginx-slim
tag: "0.8"
nodeSelector: {}
priorityClassName: high-priority
replicas: 2
tolerations: []
topologySpreadConstraints: []
Expand Down
11 changes: 11 additions & 0 deletions pkg/processor/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ func ProcessSpec(objName string, appMeta helmify.AppMetadata, spec corev1.PodSpe
}
}

if spec.PriorityClassName != "" {
err = unstructured.SetNestedField(specMap, fmt.Sprintf(`{{ .Values.%s.priorityClassName }}`, objName), "priorityClassName")
if err != nil {
return nil, nil, err
}
err = unstructured.SetNestedField(values, spec.PriorityClassName, objName, "priorityClassName")
if err != nil {
return nil, nil, err
}
}

// process tolerations if presented:
err = unstructured.SetNestedField(specMap, fmt.Sprintf(`{{- toYaml .Values.%s.tolerations | nindent %d }}`, objName, nindent), "tolerations")
if err != nil {
Expand Down
65 changes: 65 additions & 0 deletions pkg/processor/pod/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,29 @@ spec:
- key: node-role.kubernetes.io/control-plane
operator: Exists

`
strDeploymentWithPriorityClassName = `
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: localhost:6001/my_project:latest
priorityClassName: high-priority

`
)

Expand Down Expand Up @@ -462,4 +485,46 @@ func Test_pod_Process(t *testing.T) {
},
}, tmpl)
})
t.Run("deployment with priorityClassName", func(t *testing.T) {
var deploy appsv1.Deployment
obj := internal.GenerateObj(strDeploymentWithPriorityClassName)
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &deploy)
specMap, tmpl, err := ProcessSpec("nginx", &metadata.Service{}, deploy.Spec.Template.Spec, 0)
assert.NoError(t, err)
assert.Equal(t, map[string]interface{}{
"containers": []interface{}{
map[string]interface{}{
"env": []interface{}{
map[string]interface{}{
"name": "KUBERNETES_CLUSTER_DOMAIN",
"value": "{{ quote .Values.kubernetesClusterDomain }}",
},
},
"image": "{{ .Values.nginx.nginx.image.repository }}:{{ .Values.nginx.nginx.image.tag | default .Chart.AppVersion }}",
"name": "nginx",
"resources": map[string]interface{}{},
},
},
"nodeSelector": "{{- toYaml .Values.nginx.nodeSelector | nindent 8 }}",
"serviceAccountName": `{{ include ".serviceAccountName" . }}`,
"tolerations": "{{- toYaml .Values.nginx.tolerations | nindent 8 }}",
"topologySpreadConstraints": "{{- toYaml .Values.nginx.topologySpreadConstraints | nindent 8 }}",
"priorityClassName": "{{ .Values.nginx.priorityClassName }}",
}, specMap)

assert.Equal(t, helmify.Values{
"nginx": map[string]interface{}{
"priorityClassName": "high-priority",
"nginx": map[string]interface{}{
"image": map[string]interface{}{
"repository": "localhost:6001/my_project",
"tag": "latest",
},
},
"nodeSelector": map[string]interface{}{},
"tolerations": []interface{}{},
"topologySpreadConstraints": []interface{}{},
},
}, tmpl)
})
}
4 changes: 4 additions & 0 deletions test_data/sample-app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ spec:
- matchExpressions:
- key: node-role.kubernetes.io/control-plane
operator: Exists
priorityClassName: system-cluster-critical
terminationGracePeriodSeconds: 10
volumes:
- configMap:
Expand Down Expand Up @@ -278,6 +279,7 @@ spec:
labels:
name: fluentd-elasticsearch
spec:
priorityClassName: system-node-critical
tolerations:
# this toleration is to have the daemonset runnable on master nodes
# remove it if your masters can't run pods
Expand Down Expand Up @@ -332,6 +334,7 @@ spec:
spec:
template:
spec:
priorityClassName: low-priority
containers:
- name: hello
image: busybox:1.28
Expand Down Expand Up @@ -371,6 +374,7 @@ spec:
labels:
app: nginx
spec:
priorityClassName: high-priority
containers:
- name: nginx
image: registry.k8s.io/nginx-slim:0.8
Expand Down
Loading