From 224f8df4ef23ec1fa90a73415d1112acd1071b3d Mon Sep 17 00:00:00 2001 From: Markus Walker Date: Wed, 1 Apr 2026 12:39:42 -0700 Subject: [PATCH] Revert the autoscaler code to get back the needed deployment --- actions/scaling/config.go | 10 +++ .../autoscaling/auto_scaling_main_test.go | 67 +++++++++++++++++++ .../prime/autoscaling/auto_scaling_test.go | 1 - .../prime/autoscaling/defaults/defaults.yaml | 5 ++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 actions/scaling/config.go create mode 100644 validation/prime/autoscaling/auto_scaling_main_test.go diff --git a/actions/scaling/config.go b/actions/scaling/config.go new file mode 100644 index 0000000000..bc0e8e09e4 --- /dev/null +++ b/actions/scaling/config.go @@ -0,0 +1,10 @@ +package scaling + +const ( + AutoScalingConfigurationKey = "autoScalingConfig" +) + +type AutoscalingConfig struct { + ChartRepository string `json:"chartRepository,omitempty" yaml:"chartRepository,omitempty"` + Image string `json:"image,omitempty" yaml:"image,omitempty"` +} diff --git a/validation/prime/autoscaling/auto_scaling_main_test.go b/validation/prime/autoscaling/auto_scaling_main_test.go new file mode 100644 index 0000000000..24de1adfe9 --- /dev/null +++ b/validation/prime/autoscaling/auto_scaling_main_test.go @@ -0,0 +1,67 @@ +package autoscaling + +import ( + "os" + "testing" + + "github.com/rancher/shepherd/clients/rancher" + "github.com/rancher/shepherd/pkg/config" + "github.com/rancher/shepherd/pkg/config/operations" + "github.com/rancher/shepherd/pkg/session" + "github.com/rancher/tests/actions/features" + "github.com/rancher/tests/actions/scaling" + "github.com/sirupsen/logrus" +) + +func TestMain(m *testing.M) { + testSession := session.NewSession() + client, err := rancher.NewClient("", testSession) + if err != nil { + logrus.Errorf("Failed, during client setup: %s", err) + os.Exit(1) + } + + cattleConfig := config.LoadConfigFromFile(os.Getenv(config.ConfigEnvironmentKey)) + + autoScalingConfig := new(scaling.AutoscalingConfig) + operations.LoadObjectFromMap(scaling.AutoScalingConfigurationKey, cattleConfig, autoScalingConfig) + + configureAutoscaler, err := features.IsEnabled(client, features.ClusterAutoscaling) + if err != nil { + logrus.Errorf("Failed, to get %s state", features.ClusterAutoscaling) + os.Exit(1) + } + + if !configureAutoscaler { + if autoScalingConfig.ChartRepository == "" || autoScalingConfig.Image == "" { + logrus.Errorf("Autoscaling is not configured and no autoscaling config was provided") + os.Exit(1) + } + + logrus.Infof("Setting autoscaler environment variables") + err = features.ConfigureAutoscaler(client, autoScalingConfig.ChartRepository, autoScalingConfig.Image) + if err != nil { + logrus.Errorf("Failed, to set autoscaler environment variables: %s", err) + os.Exit(1) + } + + logrus.Infof("Enabling, %s", features.ClusterAutoscaling) + err = features.UpdateFeatureFlag(client, features.ClusterAutoscaling, true) + if err != nil { + logrus.Errorf("Failed, to enable %s: %s", features.ClusterAutoscaling, err) + os.Exit(1) + } + } + + exitCode := m.Run() + + if !configureAutoscaler { + err = features.UpdateFeatureFlag(client, features.ClusterAutoscaling, false) + if err != nil { + logrus.Errorf("Failed, to disable %s: %s", features.ClusterAutoscaling, err) + os.Exit(1) + } + } + + os.Exit(exitCode) +} diff --git a/validation/prime/autoscaling/auto_scaling_test.go b/validation/prime/autoscaling/auto_scaling_test.go index d88952b2e3..60e5c5e116 100644 --- a/validation/prime/autoscaling/auto_scaling_test.go +++ b/validation/prime/autoscaling/auto_scaling_test.go @@ -359,5 +359,4 @@ func TestAutoScalingPause(t *testing.T) { logrus.Warningf("Failed to upload schema parameters %s", err) } } - } diff --git a/validation/prime/autoscaling/defaults/defaults.yaml b/validation/prime/autoscaling/defaults/defaults.yaml index 94dca1918c..f33accc8a9 100644 --- a/validation/prime/autoscaling/defaults/defaults.yaml +++ b/validation/prime/autoscaling/defaults/defaults.yaml @@ -24,6 +24,11 @@ awsMachineConfigs: vpcId: "" retries: "5" zone: "a" + +#Required for non prime environments +autoScalingConfig: + autoscalerChartRepository: "" + autoScalerImage: "" logging: level: "info" \ No newline at end of file