Skip to content

Commit

Permalink
fix: jetstream statefulset resource setting (#1989)
Browse files Browse the repository at this point in the history
- fixed incorrect resource setting on buildStatefulSetSpec

Signed-off-by: omarelbanby <obanby@gmail.com>
  • Loading branch information
obanby authored May 23, 2022
1 parent 1d2f90c commit 9ea66fb
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
17 changes: 15 additions & 2 deletions controllers/eventbus/installer/jetstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,25 @@ func (r *jetStreamInstaller) buildStatefulSetSpec(jsVersion *controllers.JetStre
if js.Metadata != nil {
spec.Template.SetAnnotations(js.Metadata.Annotations)
}

podContainers := spec.Template.Spec.Containers
containers := map[string]*corev1.Container{}
for idx := range podContainers {
containers[podContainers[idx].Name] = &podContainers[idx]
}

if js.ContainerTemplate != nil {
spec.Template.Spec.Containers[0].Resources = js.ContainerTemplate.Resources
containers["main"].Resources = js.ContainerTemplate.Resources
}

if js.MetricsContainerTemplate != nil {
spec.Template.Spec.Containers[1].Resources = js.MetricsContainerTemplate.Resources
containers["metrics"].Resources = js.MetricsContainerTemplate.Resources
}

if js.ReloaderContainerTemplate != nil {
containers["reloader"].Resources = js.ReloaderContainerTemplate.Resources
}

if js.Persistence != nil {
volMode := corev1.PersistentVolumeFilesystem
// Default volume size
Expand Down
58 changes: 58 additions & 0 deletions controllers/eventbus/installer/jetstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package installer

import (
"context"

"testing"

"github.com/argoproj/argo-events/common"
Expand All @@ -10,6 +11,7 @@ import (
"go.uber.org/zap/zaptest"
appv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apiresource "k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
Expand Down Expand Up @@ -183,6 +185,62 @@ func TestBuildJetStreamStatefulSetSpec(t *testing.T) {
s := i.buildStatefulSetSpec(&fakeConfig.EventBus.JetStream.Versions[0])
assert.True(t, len(s.VolumeClaimTemplates) > 0)
})

t.Run("with resource requests", func(t *testing.T) {
i.eventBus.Spec.JetStream = &v1alpha1.JetStreamBus{
ContainerTemplate: &v1alpha1.ContainerTemplate{
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: apiresource.Quantity{Format: "1"},
corev1.ResourceMemory: apiresource.Quantity{Format: "350Mi"},
},
Requests: corev1.ResourceList{
corev1.ResourceCPU: apiresource.Quantity{Format: "1"},
corev1.ResourceMemory: apiresource.Quantity{Format: "400Mi"},
},
},
},

MetricsContainerTemplate: &v1alpha1.ContainerTemplate{
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: apiresource.Quantity{Format: "1"},
corev1.ResourceMemory: apiresource.Quantity{Format: "200Mi"},
},
Requests: corev1.ResourceList{
corev1.ResourceCPU: apiresource.Quantity{Format: "1"},
corev1.ResourceMemory: apiresource.Quantity{Format: "200Mi"},
},
},
},

ReloaderContainerTemplate: &v1alpha1.ContainerTemplate{
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: apiresource.Quantity{Format: ".3"},
corev1.ResourceMemory: apiresource.Quantity{Format: "100Mi"},
},
Requests: corev1.ResourceList{
corev1.ResourceCPU: apiresource.Quantity{Format: ".5"},
corev1.ResourceMemory: apiresource.Quantity{Format: "100Mi"},
},
},
},
}

statefulSpec := i.buildStatefulSetSpec(&fakeConfig.EventBus.JetStream.Versions[0])

podContainers := statefulSpec.Template.Spec.Containers
containers := map[string]*corev1.Container{}
for idx := range podContainers {
containers[podContainers[idx].Name] = &podContainers[idx]
}

js := i.eventBus.Spec.JetStream
assert.Equal(t, js.ContainerTemplate.Resources, containers["main"].Resources)
assert.Equal(t, js.MetricsContainerTemplate.Resources, containers["metrics"].Resources)
assert.Equal(t, js.ReloaderContainerTemplate.Resources, containers["reloader"].Resources)
})
}

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

0 comments on commit 9ea66fb

Please sign in to comment.