From 020d7400aa3627bb7a762018deba8839c19f3fbf Mon Sep 17 00:00:00 2001 From: Sky Singh Date: Sun, 18 May 2025 18:06:05 +0530 Subject: [PATCH] refactor(experiments): Remove manual setting of ConnectedInfraID in chaos experiment tests - Eliminated the logic for manually setting ConnectedInfraID from ExistingInfraID in multiple chaos experiment tests (container-kill, disk-fill, node-cpu-hog, node-io-stress, node-memory-hog, pod-autoscaler, pod-cpu-hog, pod-memory-hog, pod-network-corruption, pod-network-duplication, pod-network-latency, pod-network-loss, pod-delete). - This change simplifies the infrastructure setup process by relying on the updated logic in the SetupInfrastructure function, enhancing code clarity and maintainability. Signed-off-by: Sky Singh --- experiments/container-kill_test.go | 4 ---- experiments/disk-fill_test.go | 4 ---- experiments/node-cpu-hog_test.go | 4 ---- experiments/node-io-stress_test.go | 4 ---- experiments/node-memory-hog_test.go | 4 ---- experiments/pod-autoscaler_test.go | 4 ---- experiments/pod-cpu-hog_test.go | 4 ---- experiments/pod-delete_test.go | 4 ---- experiments/pod-memory-hog_test.go | 4 ---- experiments/pod-network-corruption_test.go | 4 ---- experiments/pod-network-duplication_test.go | 4 ---- experiments/pod-network-latency_test.go | 4 ---- experiments/pod-network-loss_test.go | 4 ---- pkg/infrastructure/infra.go | 5 +++++ 14 files changed, 5 insertions(+), 52 deletions(-) diff --git a/experiments/container-kill_test.go b/experiments/container-kill_test.go index ebe2e33..26b310f 100644 --- a/experiments/container-kill_test.go +++ b/experiments/container-kill_test.go @@ -51,10 +51,6 @@ var _ = Describe("BDD of running container-kill experiment", func() { // Setup infrastructure By("[PreChaos]: Setting up infrastructure") err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) - if experimentsDetails.ConnectedInfraID == "" && experimentsDetails.UseExistingInfra && experimentsDetails.ExistingInfraID != "" { - experimentsDetails.ConnectedInfraID = experimentsDetails.ExistingInfraID - klog.Infof("Manually set ConnectedInfraID to %s from ExistingInfraID", experimentsDetails.ConnectedInfraID) - } Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err) // Validate that infrastructure ID is properly set diff --git a/experiments/disk-fill_test.go b/experiments/disk-fill_test.go index 65a5c91..b5039ec 100644 --- a/experiments/disk-fill_test.go +++ b/experiments/disk-fill_test.go @@ -51,10 +51,6 @@ var _ = Describe("BDD of running disk-fill experiment", func() { // Setup infrastructure By("[PreChaos]: Setting up infrastructure") err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) - if experimentsDetails.ConnectedInfraID == "" && experimentsDetails.UseExistingInfra && experimentsDetails.ExistingInfraID != "" { - experimentsDetails.ConnectedInfraID = experimentsDetails.ExistingInfraID - klog.Infof("Manually set ConnectedInfraID to %s from ExistingInfraID", experimentsDetails.ConnectedInfraID) - } Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err) // Validate that infrastructure ID is properly set diff --git a/experiments/node-cpu-hog_test.go b/experiments/node-cpu-hog_test.go index 11b3931..2c2110b 100644 --- a/experiments/node-cpu-hog_test.go +++ b/experiments/node-cpu-hog_test.go @@ -52,10 +52,6 @@ var _ = Describe("BDD of running node-cpu-hog experiment", func() { // Setup infrastructure By("[PreChaos]: Setting up infrastructure") err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) - if experimentsDetails.ConnectedInfraID == "" && experimentsDetails.UseExistingInfra && experimentsDetails.ExistingInfraID != "" { - experimentsDetails.ConnectedInfraID = experimentsDetails.ExistingInfraID - klog.Infof("Manually set ConnectedInfraID to %s from ExistingInfraID", experimentsDetails.ConnectedInfraID) - } Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err) // Validate that infrastructure ID is properly set diff --git a/experiments/node-io-stress_test.go b/experiments/node-io-stress_test.go index e197e06..fff708b 100644 --- a/experiments/node-io-stress_test.go +++ b/experiments/node-io-stress_test.go @@ -52,10 +52,6 @@ var _ = Describe("BDD of running node-io-stress experiment", func() { // Setup infrastructure By("[PreChaos]: Setting up infrastructure") err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) - if experimentsDetails.ConnectedInfraID == "" && experimentsDetails.UseExistingInfra && experimentsDetails.ExistingInfraID != "" { - experimentsDetails.ConnectedInfraID = experimentsDetails.ExistingInfraID - klog.Infof("Manually set ConnectedInfraID to %s from ExistingInfraID", experimentsDetails.ConnectedInfraID) - } Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err) // Validate that infrastructure ID is properly set diff --git a/experiments/node-memory-hog_test.go b/experiments/node-memory-hog_test.go index faace44..29858df 100644 --- a/experiments/node-memory-hog_test.go +++ b/experiments/node-memory-hog_test.go @@ -52,10 +52,6 @@ var _ = Describe("BDD of running node-memory-hog experiment", func() { // Setup infrastructure By("[PreChaos]: Setting up infrastructure") err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) - if experimentsDetails.ConnectedInfraID == "" && experimentsDetails.UseExistingInfra && experimentsDetails.ExistingInfraID != "" { - experimentsDetails.ConnectedInfraID = experimentsDetails.ExistingInfraID - klog.Infof("Manually set ConnectedInfraID to %s from ExistingInfraID", experimentsDetails.ConnectedInfraID) - } Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err) // Validate that infrastructure ID is properly set diff --git a/experiments/pod-autoscaler_test.go b/experiments/pod-autoscaler_test.go index dd34f5a..ea71505 100644 --- a/experiments/pod-autoscaler_test.go +++ b/experiments/pod-autoscaler_test.go @@ -51,10 +51,6 @@ var _ = Describe("BDD of running pod-autoscaler experiment", func() { // Setup infrastructure By("[PreChaos]: Setting up infrastructure") err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) - if experimentsDetails.ConnectedInfraID == "" && experimentsDetails.UseExistingInfra && experimentsDetails.ExistingInfraID != "" { - experimentsDetails.ConnectedInfraID = experimentsDetails.ExistingInfraID - klog.Infof("Manually set ConnectedInfraID to %s from ExistingInfraID", experimentsDetails.ConnectedInfraID) - } Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err) // Validate that infrastructure ID is properly set diff --git a/experiments/pod-cpu-hog_test.go b/experiments/pod-cpu-hog_test.go index 29bc9f1..8cd0cc5 100644 --- a/experiments/pod-cpu-hog_test.go +++ b/experiments/pod-cpu-hog_test.go @@ -51,10 +51,6 @@ var _ = Describe("BDD of running pod-cpu-hog experiment", func() { // Setup infrastructure By("[PreChaos]: Setting up infrastructure") err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) - if experimentsDetails.ConnectedInfraID == "" && experimentsDetails.UseExistingInfra && experimentsDetails.ExistingInfraID != "" { - experimentsDetails.ConnectedInfraID = experimentsDetails.ExistingInfraID - klog.Infof("Manually set ConnectedInfraID to %s from ExistingInfraID", experimentsDetails.ConnectedInfraID) - } Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err) // Validate that infrastructure ID is properly set diff --git a/experiments/pod-delete_test.go b/experiments/pod-delete_test.go index fbe516d..ec79ef7 100644 --- a/experiments/pod-delete_test.go +++ b/experiments/pod-delete_test.go @@ -51,10 +51,6 @@ var _ = Describe("BDD of running pod-delete experiment", func() { // Setup infrastructure By("[PreChaos]: Setting up infrastructure") err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) - if experimentsDetails.ConnectedInfraID == "" && experimentsDetails.UseExistingInfra && experimentsDetails.ExistingInfraID != "" { - experimentsDetails.ConnectedInfraID = experimentsDetails.ExistingInfraID - klog.Infof("Manually set ConnectedInfraID to %s from ExistingInfraID", experimentsDetails.ConnectedInfraID) - } Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err) // Validate that infrastructure ID is properly set diff --git a/experiments/pod-memory-hog_test.go b/experiments/pod-memory-hog_test.go index 226a288..a459bcc 100644 --- a/experiments/pod-memory-hog_test.go +++ b/experiments/pod-memory-hog_test.go @@ -51,10 +51,6 @@ var _ = Describe("BDD of running pod-memory-hog experiment", func() { // Setup infrastructure By("[PreChaos]: Setting up infrastructure") err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) - if experimentsDetails.ConnectedInfraID == "" && experimentsDetails.UseExistingInfra && experimentsDetails.ExistingInfraID != "" { - experimentsDetails.ConnectedInfraID = experimentsDetails.ExistingInfraID - klog.Infof("Manually set ConnectedInfraID to %s from ExistingInfraID", experimentsDetails.ConnectedInfraID) - } Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err) // Validate that infrastructure ID is properly set diff --git a/experiments/pod-network-corruption_test.go b/experiments/pod-network-corruption_test.go index c0e189f..0be64b4 100644 --- a/experiments/pod-network-corruption_test.go +++ b/experiments/pod-network-corruption_test.go @@ -51,10 +51,6 @@ var _ = Describe("BDD of running pod-network-corruption experiment", func() { // Setup infrastructure By("[PreChaos]: Setting up infrastructure") err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) - if experimentsDetails.ConnectedInfraID == "" && experimentsDetails.UseExistingInfra && experimentsDetails.ExistingInfraID != "" { - experimentsDetails.ConnectedInfraID = experimentsDetails.ExistingInfraID - klog.Infof("Manually set ConnectedInfraID to %s from ExistingInfraID", experimentsDetails.ConnectedInfraID) - } Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err) // Validate that infrastructure ID is properly set diff --git a/experiments/pod-network-duplication_test.go b/experiments/pod-network-duplication_test.go index cf2cd58..15950db 100644 --- a/experiments/pod-network-duplication_test.go +++ b/experiments/pod-network-duplication_test.go @@ -51,10 +51,6 @@ var _ = Describe("BDD of running pod-network-duplication experiment", func() { // Setup infrastructure By("[PreChaos]: Setting up infrastructure") err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) - if experimentsDetails.ConnectedInfraID == "" && experimentsDetails.UseExistingInfra && experimentsDetails.ExistingInfraID != "" { - experimentsDetails.ConnectedInfraID = experimentsDetails.ExistingInfraID - klog.Infof("Manually set ConnectedInfraID to %s from ExistingInfraID", experimentsDetails.ConnectedInfraID) - } Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err) // Validate that infrastructure ID is properly set diff --git a/experiments/pod-network-latency_test.go b/experiments/pod-network-latency_test.go index ab287e8..9cc3caf 100644 --- a/experiments/pod-network-latency_test.go +++ b/experiments/pod-network-latency_test.go @@ -51,10 +51,6 @@ var _ = Describe("BDD of running pod-network-latency experiment", func() { // Setup infrastructure By("[PreChaos]: Setting up infrastructure") err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) - if experimentsDetails.ConnectedInfraID == "" && experimentsDetails.UseExistingInfra && experimentsDetails.ExistingInfraID != "" { - experimentsDetails.ConnectedInfraID = experimentsDetails.ExistingInfraID - klog.Infof("Manually set ConnectedInfraID to %s from ExistingInfraID", experimentsDetails.ConnectedInfraID) - } Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err) // Validate that infrastructure ID is properly set diff --git a/experiments/pod-network-loss_test.go b/experiments/pod-network-loss_test.go index 6fa9eb3..888edd0 100644 --- a/experiments/pod-network-loss_test.go +++ b/experiments/pod-network-loss_test.go @@ -51,10 +51,6 @@ var _ = Describe("BDD of running pod-network-loss experiment", func() { // Setup infrastructure By("[PreChaos]: Setting up infrastructure") err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) - if experimentsDetails.ConnectedInfraID == "" && experimentsDetails.UseExistingInfra && experimentsDetails.ExistingInfraID != "" { - experimentsDetails.ConnectedInfraID = experimentsDetails.ExistingInfraID - klog.Infof("Manually set ConnectedInfraID to %s from ExistingInfraID", experimentsDetails.ConnectedInfraID) - } Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err) // Validate that infrastructure ID is properly set diff --git a/pkg/infrastructure/infra.go b/pkg/infrastructure/infra.go index b0bda91..38da89c 100644 --- a/pkg/infrastructure/infra.go +++ b/pkg/infrastructure/infra.go @@ -20,6 +20,11 @@ func SetupInfrastructure(experimentsDetails *types.ExperimentDetails, sdkClient installInfra, _ := strconv.ParseBool(os.Getenv("INSTALL_INFRA")) if !installInfra { klog.Info("INSTALL_INFRA is set to false, skipping infrastructure setup") + // Handle case where we're using existing infrastructure but not installing + if experimentsDetails.ConnectedInfraID == "" && experimentsDetails.UseExistingInfra && experimentsDetails.ExistingInfraID != "" { + experimentsDetails.ConnectedInfraID = experimentsDetails.ExistingInfraID + klog.Infof("Manually set ConnectedInfraID to %s from ExistingInfraID", experimentsDetails.ConnectedInfraID) + } return nil }