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 <akashsingh2210670@gmail.com>
This commit is contained in:
Sky Singh 2025-05-18 18:06:05 +05:30
parent 8741dd40e0
commit 020d7400aa
No known key found for this signature in database
GPG Key ID: 0FE88BD41A5B05BF
14 changed files with 5 additions and 52 deletions

View File

@ -51,10 +51,6 @@ var _ = Describe("BDD of running container-kill experiment", func() {
// Setup infrastructure // Setup infrastructure
By("[PreChaos]: Setting up infrastructure") By("[PreChaos]: Setting up infrastructure")
err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) 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) Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err)
// Validate that infrastructure ID is properly set // Validate that infrastructure ID is properly set

View File

@ -51,10 +51,6 @@ var _ = Describe("BDD of running disk-fill experiment", func() {
// Setup infrastructure // Setup infrastructure
By("[PreChaos]: Setting up infrastructure") By("[PreChaos]: Setting up infrastructure")
err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) 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) Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err)
// Validate that infrastructure ID is properly set // Validate that infrastructure ID is properly set

View File

@ -52,10 +52,6 @@ var _ = Describe("BDD of running node-cpu-hog experiment", func() {
// Setup infrastructure // Setup infrastructure
By("[PreChaos]: Setting up infrastructure") By("[PreChaos]: Setting up infrastructure")
err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) 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) Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err)
// Validate that infrastructure ID is properly set // Validate that infrastructure ID is properly set

View File

@ -52,10 +52,6 @@ var _ = Describe("BDD of running node-io-stress experiment", func() {
// Setup infrastructure // Setup infrastructure
By("[PreChaos]: Setting up infrastructure") By("[PreChaos]: Setting up infrastructure")
err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) 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) Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err)
// Validate that infrastructure ID is properly set // Validate that infrastructure ID is properly set

View File

@ -52,10 +52,6 @@ var _ = Describe("BDD of running node-memory-hog experiment", func() {
// Setup infrastructure // Setup infrastructure
By("[PreChaos]: Setting up infrastructure") By("[PreChaos]: Setting up infrastructure")
err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) 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) Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err)
// Validate that infrastructure ID is properly set // Validate that infrastructure ID is properly set

View File

@ -51,10 +51,6 @@ var _ = Describe("BDD of running pod-autoscaler experiment", func() {
// Setup infrastructure // Setup infrastructure
By("[PreChaos]: Setting up infrastructure") By("[PreChaos]: Setting up infrastructure")
err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) 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) Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err)
// Validate that infrastructure ID is properly set // Validate that infrastructure ID is properly set

View File

@ -51,10 +51,6 @@ var _ = Describe("BDD of running pod-cpu-hog experiment", func() {
// Setup infrastructure // Setup infrastructure
By("[PreChaos]: Setting up infrastructure") By("[PreChaos]: Setting up infrastructure")
err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) 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) Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err)
// Validate that infrastructure ID is properly set // Validate that infrastructure ID is properly set

View File

@ -51,10 +51,6 @@ var _ = Describe("BDD of running pod-delete experiment", func() {
// Setup infrastructure // Setup infrastructure
By("[PreChaos]: Setting up infrastructure") By("[PreChaos]: Setting up infrastructure")
err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) 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) Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err)
// Validate that infrastructure ID is properly set // Validate that infrastructure ID is properly set

View File

@ -51,10 +51,6 @@ var _ = Describe("BDD of running pod-memory-hog experiment", func() {
// Setup infrastructure // Setup infrastructure
By("[PreChaos]: Setting up infrastructure") By("[PreChaos]: Setting up infrastructure")
err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) 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) Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err)
// Validate that infrastructure ID is properly set // Validate that infrastructure ID is properly set

View File

@ -51,10 +51,6 @@ var _ = Describe("BDD of running pod-network-corruption experiment", func() {
// Setup infrastructure // Setup infrastructure
By("[PreChaos]: Setting up infrastructure") By("[PreChaos]: Setting up infrastructure")
err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) 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) Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err)
// Validate that infrastructure ID is properly set // Validate that infrastructure ID is properly set

View File

@ -51,10 +51,6 @@ var _ = Describe("BDD of running pod-network-duplication experiment", func() {
// Setup infrastructure // Setup infrastructure
By("[PreChaos]: Setting up infrastructure") By("[PreChaos]: Setting up infrastructure")
err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) 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) Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err)
// Validate that infrastructure ID is properly set // Validate that infrastructure ID is properly set

View File

@ -51,10 +51,6 @@ var _ = Describe("BDD of running pod-network-latency experiment", func() {
// Setup infrastructure // Setup infrastructure
By("[PreChaos]: Setting up infrastructure") By("[PreChaos]: Setting up infrastructure")
err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) 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) Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err)
// Validate that infrastructure ID is properly set // Validate that infrastructure ID is properly set

View File

@ -51,10 +51,6 @@ var _ = Describe("BDD of running pod-network-loss experiment", func() {
// Setup infrastructure // Setup infrastructure
By("[PreChaos]: Setting up infrastructure") By("[PreChaos]: Setting up infrastructure")
err = infrastructure.SetupInfrastructure(&experimentsDetails, sdkClient) 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) Expect(err).To(BeNil(), "Failed to setup infrastructure, due to {%v}", err)
// Validate that infrastructure ID is properly set // Validate that infrastructure ID is properly set

View File

@ -20,6 +20,11 @@ func SetupInfrastructure(experimentsDetails *types.ExperimentDetails, sdkClient
installInfra, _ := strconv.ParseBool(os.Getenv("INSTALL_INFRA")) installInfra, _ := strconv.ParseBool(os.Getenv("INSTALL_INFRA"))
if !installInfra { if !installInfra {
klog.Info("INSTALL_INFRA is set to false, skipping infrastructure setup") 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 return nil
} }