Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: default resources mutated when applying templates #1948

Merged
merged 1 commit into from
Aug 15, 2024
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
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
Loading