From 44baabb6c96e51fe6add03fa7b7775aa5027e567 Mon Sep 17 00:00:00 2001 From: Rewant Soni Date: Tue, 28 Apr 2026 13:44:53 +0530 Subject: [PATCH 1/2] add: priorityClassName Signed-off-by: Rewant Soni --- pkg/processor/pod/pod.go | 12 +++++++ pkg/processor/pod/pod_test.go | 65 +++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/pkg/processor/pod/pod.go b/pkg/processor/pod/pod.go index 4d6ae275..a3574948 100644 --- a/pkg/processor/pod/pod.go +++ b/pkg/processor/pod/pod.go @@ -115,6 +115,18 @@ func ProcessSpec(objName string, appMeta helmify.AppMetadata, spec corev1.PodSpe } } + // process priorityClassName if presented: + 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 { diff --git a/pkg/processor/pod/pod_test.go b/pkg/processor/pod/pod_test.go index dfe14529..f3dea5ff 100644 --- a/pkg/processor/pod/pod_test.go +++ b/pkg/processor/pod/pod_test.go @@ -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 + ` ) @@ -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) + }) } From 1dcc850b10b6694902010658d66342f737fcd73e Mon Sep 17 00:00:00 2001 From: Rewant Soni Date: Tue, 28 Apr 2026 13:51:44 +0530 Subject: [PATCH 2/2] add priorityClassName to the test data Signed-off-by: Rewant Soni --- examples/app/templates/cron-job.yaml | 1 + examples/app/templates/daemonset.yaml | 1 + examples/app/templates/deployment.yaml | 1 + examples/app/templates/statefulset.yaml | 1 + examples/app/values.yaml | 4 ++++ pkg/processor/pod/pod.go | 1 - test_data/sample-app.yaml | 4 ++++ 7 files changed, 12 insertions(+), 1 deletion(-) diff --git a/examples/app/templates/cron-job.yaml b/examples/app/templates/cron-job.yaml index 3025af6f..4e4c3cd4 100644 --- a/examples/app/templates/cron-job.yaml +++ b/examples/app/templates/cron-job.yaml @@ -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 }} diff --git a/examples/app/templates/daemonset.yaml b/examples/app/templates/daemonset.yaml index 06eedd41..9e8ba3ff 100644 --- a/examples/app/templates/daemonset.yaml +++ b/examples/app/templates/daemonset.yaml @@ -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 }} diff --git a/examples/app/templates/deployment.yaml b/examples/app/templates/deployment.yaml index e591c525..41d31555 100644 --- a/examples/app/templates/deployment.yaml +++ b/examples/app/templates/deployment.yaml @@ -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 diff --git a/examples/app/templates/statefulset.yaml b/examples/app/templates/statefulset.yaml index 641cc376..be9cf084 100644 --- a/examples/app/templates/statefulset.yaml +++ b/examples/app/templates/statefulset.yaml @@ -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 | diff --git a/examples/app/values.yaml b/examples/app/values.yaml index 3c1edaed..547b1880 100644 --- a/examples/app/values.yaml +++ b/examples/app/values.yaml @@ -14,6 +14,7 @@ cronJob: tag: "1.28" imagePullPolicy: IfNotPresent nodeSelector: {} + priorityClassName: low-priority schedule: '* * * * *' tolerations: [] topologySpreadConstraints: [] @@ -29,6 +30,7 @@ fluentdElasticsearch: cpu: 100m memory: 200Mi nodeSelector: {} + priorityClassName: system-node-critical tolerations: - effect: NoSchedule key: node-role.kubernetes.io/master @@ -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 @@ -152,6 +155,7 @@ web: repository: registry.k8s.io/nginx-slim tag: "0.8" nodeSelector: {} + priorityClassName: high-priority replicas: 2 tolerations: [] topologySpreadConstraints: [] diff --git a/pkg/processor/pod/pod.go b/pkg/processor/pod/pod.go index a3574948..2f033f79 100644 --- a/pkg/processor/pod/pod.go +++ b/pkg/processor/pod/pod.go @@ -115,7 +115,6 @@ func ProcessSpec(objName string, appMeta helmify.AppMetadata, spec corev1.PodSpe } } - // process priorityClassName if presented: if spec.PriorityClassName != "" { err = unstructured.SetNestedField(specMap, fmt.Sprintf(`{{ .Values.%s.priorityClassName }}`, objName), "priorityClassName") if err != nil { diff --git a/test_data/sample-app.yaml b/test_data/sample-app.yaml index d13bb8da..0000d7c8 100644 --- a/test_data/sample-app.yaml +++ b/test_data/sample-app.yaml @@ -101,6 +101,7 @@ spec: - matchExpressions: - key: node-role.kubernetes.io/control-plane operator: Exists + priorityClassName: system-cluster-critical terminationGracePeriodSeconds: 10 volumes: - configMap: @@ -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 @@ -332,6 +334,7 @@ spec: spec: template: spec: + priorityClassName: low-priority containers: - name: hello image: busybox:1.28 @@ -371,6 +374,7 @@ spec: labels: app: nginx spec: + priorityClassName: high-priority containers: - name: nginx image: registry.k8s.io/nginx-slim:0.8