From 49a35f770bf48b07406b19c7eaae56ecb55dabd2 Mon Sep 17 00:00:00 2001 From: Peter Braun Date: Thu, 23 Feb 2023 18:30:20 +0100 Subject: [PATCH] feat: return all sizes regardless of capacity for enterprise --- .../kafka/internal/handlers/cluster_test.go | 12 ++++++ internal/kafka/internal/presenters/cluster.go | 15 ++------ .../kafka/internal/presenters/cluster_test.go | 37 +++++++++++++++++-- .../cluster_get_enterprise_test.go | 4 +- 4 files changed, 51 insertions(+), 17 deletions(-) diff --git a/internal/kafka/internal/handlers/cluster_test.go b/internal/kafka/internal/handlers/cluster_test.go index bd0995e0a..8e07f11c3 100644 --- a/internal/kafka/internal/handlers/cluster_test.go +++ b/internal/kafka/internal/handlers/cluster_test.go @@ -1134,6 +1134,18 @@ func Test_GetEnterpriseCluster(t *testing.T) { Id: "x1", CapacityConsumed: 1, }, + { + Id: "x2", + CapacityConsumed: 2, + }, + { + Id: "x3", + CapacityConsumed: 3, + }, + { + Id: "x4", + CapacityConsumed: 4, + }, }, SupportedBillingModels: []public.SupportedKafkaBillingModel{ { diff --git a/internal/kafka/internal/presenters/cluster.go b/internal/kafka/internal/presenters/cluster.go index e4f144e6d..7749c7478 100644 --- a/internal/kafka/internal/presenters/cluster.go +++ b/internal/kafka/internal/presenters/cluster.go @@ -11,7 +11,6 @@ import ( "github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/pkg/api" "github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/pkg/errors" "github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/pkg/logger" - "github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/pkg/shared/utils/arrays" ) func PresentEnterpriseClusterListItem(cluster api.Cluster) public.EnterpriseClusterListItem { @@ -75,7 +74,7 @@ func PresentEnterpriseCluster(cluster api.Cluster, consumedStreamingUnitsInTheCl storedCapacityInfo, ok := cluster.RetrieveDynamicCapacityInfo()[types.STANDARD.String()] if ok { presentedCluster.CapacityInformation = presentEnterpriseClusterCapacityInfo(consumedStreamingUnitsInTheCluster, storedCapacityInfo) - supportedInstanceTypes, err := presentEnterpriseClusterSupportedInstanceTypes(presentedCluster.CapacityInformation.RemainingKafkaStreamingUnits, kafkaConfig) + supportedInstanceTypes, err := presentEnterpriseClusterSupportedInstanceTypes(kafkaConfig) if err != nil { return public.EnterpriseCluster{}, err } @@ -99,7 +98,7 @@ func presentEnterpriseClusterCapacityInfo(consumedStreamingUnitsInTheCluster int } } -func presentEnterpriseClusterSupportedInstanceTypes(remainingCapacity int32, kafkaConfig *config.KafkaConfig) (public.SupportedKafkaInstanceTypesList, error) { +func presentEnterpriseClusterSupportedInstanceTypes(kafkaConfig *config.KafkaConfig) (public.SupportedKafkaInstanceTypesList, error) { // enterprise clusters only supports standard instance type for now. It is safe to hardcode this. standardInstanceType, err := kafkaConfig.SupportedInstanceTypes.Configuration.GetKafkaInstanceTypeByID(types.STANDARD.String()) if err != nil { // this should never happen, lets log an error in case it happens. @@ -118,15 +117,7 @@ func presentEnterpriseClusterSupportedInstanceTypes(remainingCapacity int32, kaf }, err } - availableSizes := arrays.Filter(standardInstanceType.Sizes, func(size config.KafkaInstanceSize) bool { - return int32(size.CapacityConsumed) <= remainingCapacity - }) - - presentedSizes := []public.SupportedKafkaSize{} - - if len(availableSizes) > 0 { - presentedSizes = GetSupportedSizes(&config.KafkaInstanceType{Sizes: availableSizes}) - } + presentedSizes := GetSupportedSizes(&config.KafkaInstanceType{Sizes: standardInstanceType.Sizes}) return public.SupportedKafkaInstanceTypesList{ InstanceTypes: []public.SupportedKafkaInstanceType{ diff --git a/internal/kafka/internal/presenters/cluster_test.go b/internal/kafka/internal/presenters/cluster_test.go index 2dc60b29b..535123697 100644 --- a/internal/kafka/internal/presenters/cluster_test.go +++ b/internal/kafka/internal/presenters/cluster_test.go @@ -218,7 +218,7 @@ func Test_PresentEnterpriseCluster(t *testing.T) { CloudProvider: "azure", Region: "af-east", MultiAZ: true, - DynamicCapacityInfo: api.JSON([]byte(`{"standard":{"max_nodes":15,"max_units":5,"remaining_units":3}}`)), + DynamicCapacityInfo: api.JSON(`{"standard":{"max_nodes":15,"max_units":5,"remaining_units":3}}`), }, kafkaConfig: validKafkaConfig, }, @@ -254,6 +254,14 @@ func Test_PresentEnterpriseCluster(t *testing.T) { Id: "x3", CapacityConsumed: 3, }, + { + Id: "x4", + CapacityConsumed: 4, + }, + { + Id: "x5", + CapacityConsumed: 5, + }, }, SupportedBillingModels: []public.SupportedKafkaBillingModel{ { @@ -267,7 +275,7 @@ func Test_PresentEnterpriseCluster(t *testing.T) { }, }, { - name: "should successfully convert api.Cluster to EnterpriseCluster with capacity information and supported types that has an empty list of sizes when there is not capacity left", + name: "should successfully convert api.Cluster to EnterpriseCluster with capacity information and a full list of supported sizes", args: args{ cluster: api.Cluster{ ClusterID: clusterId, @@ -298,8 +306,29 @@ func Test_PresentEnterpriseCluster(t *testing.T) { SupportedInstanceTypes: public.SupportedKafkaInstanceTypesList{ InstanceTypes: []public.SupportedKafkaInstanceType{ { - Id: types.STANDARD.String(), - Sizes: []public.SupportedKafkaSize{}, + Id: types.STANDARD.String(), + Sizes: []public.SupportedKafkaSize{ + { + Id: "x1", + CapacityConsumed: 1, + }, + { + Id: "x2", + CapacityConsumed: 2, + }, + { + Id: "x3", + CapacityConsumed: 3, + }, + { + Id: "x4", + CapacityConsumed: 4, + }, + { + Id: "x5", + CapacityConsumed: 5, + }, + }, SupportedBillingModels: []public.SupportedKafkaBillingModel{ { Id: constants.BillingModelEnterprise.String(), diff --git a/internal/kafka/test/integration/cluster_get_enterprise_test.go b/internal/kafka/test/integration/cluster_get_enterprise_test.go index 77a557242..4e6827b3a 100644 --- a/internal/kafka/test/integration/cluster_get_enterprise_test.go +++ b/internal/kafka/test/integration/cluster_get_enterprise_test.go @@ -250,8 +250,10 @@ func TestEnterpriseClusterGet(t *testing.T) { g.Expect(standardInstanceType.Id).To(gomega.Equal(types.STANDARD.String())) g.Expect(standardInstanceType.SupportedBillingModels).To(gomega.HaveLen(1)) g.Expect(standardInstanceType.SupportedBillingModels[0].Id).To(gomega.Equal(constants.BillingModelEnterprise.String())) - g.Expect(standardInstanceType.Sizes).To(gomega.HaveLen(1)) + g.Expect(standardInstanceType.Sizes).To(gomega.HaveLen(2)) g.Expect(standardInstanceType.Sizes[0].Id).To(gomega.Equal("x1")) + g.Expect(standardInstanceType.Sizes[1].Id).To(gomega.Equal("x2")) + // get cluster addons parameters clusterWithAddonParameters, resp11, err := client.EnterpriseDataplaneClustersApi.GetEnterpriseClusterWithAddonParameters(adminCtx, entCluster.ClusterID) g.Expect(err).ToNot(gomega.HaveOccurred())