From e45299364ef6cf02d86789c351392c041285611b Mon Sep 17 00:00:00 2001 From: erikzaadi Date: Tue, 10 Dec 2024 14:58:35 +0200 Subject: [PATCH] Enable multiple installations by not failing if all existing default resources exists --- pkg/defaults/defaults.go | 6 ------ pkg/defaults/defaults_test.go | 8 ++++---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/pkg/defaults/defaults.go b/pkg/defaults/defaults.go index 87ceffb..4927708 100644 --- a/pkg/defaults/defaults.go +++ b/pkg/defaults/defaults.go @@ -174,7 +174,6 @@ func validateResourcesDoesNotExist(portClient *cli.PortClient, defaults *Default func createResources(portClient *cli.PortClient, defaults *Defaults, config *port.Config) *AbortDefaultCreationError { if err := validateResourcesDoesNotExist(portClient, defaults, config); err != nil { klog.Warningf("Failed to create resources: %v.", err.Errors) - return err } bareBlueprints, patchStages := deconstructBlueprintsToCreationSteps(defaults.Blueprints) @@ -206,7 +205,6 @@ func createResources(portClient *cli.PortClient, defaults *Defaults, config *por waitGroup.Wait() if err := validateResourcesErrors(createdBlueprints, createdPages, resourceErrors); err != nil { - return err } for _, patchStage := range patchStages { @@ -224,7 +222,6 @@ func createResources(portClient *cli.PortClient, defaults *Defaults, config *por } if err := validateResourcesErrors(createdBlueprints, createdPages, resourceErrors); err != nil { - return err } for _, blueprintScorecards := range defaults.Scorecards { @@ -242,7 +239,6 @@ func createResources(portClient *cli.PortClient, defaults *Defaults, config *por waitGroup.Wait() if err := validateResourcesErrors(createdBlueprints, createdPages, resourceErrors); err != nil { - return err } for _, pageToCreate := range defaults.Pages { @@ -261,12 +257,10 @@ func createResources(portClient *cli.PortClient, defaults *Defaults, config *por waitGroup.Wait() if err := validateResourcesErrors(createdBlueprints, createdPages, resourceErrors); err != nil { - return err } if err := integration.CreateIntegration(portClient, config.StateKey, config.EventListenerType, defaults.AppConfig); err != nil { klog.Warningf("Failed to create integration with default configuration. state key %s: %v", config.StateKey, err.Error()) - return &AbortDefaultCreationError{BlueprintsToRollback: createdBlueprints, PagesToRollback: createdPages, Errors: []error{err}} } return nil diff --git a/pkg/defaults/defaults_test.go b/pkg/defaults/defaults_test.go index 6b0262c..234ba93 100644 --- a/pkg/defaults/defaults_test.go +++ b/pkg/defaults/defaults_test.go @@ -131,13 +131,13 @@ func Test_InitIntegration_BlueprintExists(t *testing.T) { assert.Nil(t, e) i, err := integration.GetIntegration(f.portClient, f.stateKey) - assert.Nil(t, i.Config.Resources) + assert.NotNil(t, i.Config.Resources) assert.Nil(t, err) _, err = blueprint.GetBlueprint(f.portClient, "workload") assert.Nil(t, err) - testUtils.CheckResourcesExistence(false, false, f.portClient, f.t, []string{"namespace", "cluster"}, []string{"workload_overview_dashboard", "availability_scorecard_dashboard"}, []string{}) + testUtils.CheckResourcesExistence(true, false, f.portClient, f.t, []string{"namespace", "cluster"}, []string{"workload_overview_dashboard", "availability_scorecard_dashboard"}, []string{}) } func Test_InitIntegration_PageExists(t *testing.T) { @@ -157,13 +157,13 @@ func Test_InitIntegration_PageExists(t *testing.T) { assert.Nil(t, e) i, err := integration.GetIntegration(f.portClient, f.stateKey) - assert.Nil(t, i.Config.Resources) + assert.NotNil(t, i.Config.Resources) assert.Nil(t, err) _, err = page.GetPage(f.portClient, "workload_overview_dashboard") assert.Nil(t, err) - testUtils.CheckResourcesExistence(false, false, f.portClient, f.t, []string{"workload", "namespace", "cluster"}, []string{"availability_scorecard_dashboard"}, []string{}) + testUtils.CheckResourcesExistence(true, false, f.portClient, f.t, []string{"workload", "namespace", "cluster"}, []string{"availability_scorecard_dashboard"}, []string{}) } func Test_InitIntegration_ExistingIntegration(t *testing.T) {