@@ -23,6 +23,7 @@ import (
2323 "emperror.dev/errors"
2424 "github.com/go-logr/logr"
2525 "github.com/prometheus/common/model"
26+ "golang.org/x/exp/slices"
2627 corev1 "k8s.io/api/core/v1"
2728 "k8s.io/apimachinery/pkg/api/resource"
2829 "k8s.io/apimachinery/pkg/types"
@@ -262,20 +263,25 @@ func resizePvc(log logr.Logger, labels model.LabelSet, annotiations model.LabelS
262263
263264 storageConfigs := brokerConfig .StorageConfigs
264265
265- for n , c := range storageConfigs {
266+ for _ , c := range storageConfigs {
266267 modifiableConfig := c .DeepCopy ()
267268 if modifiableConfig .MountPath == pvc .Annotations ["mountPath" ] {
268269 size := * modifiableConfig .PvcSpec .Resources .Requests .Storage ()
269270 size .Add (incrementBy )
270271
271272 modifiableConfig .PvcSpec .Resources .Requests ["storage" ] = size
272273
274+ // When the storage is in a brokerConfigGroup we don't resize the storage there because in that case
275+ // all of the brokers that are using this brokerConfigGroup would have their storages resized.
276+ // We add the storage into the broker.BrokerConfig.StorageConfigs in this way only the PVC belonging to that specific broker will be resized.
273277 if broker .BrokerConfig == nil {
274- broker .BrokerConfig = & v1beta1.BrokerConfig {
275- StorageConfigs : []v1beta1.StorageConfig {* modifiableConfig },
276- }
278+ broker .BrokerConfig = & v1beta1.BrokerConfig {}
279+ }
280+ idx := slices .IndexFunc (broker .BrokerConfig .StorageConfigs , func (c v1beta1.StorageConfig ) bool { return c .MountPath == pvc .Annotations ["mountPath" ] })
281+ if idx == - 1 {
282+ broker .BrokerConfig .StorageConfigs = append (broker .BrokerConfig .StorageConfigs , * modifiableConfig )
277283 } else {
278- broker .BrokerConfig .StorageConfigs [n ] = * modifiableConfig
284+ broker .BrokerConfig .StorageConfigs [idx ] = * modifiableConfig
279285 }
280286 }
281287 }
0 commit comments