Repository: numaproj/numaflow (go)

Issue:
Missing/mismatched container resource for jetstream isbsvc
**Describe the bug**

When setting container resources on a jetstream InterStepBufferService the reloader and metrics containers in the sts don't match what is set in the isbsvc CR.

**To Reproduce**
Steps to reproduce the behavior:

1. `kubectl apply -f <js-isbs-file>`
```
apiVersion: numaflow.numaproj.io/v1alpha1
kind: InterStepBufferService
metadata:
  name: default
spec:
  jetstream:
    version: latest
    containerTemplate:
      resources:
        requests:
          cpu: 100m
        limits:
          memory: 100Mi
    reloaderContainerTemplate:
      resources:
        requests:
          cpu: 10m
        limits:
          memory: 50Mi
    metricsContainerTemplate:
      resources:
        requests:
          cpu: 20m
        limits:
          memory: 50Mi
```
2. `kubectl get sts isbsvc-default-js -oyaml`  note missing/incorrect resources

**Expected behavior**
Resources to be set on all the containers

**Environment (please complete the following information):**

- Kubernetes: 1.25.3
- Numaflow: head of main

---

<!-- Issue Author: Don't delete this message to encourage other users to support your issue! -->

**Message from the maintainers**:

Impacted by this bug? Give it a 👍. We often sort issues this way to know what to prioritize.


Pull request description:
fix: container resource for jetstream isbsvc. Fixes #253
Signed-off-by: David Seapy <dseapy@gmail.com>

Fixes: #253

Fixes container resources on jetstream isbsvc sts.


Patch:
diff --git a/pkg/apis/numaflow/v1alpha1/jetstream_buffer_service.go b/pkg/apis/numaflow/v1alpha1/jetstream_buffer_service.go
index 4be0735b..6493c0b9 100644
--- a/pkg/apis/numaflow/v1alpha1/jetstream_buffer_service.go
+++ b/pkg/apis/numaflow/v1alpha1/jetstream_buffer_service.go
@@ -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


Test patch:
diff --git a/pkg/apis/numaflow/v1alpha1/jetstream_buffer_service_test.go b/pkg/apis/numaflow/v1alpha1/jetstream_buffer_service_test.go
index c42a2271..2a9c8b03 100644
--- a/pkg/apis/numaflow/v1alpha1/jetstream_buffer_service_test.go
+++ b/pkg/apis/numaflow/v1alpha1/jetstream_buffer_service_test.go
@@ -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) {
@@ -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) {
diff --git a/pkg/apis/numaflow/v1alpha1/redis_buffer_service_test.go b/pkg/apis/numaflow/v1alpha1/redis_buffer_service_test.go
index 28c5ee03..3a44b305 100644
--- a/pkg/apis/numaflow/v1alpha1/redis_buffer_service_test.go
+++ b/pkg/apis/numaflow/v1alpha1/redis_buffer_service_test.go
@@ -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) {
@@ -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) {