Skip to content

Commit

Permalink
fix: container resource for jetstream isbsvc. Fixes #253 (#254)
Browse files Browse the repository at this point in the history
Signed-off-by: David Seapy <[email protected]>
  • Loading branch information
dseapy authored and whynowy committed Oct 27, 2022
1 parent 33ce742 commit 3436049
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/apis/numaflow/v1alpha1/jetstream_buffer_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,11 @@ func (j JetStreamBufferService) GetStatefulSetSpec(req GetJetStreamStatefulSetSp
if j.ContainerTemplate != nil {
spec.Template.Spec.Containers[0].Resources = j.ContainerTemplate.Resources
}
if j.ReloaderContainerTemplate != nil {
spec.Template.Spec.Containers[1].Resources = j.ReloaderContainerTemplate.Resources
}
if j.MetricsContainerTemplate != nil {
spec.Template.Spec.Containers[1].Resources = j.MetricsContainerTemplate.Resources
spec.Template.Spec.Containers[2].Resources = j.MetricsContainerTemplate.Resources
}
if j.Persistence != nil {
volMode := corev1.PersistentVolumeFilesystem
Expand Down
18 changes: 18 additions & 0 deletions pkg/apis/numaflow/v1alpha1/jetstream_buffer_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

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

func TestJetStreamGetStatefulSetSpec(t *testing.T) {
Expand Down Expand Up @@ -68,6 +69,23 @@ func TestJetStreamGetStatefulSetSpec(t *testing.T) {
assert.Equal(t, "config-volume", spec.Template.Spec.Volumes[1].Name)
assert.Equal(t, 7, len(spec.Template.Spec.Volumes[1].VolumeSource.Projected.Sources[1].Secret.Items))
})

t.Run("with container resources", func(t *testing.T) {
r := corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse("100Mi"),
},
}
s := &JetStreamBufferService{
ContainerTemplate: &ContainerTemplate{Resources: r},
ReloaderContainerTemplate: &ContainerTemplate{Resources: r},
MetricsContainerTemplate: &ContainerTemplate{Resources: r},
}
spec := s.GetStatefulSetSpec(req)
for _, c := range spec.Template.Spec.Containers {
assert.Equal(t, c.Resources, r)
}
})
}

func TestJetStreamGetServiceSpec(t *testing.T) {
Expand Down
19 changes: 19 additions & 0 deletions pkg/apis/numaflow/v1alpha1/redis_buffer_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"testing"

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

func TestRedisGetStatefulSetSpec(t *testing.T) {
Expand Down Expand Up @@ -55,6 +57,23 @@ func TestRedisGetStatefulSetSpec(t *testing.T) {
assert.NotNil(t, spec.Template.Spec.Containers[1].SecurityContext)
assert.NotNil(t, spec.Template.Spec.SecurityContext.FSGroup)
})

t.Run("with container resources", func(t *testing.T) {
r := corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse("100Mi"),
},
}
s := &NativeRedis{
RedisContainerTemplate: &ContainerTemplate{Resources: r},
SentinelContainerTemplate: &ContainerTemplate{Resources: r},
MetricsContainerTemplate: &ContainerTemplate{Resources: r},
}
spec := s.GetStatefulSetSpec(req)
for _, c := range spec.Template.Spec.Containers {
assert.Equal(t, c.Resources, r)
}
})
}

func TestRedisGetServiceSpec(t *testing.T) {
Expand Down

0 comments on commit 3436049

Please sign in to comment.