Skip to content

Commit

Permalink
fix: default resources mutated when applying templates (#1948)
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Wang <[email protected]>
  • Loading branch information
whynowy authored and KeranYang committed Aug 19, 2024
1 parent 5a53162 commit 447cd3f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/apis/numaflow/v1alpha1/container_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (b containerBuilder) init(req getContainerReq) containerBuilder {
b.Image = req.image
b.ImagePullPolicy = req.imagePullPolicy
b.Name = CtrMain
b.Resources = req.resources
b.Resources = *req.resources.DeepCopy()
b.VolumeMounts = req.volumeMounts
return b
}
Expand Down
29 changes: 29 additions & 0 deletions pkg/apis/numaflow/v1alpha1/vertex_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
resource "k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
)
Expand Down Expand Up @@ -198,7 +199,15 @@ func TestGetPodSpec(t *testing.T) {
{Name: "test-env", Value: "test-val"},
},
SideInputsStoreName: "test-store",
DefaultResources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("100m"),
corev1.ResourceMemory: resource.MustParse("100Mi"),
},
Limits: corev1.ResourceList{},
},
}

t.Run("test source", func(t *testing.T) {
testObj := testVertex.DeepCopy()
testObj.Spec.Source = &Source{}
Expand All @@ -215,6 +224,18 @@ func TestGetPodSpec(t *testing.T) {
DNSPolicy: corev1.DNSClusterFirstWithHostNet,
DNSConfig: &corev1.PodDNSConfig{Nameservers: []string{"aaa.aaa"}},
}
testObj.Spec.ContainerTemplate = &ContainerTemplate{
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("200m"),
corev1.ResourceMemory: resource.MustParse("200Mi"),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("200m"),
corev1.ResourceMemory: resource.MustParse("200Mi"),
},
},
}
s, err := testObj.GetPodSpec(req)
assert.NoError(t, err)
assert.NotNil(t, s.NodeSelector)
Expand Down Expand Up @@ -252,6 +273,14 @@ func TestGetPodSpec(t *testing.T) {
assert.Contains(t, s.Containers[0].Args, "--type="+string(VertexTypeSource))
assert.Equal(t, 1, len(s.InitContainers))
assert.Equal(t, CtrInit, s.InitContainers[0].Name)
assert.Equal(t, "200m", s.Containers[0].Resources.Requests.Cpu().String())
assert.Equal(t, "200m", s.Containers[0].Resources.Limits.Cpu().String())
assert.Equal(t, "200Mi", s.Containers[0].Resources.Requests.Memory().String())
assert.Equal(t, "200Mi", s.Containers[0].Resources.Limits.Memory().String())
assert.Equal(t, "100m", s.InitContainers[0].Resources.Requests.Cpu().String())
assert.Equal(t, "100Mi", s.InitContainers[0].Resources.Requests.Memory().String())
assert.Equal(t, "0", s.InitContainers[0].Resources.Limits.Cpu().String())
assert.Equal(t, "0", s.InitContainers[0].Resources.Limits.Memory().String())
})

t.Run("test sink", func(t *testing.T) {
Expand Down

0 comments on commit 447cd3f

Please sign in to comment.