Skip to content

Commit

Permalink
fix: podSpec incorrectly configured in case template exist (#1516)
Browse files Browse the repository at this point in the history
Signed-off-by: Nishchith Shetty <[email protected]>
  • Loading branch information
inishchith authored Feb 23, 2024
1 parent 37a9d5d commit 762e130
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 12 deletions.
48 changes: 36 additions & 12 deletions pkg/apis/numaflow/v1alpha1/pod_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,42 @@ type AbstractPodTemplate struct {

// ApplyToPodSpec updates the PodSpec with the values in the AbstractPodTemplate
func (apt *AbstractPodTemplate) ApplyToPodSpec(ps *corev1.PodSpec) {
ps.NodeSelector = apt.NodeSelector
ps.Tolerations = apt.Tolerations
ps.SecurityContext = apt.SecurityContext
ps.ImagePullSecrets = apt.ImagePullSecrets
ps.PriorityClassName = apt.PriorityClassName
ps.Priority = apt.Priority
ps.Affinity = apt.Affinity
ps.ServiceAccountName = apt.ServiceAccountName
ps.RuntimeClassName = apt.RuntimeClassName
ps.AutomountServiceAccountToken = apt.AutomountServiceAccountToken
ps.DNSPolicy = apt.DNSPolicy
ps.DNSConfig = apt.DNSConfig
if len(ps.NodeSelector) == 0 {
ps.NodeSelector = apt.NodeSelector
}
if len(ps.Tolerations) == 0 {
ps.Tolerations = apt.Tolerations
}
if ps.SecurityContext == nil {
ps.SecurityContext = apt.SecurityContext
}
if len(ps.ImagePullSecrets) == 0 {
ps.ImagePullSecrets = apt.ImagePullSecrets
}
if ps.PriorityClassName == "" {
ps.PriorityClassName = apt.PriorityClassName
}
if ps.Priority == nil {
ps.Priority = apt.Priority
}
if ps.Affinity == nil {
ps.Affinity = apt.Affinity
}
if ps.ServiceAccountName == "" {
ps.ServiceAccountName = apt.ServiceAccountName
}
if ps.RuntimeClassName == nil {
ps.RuntimeClassName = apt.RuntimeClassName
}
if ps.AutomountServiceAccountToken == nil {
ps.AutomountServiceAccountToken = apt.AutomountServiceAccountToken
}
if ps.DNSPolicy == "" {
ps.DNSPolicy = apt.DNSPolicy
}
if ps.DNSConfig == nil {
ps.DNSConfig = apt.DNSConfig
}
}

// ApplyToPodTemplateSpec updates the PodTemplateSpec with the values in the AbstractPodTemplate
Expand Down
79 changes: 79 additions & 0 deletions pkg/apis/numaflow/v1alpha1/pod_template_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package v1alpha1

import (
"testing"

"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
)

func TestApplyToPodSpec(t *testing.T) {
runAsUser := int64(1001)
runAsUser0 := int64(0)
priority := int32(100)

abstractPodTemplate := &AbstractPodTemplate{
Metadata: &Metadata{
Annotations: map[string]string{"my-annotation-name": "my-annotation-value"},
Labels: map[string]string{"my-label-name": "my-label-value"},
},
NodeSelector: map[string]string{"my-node-selector-name": "my-node-selector-value"},
SecurityContext: &corev1.PodSecurityContext{
RunAsUser: &runAsUser,
RunAsGroup: &runAsUser0,
},
Tolerations: []corev1.Toleration{
{
Key: "my-toleration-key",
Operator: "Equal",
Value: "my-toleration-value",
Effect: "NoSchedule",
},
},
ImagePullSecrets: []corev1.LocalObjectReference{
{
Name: "template-image-pull-secret",
},
},
PriorityClassName: "my-priority-class-name",
Priority: &priority,
Affinity: &corev1.Affinity{
NodeAffinity: &corev1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{
NodeSelectorTerms: []corev1.NodeSelectorTerm{
{
MatchExpressions: []corev1.NodeSelectorRequirement{
{
Key: "m",
Operator: "n",
Values: []string{"o"},
},
},
},
},
},
},
},
ServiceAccountName: "template-sa",
}

podSpec := &corev1.PodSpec{
ServiceAccountName: "spec-sa",
ImagePullSecrets: []corev1.LocalObjectReference{
{
Name: "spec-image-pull-secret",
},
},
}

abstractPodTemplate.ApplyToPodSpec(podSpec)

assert.Equal(t, podSpec.NodeSelector, abstractPodTemplate.NodeSelector)
assert.Equal(t, podSpec.Tolerations, abstractPodTemplate.Tolerations)
assert.Equal(t, podSpec.SecurityContext, abstractPodTemplate.SecurityContext)
assert.Equal(t, podSpec.ImagePullSecrets[0].Name, "spec-image-pull-secret")
assert.Equal(t, podSpec.PriorityClassName, abstractPodTemplate.PriorityClassName)
assert.Equal(t, podSpec.Priority, abstractPodTemplate.Priority)
assert.Equal(t, podSpec.Affinity, abstractPodTemplate.Affinity)
assert.Equal(t, podSpec.ServiceAccountName, "spec-sa")
}

0 comments on commit 762e130

Please sign in to comment.