From ec65a5cfe6996db10f9c87eb7cdcb01e0ecc966b Mon Sep 17 00:00:00 2001 From: Richard87 Date: Mon, 17 Jun 2024 12:58:03 +0200 Subject: [PATCH 1/3] Cleanup required properties --- .../models/component_deployment.go | 22 ++++++------------- api/models/horizontal_scaling_summary.go | 22 ++++--------------- swaggerui/html/swagger.json | 5 +++++ swaggerui/swagger.go | 1 + 4 files changed, 17 insertions(+), 33 deletions(-) diff --git a/api/deployments/models/component_deployment.go b/api/deployments/models/component_deployment.go index 14e48b5b..d2207133 100644 --- a/api/deployments/models/component_deployment.go +++ b/api/deployments/models/component_deployment.go @@ -410,66 +410,58 @@ type ReplicaStatus struct { type HorizontalScalingSummary struct { // Component minimum replicas. From radixconfig.yaml // - // required: false // example: 2 - MinReplicas int32 `json:"minReplicas"` + MinReplicas *int32 `json:"minReplicas,omitempty"` // Component maximum replicas. From radixconfig.yaml // - // required: false // example: 5 - MaxReplicas int32 `json:"maxReplicas"` + MaxReplicas *int32 `json:"maxReplicas,omitempty"` // CooldownPeriod in seconds. From radixconfig.yaml // - // required: false // example: 300 - CooldownPeriod int32 `json:"cooldownPeriod"` + CooldownPeriod *int32 `json:"cooldownPeriod,omitempty"` // PollingInterval in seconds. From radixconfig.yaml // - // required: false // example: 30 - PollingInterval int32 `json:"pollingInterval"` + PollingInterval *int32 `json:"pollingInterval,omitempty"` // Triggers lists status of all triggers found in radixconfig.yaml // - // required: false // example: 30 + // required: true Triggers []HorizontalScalingSummaryTriggerStatus `json:"triggers"` // Deprecated: Component current average CPU utilization over all pods, represented as a percentage of requested CPU. Use Triggers instead. Will be removed from Radix API 2025-01-01. // - // required: false // example: 70 CurrentCPUUtilizationPercentage *int32 `json:"currentCPUUtilizationPercentage"` // Deprecated: Component target average CPU utilization over all pods. Use Triggers instead. Will be removed from Radix API 2025-01-01. // - // required: false // example: 80 TargetCPUUtilizationPercentage *int32 `json:"targetCPUUtilizationPercentage"` // Deprecated: Component current average memory utilization over all pods, represented as a percentage of requested memory. Use Triggers instead. Will be removed from Radix API 2025-01-01. // - // required: false // example: 80 CurrentMemoryUtilizationPercentage *int32 `json:"currentMemoryUtilizationPercentage"` // Deprecated: Component target average memory utilization over all pods. use Triggers instead. Will be removed from Radix API 2025-01-01. // - // required: false // example: 80 TargetMemoryUtilizationPercentage *int32 `json:"targetMemoryUtilizationPercentage"` // CurrentReplicas returns the current number of replicas - // required: false // example: 1 + // required: true CurrentReplicas int32 `json:"currentReplicas"` // DesiredReplicas returns the target number of replicas across all triggers - // required: false // example: 2 + // required: true DesiredReplicas int32 `json:"desiredReplicas"` } diff --git a/api/models/horizontal_scaling_summary.go b/api/models/horizontal_scaling_summary.go index d80980f0..1cceaa1f 100644 --- a/api/models/horizontal_scaling_summary.go +++ b/api/models/horizontal_scaling_summary.go @@ -28,20 +28,6 @@ func GetHpaSummary(appName, componentName string, hpaList []autoscalingv2.Horizo return nil } - var minReplicas, maxReplicas, cooldownPeriod, pollingInterval int32 - if scaler.Spec.MinReplicaCount != nil { - minReplicas = *scaler.Spec.MinReplicaCount - } - if scaler.Spec.MaxReplicaCount != nil { - maxReplicas = *scaler.Spec.MaxReplicaCount - } - if scaler.Spec.CooldownPeriod != nil { - cooldownPeriod = *scaler.Spec.CooldownPeriod - } - if scaler.Spec.PollingInterval != nil { - pollingInterval = *scaler.Spec.PollingInterval - } - currentCpuUtil, targetCpuUtil := getHpaMetrics(&hpa, corev1.ResourceCPU) currentMemoryUtil, targetMemoryUtil := getHpaMetrics(&hpa, corev1.ResourceMemory) @@ -75,10 +61,10 @@ func GetHpaSummary(appName, componentName string, hpaList []autoscalingv2.Horizo } hpaSummary := deploymentModels.HorizontalScalingSummary{ - MinReplicas: minReplicas, - MaxReplicas: maxReplicas, - CooldownPeriod: cooldownPeriod, - PollingInterval: pollingInterval, + MinReplicas: scaler.Spec.MinReplicaCount, + MaxReplicas: scaler.Spec.MaxReplicaCount, + CooldownPeriod: scaler.Spec.CooldownPeriod, + PollingInterval: scaler.Spec.PollingInterval, CurrentCPUUtilizationPercentage: currentCpuUtil, TargetCPUUtilizationPercentage: targetCpuUtil, CurrentMemoryUtilizationPercentage: currentMemoryUtil, diff --git a/swaggerui/html/swagger.json b/swaggerui/html/swagger.json index d85ab582..151fbcba 100644 --- a/swaggerui/html/swagger.json +++ b/swaggerui/html/swagger.json @@ -6300,6 +6300,11 @@ "HorizontalScalingSummary": { "description": "HorizontalScalingSummary describe the summary of horizontal scaling of a component", "type": "object", + "required": [ + "triggers", + "currentReplicas", + "desiredReplicas" + ], "properties": { "cooldownPeriod": { "description": "CooldownPeriod in seconds. From radixconfig.yaml", diff --git a/swaggerui/swagger.go b/swaggerui/swagger.go index 5c02b053..fa38b1ca 100644 --- a/swaggerui/swagger.go +++ b/swaggerui/swagger.go @@ -1,3 +1,4 @@ + package swaggerui import ( From 55bbc4c026d78c33757ea230c583d74e90e087fd Mon Sep 17 00:00:00 2001 From: Richard87 Date: Mon, 17 Jun 2024 13:01:04 +0200 Subject: [PATCH 2/3] formatting --- swaggerui/swagger.go | 1 - 1 file changed, 1 deletion(-) diff --git a/swaggerui/swagger.go b/swaggerui/swagger.go index fa38b1ca..5c02b053 100644 --- a/swaggerui/swagger.go +++ b/swaggerui/swagger.go @@ -1,4 +1,3 @@ - package swaggerui import ( From eda6f03938a68037e6f29f90edd34a6530b4e778 Mon Sep 17 00:00:00 2001 From: Richard87 Date: Mon, 17 Jun 2024 13:20:12 +0200 Subject: [PATCH 3/3] fix tests --- api/deployments/component_controller_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/deployments/component_controller_test.go b/api/deployments/component_controller_test.go index e14583e3..356d59e5 100644 --- a/api/deployments/component_controller_test.go +++ b/api/deployments/component_controller_test.go @@ -616,8 +616,8 @@ func TestGetComponents_WithHorizontalScaling(t *testing.T) { require.NoError(t, err) require.NotNil(t, components[0].HorizontalScalingSummary) - assert.Equal(t, scenario.minReplicas, components[0].HorizontalScalingSummary.MinReplicas) - assert.Equal(t, scenario.maxReplicas, components[0].HorizontalScalingSummary.MaxReplicas) + assert.Equal(t, scenario.minReplicas, *components[0].HorizontalScalingSummary.MinReplicas) + assert.Equal(t, scenario.maxReplicas, *components[0].HorizontalScalingSummary.MaxReplicas) assert.EqualValues(t, 2, components[0].HorizontalScalingSummary.CurrentReplicas) assert.EqualValues(t, 4, components[0].HorizontalScalingSummary.DesiredReplicas) assert.Nil(t, components[0].HorizontalScalingSummary.CurrentCPUUtilizationPercentage) // nolint:staticcheck // SA1019: Ignore linting deprecated fields