From e45299364ef6cf02d86789c351392c041285611b Mon Sep 17 00:00:00 2001 From: erikzaadi Date: Tue, 10 Dec 2024 14:58:35 +0200 Subject: [PATCH 1/9] 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) { From 189f37309068f9da494c638862ca68f149b0e82f Mon Sep 17 00:00:00 2001 From: Arik Gortsunian Date: Thu, 9 Jan 2025 10:28:31 +0200 Subject: [PATCH 2/9] removed multiple validations due to no hard stop, validation runs at the end for all --- pkg/defaults/defaults.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/pkg/defaults/defaults.go b/pkg/defaults/defaults.go index 4927708..7990ffd 100644 --- a/pkg/defaults/defaults.go +++ b/pkg/defaults/defaults.go @@ -204,9 +204,6 @@ func createResources(portClient *cli.PortClient, defaults *Defaults, config *por } waitGroup.Wait() - if err := validateResourcesErrors(createdBlueprints, createdPages, resourceErrors); err != nil { - } - for _, patchStage := range patchStages { for _, bp := range patchStage { waitGroup.Add(1) @@ -221,9 +218,6 @@ func createResources(portClient *cli.PortClient, defaults *Defaults, config *por waitGroup.Wait() } - if err := validateResourcesErrors(createdBlueprints, createdPages, resourceErrors); err != nil { - } - for _, blueprintScorecards := range defaults.Scorecards { for _, scorecard := range blueprintScorecards.Scorecards { waitGroup.Add(1) @@ -238,9 +232,6 @@ func createResources(portClient *cli.PortClient, defaults *Defaults, config *por } waitGroup.Wait() - if err := validateResourcesErrors(createdBlueprints, createdPages, resourceErrors); err != nil { - } - for _, pageToCreate := range defaults.Pages { waitGroup.Add(1) go func(p port.Page) { @@ -256,11 +247,11 @@ func createResources(portClient *cli.PortClient, defaults *Defaults, config *por } waitGroup.Wait() - if err := validateResourcesErrors(createdBlueprints, createdPages, resourceErrors); err != nil { - } + validateResourcesErrors(createdBlueprints, createdPages, resourceErrors) 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 From 6fec1fc4577b5c6a76e946e4bbe2cc6ec5f3ce25 Mon Sep 17 00:00:00 2001 From: Arik Gortsunian Date: Tue, 14 Jan 2025 09:17:47 +0200 Subject: [PATCH 3/9] add change to logic to match the ocean logic --- pkg/defaults/defaults.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/defaults/defaults.go b/pkg/defaults/defaults.go index 7990ffd..3912e04 100644 --- a/pkg/defaults/defaults.go +++ b/pkg/defaults/defaults.go @@ -174,6 +174,7 @@ 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 nil } bareBlueprints, patchStages := deconstructBlueprintsToCreationSteps(defaults.Blueprints) @@ -204,6 +205,10 @@ 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 { for _, bp := range patchStage { waitGroup.Add(1) @@ -218,6 +223,10 @@ func createResources(portClient *cli.PortClient, defaults *Defaults, config *por waitGroup.Wait() } + if err := validateResourcesErrors(createdBlueprints, createdPages, resourceErrors); err != nil { + return err + } + for _, blueprintScorecards := range defaults.Scorecards { for _, scorecard := range blueprintScorecards.Scorecards { waitGroup.Add(1) @@ -232,6 +241,10 @@ 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 { waitGroup.Add(1) go func(p port.Page) { @@ -247,7 +260,9 @@ func createResources(portClient *cli.PortClient, defaults *Defaults, config *por } waitGroup.Wait() - validateResourcesErrors(createdBlueprints, createdPages, resourceErrors) + 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()) From d05cad43270cc21412967d07dee38a392535428c Mon Sep 17 00:00:00 2001 From: omribarouch Date: Tue, 14 Jan 2025 18:45:25 +0200 Subject: [PATCH 4/9] Change default resources behavior to match ocean's behavior --- pkg/defaults/defaults.go | 114 ++++++++++++--------------------------- pkg/defaults/init.go | 37 ++++++------- 2 files changed, 48 insertions(+), 103 deletions(-) diff --git a/pkg/defaults/defaults.go b/pkg/defaults/defaults.go index 3912e04..457d631 100644 --- a/pkg/defaults/defaults.go +++ b/pkg/defaults/defaults.go @@ -2,14 +2,12 @@ package defaults import ( "encoding/json" - "fmt" "os" "sync" "github.com/port-labs/port-k8s-exporter/pkg/port" "github.com/port-labs/port-k8s-exporter/pkg/port/blueprint" "github.com/port-labs/port-k8s-exporter/pkg/port/cli" - "github.com/port-labs/port-k8s-exporter/pkg/port/integration" "github.com/port-labs/port-k8s-exporter/pkg/port/page" "github.com/port-labs/port-k8s-exporter/pkg/port/scorecards" "gopkg.in/yaml.v3" @@ -142,71 +140,48 @@ func validateResourcesErrors(createdBlueprints []string, createdPages []string, return nil } -func validateResourcesDoesNotExist(portClient *cli.PortClient, defaults *Defaults, config *port.Config) *AbortDefaultCreationError { - var errors []error - if _, err := integration.GetIntegration(portClient, config.StateKey); err == nil { - klog.Warningf("Integration with state key %s already exists", config.StateKey) - return &AbortDefaultCreationError{Errors: []error{ - fmt.Errorf("integration with state key %s already exists", config.StateKey), - }} - } - +func createResources(portClient *cli.PortClient, defaults *Defaults) error { + existingBlueprints := []string{} for _, bp := range defaults.Blueprints { if _, err := blueprint.GetBlueprint(portClient, bp.Identifier); err == nil { - klog.Warningf("Blueprint with identifier %s already exists", bp.Identifier) - errors = append(errors, fmt.Errorf("blueprint with identifier %s already exists", bp.Identifier)) - } - } - - for _, p := range defaults.Pages { - if _, err := page.GetPage(portClient, p.Identifier); err == nil { - klog.Warningf("Page with identifier %s already exists", p.Identifier) - errors = append(errors, fmt.Errorf("page with identifier %s already exists", p.Identifier)) + existingBlueprints = append(existingBlueprints, bp.Identifier) } } - if errors != nil { - return &AbortDefaultCreationError{Errors: errors} - } - return nil -} - -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) + if len(existingBlueprints) > 0 { + klog.Infof("Found existing blueprints: %v, skipping default resources creation", existingBlueprints) return nil } bareBlueprints, patchStages := deconstructBlueprintsToCreationSteps(defaults.Blueprints) - waitGroup := sync.WaitGroup{} - var resourceErrors []error - var createdBlueprints []string - var createdPages []string mutex := sync.Mutex{} + createdBlueprints := []string{} for _, bp := range bareBlueprints { waitGroup.Add(1) go func(bp port.Blueprint) { defer waitGroup.Done() result, err := blueprint.NewBlueprint(portClient, bp) - mutex.Lock() if err != nil { klog.Warningf("Failed to create blueprint %s: %v", bp.Identifier, err.Error()) resourceErrors = append(resourceErrors, err) } else { klog.Infof("Created blueprint %s", result.Identifier) - createdBlueprints = append(createdBlueprints, result.Identifier) + createdBlueprints = append(createdBlueprints, bp.Identifier) } mutex.Unlock() }(bp) } waitGroup.Wait() - if err := validateResourcesErrors(createdBlueprints, createdPages, resourceErrors); err != nil { - return err + if len(resourceErrors) > 0 { + return &AbortDefaultCreationError{ + BlueprintsToRollback: createdBlueprints, + Errors: resourceErrors, + } } for _, patchStage := range patchStages { @@ -215,16 +190,22 @@ func createResources(portClient *cli.PortClient, defaults *Defaults, config *por go func(bp port.Blueprint) { defer waitGroup.Done() if _, err := blueprint.PatchBlueprint(portClient, bp); err != nil { + mutex.Lock() klog.Warningf("Failed to patch blueprint %s: %v", bp.Identifier, err.Error()) resourceErrors = append(resourceErrors, err) + mutex.Unlock() } }(bp) } waitGroup.Wait() - } - if err := validateResourcesErrors(createdBlueprints, createdPages, resourceErrors); err != nil { - return err + // If any patch failed, return abort error + if len(resourceErrors) > 0 { + return &AbortDefaultCreationError{ + BlueprintsToRollback: createdBlueprints, + Errors: resourceErrors, + } + } } for _, blueprintScorecards := range defaults.Scorecards { @@ -234,76 +215,47 @@ func createResources(portClient *cli.PortClient, defaults *Defaults, config *por defer waitGroup.Done() if err := scorecards.CreateScorecard(portClient, blueprintIdentifier, scorecard); err != nil { klog.Warningf("Failed to create scorecard for blueprint %s: %v", blueprintIdentifier, err.Error()) - resourceErrors = append(resourceErrors, err) } }(blueprintScorecards.Blueprint, scorecard) } } waitGroup.Wait() - if err := validateResourcesErrors(createdBlueprints, createdPages, resourceErrors); err != nil { - return err - } - for _, pageToCreate := range defaults.Pages { waitGroup.Add(1) go func(p port.Page) { defer waitGroup.Done() if err := page.CreatePage(portClient, p); err != nil { klog.Warningf("Failed to create page %s: %v", p.Identifier, err.Error()) - resourceErrors = append(resourceErrors, err) } else { klog.Infof("Created page %s", p.Identifier) - createdPages = append(createdPages, p.Identifier) } }(pageToCreate) } 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 } -func initializeDefaults(portClient *cli.PortClient, config *port.Config) error { +func initializeDefaults(portClient *cli.PortClient) error { defaults, err := getDefaults() if err != nil { return err } - if err := createResources(portClient, defaults, config); err != nil { - klog.Infof("Failed to create resources. Rolling back blueprints: %v", err.BlueprintsToRollback) - var rollbackWg sync.WaitGroup - for _, identifier := range err.BlueprintsToRollback { - rollbackWg.Add(1) - go func(identifier string) { - defer rollbackWg.Done() - if err := blueprint.DeleteBlueprint(portClient, identifier); err != nil { - klog.Warningf("Failed to rollback blueprint %s creation: %v", identifier, err) - } - }(identifier) - } - rollbackWg.Wait() - - for _, identifier := range err.PagesToRollback { - rollbackWg.Add(1) - go func(identifier string) { - defer rollbackWg.Done() - if err := page.DeletePage(portClient, identifier); err != nil { - klog.Warningf("Failed to rollback page %s creation: %v", identifier, err) + if err := createResources(portClient, defaults); err != nil { + if abortErr, ok := err.(*AbortDefaultCreationError); ok { + klog.Warningf("Rolling back blueprints due to creation error") + for _, blueprintID := range abortErr.BlueprintsToRollback { + if err := blueprint.DeleteBlueprint(portClient, blueprintID); err != nil { + klog.Warningf("Failed to rollback blueprint %s: %v", blueprintID, err) + } else { + klog.Infof("Successfully rolled back blueprint %s", blueprintID) } - }(identifier) + } } - rollbackWg.Wait() - - return &ExceptionGroup{Message: err.Error(), Errors: err.Errors} + klog.Warningf("Error creating default resources: %v", err) + return err } return nil diff --git a/pkg/defaults/init.go b/pkg/defaults/init.go index 1f5f284..0f9ca40 100644 --- a/pkg/defaults/init.go +++ b/pkg/defaults/init.go @@ -29,38 +29,31 @@ func InitIntegration(portClient *cli.PortClient, applicationConfig *port.Config) if err != nil { klog.Infof("Could not get integration with state key %s, error: %s", applicationConfig.StateKey, err.Error()) - klog.Infof("Creating integration") - // The exporter supports a deprecated case where resources are provided in config file and integration does not - // exist. If this is not the case, we support the new way of creating the integration with the default resources. - // Only one of the two cases can be true. - if defaultIntegrationConfig.Resources == nil && applicationConfig.CreateDefaultResources { - klog.Infof("Creating default resources") - if err := initializeDefaults(portClient, applicationConfig); err != nil { - klog.Warningf("Error initializing defaults: %s", err.Error()) - klog.Warningf("The integration will start without default integration mapping and other default resources. Please create them manually in Port. ") - } else { - klog.Infof("Default resources created successfully") - return nil - } + if err := integration.CreateIntegration(portClient, applicationConfig.StateKey, applicationConfig.EventListenerType, defaultIntegrationConfig); err != nil { + return err } - - klog.Infof("Could not create default resources, creating integration with no resources") - klog.Infof("Creating integration with config: %v", defaultIntegrationConfig) - // Handle a deprecated case where resources are provided in config file - return integration.CreateIntegration(portClient, applicationConfig.StateKey, applicationConfig.EventListenerType, defaultIntegrationConfig) } else { klog.Infof("Integration with state key %s already exists, patching it", applicationConfig.StateKey) integrationPatch := &port.Integration{ EventListener: getEventListenerConfig(applicationConfig.EventListenerType), } - // Handle a deprecated case where resources are provided in config file and integration exists from previous - //versions without a config if existingIntegration.Config == nil || applicationConfig.OverwriteConfigurationOnRestart { - klog.Infof("Integration exists without a config, patching it with default config: %v", defaultIntegrationConfig) integrationPatch.Config = defaultIntegrationConfig } - return integration.PatchIntegration(portClient, applicationConfig.StateKey, integrationPatch) + if err := integration.PatchIntegration(portClient, applicationConfig.StateKey, integrationPatch); err != nil { + return err + } } + + if applicationConfig.CreateDefaultResources { + klog.Infof("Creating default resources") + if err := initializeDefaults(portClient); err != nil { + klog.Warningf("Error initializing defaults: %s", err.Error()) + klog.Warningf("Some default resources may not have been created. The integration will continue running.") + } + } + + return nil } From b471d613e3398f8642c64def8c9fa7b8b8fe8acc Mon Sep 17 00:00:00 2001 From: omribarouch Date: Wed, 15 Jan 2025 10:46:26 +0200 Subject: [PATCH 5/9] fix tests --- pkg/defaults/defaults.go | 18 +----------------- pkg/defaults/defaults_test.go | 2 +- pkg/defaults/init.go | 11 ++++++++++- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/pkg/defaults/defaults.go b/pkg/defaults/defaults.go index 457d631..65b0773 100644 --- a/pkg/defaults/defaults.go +++ b/pkg/defaults/defaults.go @@ -130,16 +130,6 @@ func (e *AbortDefaultCreationError) Error() string { return "AbortDefaultCreationError" } -func validateResourcesErrors(createdBlueprints []string, createdPages []string, resourceErrors []error) *AbortDefaultCreationError { - if len(resourceErrors) > 0 { - for _, err := range resourceErrors { - klog.Infof("Failed to create resources: %v.", err.Error()) - } - return &AbortDefaultCreationError{BlueprintsToRollback: createdBlueprints, PagesToRollback: createdPages, Errors: resourceErrors} - } - return nil -} - func createResources(portClient *cli.PortClient, defaults *Defaults) error { existingBlueprints := []string{} for _, bp := range defaults.Blueprints { @@ -199,7 +189,6 @@ func createResources(portClient *cli.PortClient, defaults *Defaults) error { } waitGroup.Wait() - // If any patch failed, return abort error if len(resourceErrors) > 0 { return &AbortDefaultCreationError{ BlueprintsToRollback: createdBlueprints, @@ -237,12 +226,7 @@ func createResources(portClient *cli.PortClient, defaults *Defaults) error { return nil } -func initializeDefaults(portClient *cli.PortClient) error { - defaults, err := getDefaults() - if err != nil { - return err - } - +func initializeDefaults(portClient *cli.PortClient, defaults *Defaults) error { if err := createResources(portClient, defaults); err != nil { if abortErr, ok := err.(*AbortDefaultCreationError); ok { klog.Warningf("Rolling back blueprints due to creation error") diff --git a/pkg/defaults/defaults_test.go b/pkg/defaults/defaults_test.go index 234ba93..dc2419d 100644 --- a/pkg/defaults/defaults_test.go +++ b/pkg/defaults/defaults_test.go @@ -137,7 +137,7 @@ func Test_InitIntegration_BlueprintExists(t *testing.T) { _, err = blueprint.GetBlueprint(f.portClient, "workload") assert.Nil(t, err) - testUtils.CheckResourcesExistence(true, false, f.portClient, f.t, []string{"namespace", "cluster"}, []string{"workload_overview_dashboard", "availability_scorecard_dashboard"}, []string{}) + testUtils.CheckResourcesExistence(false, false, f.portClient, f.t, []string{"namespace", "cluster"}, []string{"workload_overview_dashboard", "availability_scorecard_dashboard"}, []string{}) } func Test_InitIntegration_PageExists(t *testing.T) { diff --git a/pkg/defaults/init.go b/pkg/defaults/init.go index 0f9ca40..f37f9db 100644 --- a/pkg/defaults/init.go +++ b/pkg/defaults/init.go @@ -18,6 +18,11 @@ func getEventListenerConfig(eventListenerType string) *port.EventListenerSetting func InitIntegration(portClient *cli.PortClient, applicationConfig *port.Config) error { klog.Infof("Initializing Port integration") + defaults, err := getDefaults() + if err != nil { + return err + } + existingIntegration, err := integration.GetIntegration(portClient, applicationConfig.StateKey) defaultIntegrationConfig := &port.IntegrationAppConfig{ Resources: applicationConfig.Resources, @@ -28,6 +33,10 @@ func InitIntegration(portClient *cli.PortClient, applicationConfig *port.Config) } if err != nil { + if applicationConfig.CreateDefaultResources { + defaultIntegrationConfig = defaults.AppConfig + } + klog.Infof("Could not get integration with state key %s, error: %s", applicationConfig.StateKey, err.Error()) if err := integration.CreateIntegration(portClient, applicationConfig.StateKey, applicationConfig.EventListenerType, defaultIntegrationConfig); err != nil { return err @@ -49,7 +58,7 @@ func InitIntegration(portClient *cli.PortClient, applicationConfig *port.Config) if applicationConfig.CreateDefaultResources { klog.Infof("Creating default resources") - if err := initializeDefaults(portClient); err != nil { + if err := initializeDefaults(portClient, defaults); err != nil { klog.Warningf("Error initializing defaults: %s", err.Error()) klog.Warningf("Some default resources may not have been created. The integration will continue running.") } From d02cbb8440ee5257ced1e32c06b04091aef3617b Mon Sep 17 00:00:00 2001 From: omribarouch Date: Wed, 15 Jan 2025 11:43:36 +0200 Subject: [PATCH 6/9] fix test --- pkg/defaults/defaults_test.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/defaults/defaults_test.go b/pkg/defaults/defaults_test.go index dc2419d..e3513b6 100644 --- a/pkg/defaults/defaults_test.go +++ b/pkg/defaults/defaults_test.go @@ -183,7 +183,7 @@ func Test_InitIntegration_ExistingIntegration(t *testing.T) { _, err = integration.GetIntegration(f.portClient, f.stateKey) assert.Nil(t, err) - testUtils.CheckResourcesExistence(false, false, f.portClient, f.t, []string{"workload", "namespace", "cluster"}, []string{"workload_overview_dashboard", "availability_scorecard_dashboard"}, []string{}) + testUtils.CheckResourcesExistence(true, false, f.portClient, f.t, []string{"workload", "namespace", "cluster"}, []string{"workload_overview_dashboard", "availability_scorecard_dashboard"}, []string{}) } func Test_InitIntegration_LocalResourcesConfiguration(t *testing.T) { @@ -225,7 +225,7 @@ func Test_InitIntegration_LocalResourcesConfiguration(t *testing.T) { assert.Equal(t, expectedResources, i.Config.Resources) assert.Nil(t, err) - testUtils.CheckResourcesExistence(false, false, f.portClient, f.t, []string{"workload", "namespace", "cluster"}, []string{"workload_overview_dashboard", "availability_scorecard_dashboard"}, []string{}) + testUtils.CheckResourcesExistence(true, false, f.portClient, f.t, []string{"workload", "namespace", "cluster"}, []string{"workload_overview_dashboard", "availability_scorecard_dashboard"}, []string{}) } func Test_InitIntegration_LocalResourcesConfiguration_ExistingIntegration_EmptyConfiguration(t *testing.T) { @@ -247,11 +247,12 @@ func Test_InitIntegration_LocalResourcesConfiguration_ExistingIntegration_EmptyC assert.Nil(t, err) assert.Equal(t, "KAFKA", i.EventListener.Type) - testUtils.CheckResourcesExistence(false, false, f.portClient, f.t, []string{"workload", "namespace", "cluster"}, []string{"workload_overview_dashboard", "availability_scorecard_dashboard"}, []string{}) + testUtils.CheckResourcesExistence(true, false, f.portClient, f.t, []string{"workload", "namespace", "cluster"}, []string{"workload_overview_dashboard", "availability_scorecard_dashboard"}, []string{}) } func Test_InitIntegration_LocalResourcesConfiguration_ExistingIntegration_WithConfiguration_WithOverwriteConfigurationOnRestartFlag(t *testing.T) { f := NewFixture(t) + defer tearDownFixture(t, f) expectedConfig := &port.IntegrationAppConfig{ Resources: []port.Resource{ @@ -294,7 +295,5 @@ func Test_InitIntegration_LocalResourcesConfiguration_ExistingIntegration_WithCo assert.Nil(t, err) assert.Equal(t, expectedConfig.Resources, i.Config.Resources) - testUtils.CheckResourcesExistence(false, false, f.portClient, f.t, []string{"workload", "namespace", "cluster"}, []string{"workload_overview_dashboard", "availability_scorecard_dashboard"}, []string{}) - defer tearDownFixture(t, f) - + testUtils.CheckResourcesExistence(true, false, f.portClient, f.t, []string{"workload", "namespace", "cluster"}, []string{"workload_overview_dashboard", "availability_scorecard_dashboard"}, []string{}) } From 2bb5432dde2f8b8cc38c53ad0d62b79cee128ccc Mon Sep 17 00:00:00 2001 From: omby8888 <160610297+omby8888@users.noreply.github.com> Date: Thu, 16 Jan 2025 16:12:39 +0200 Subject: [PATCH 7/9] Update pkg/defaults/init.go Co-authored-by: Matan <51418643+matan84@users.noreply.github.com> --- pkg/defaults/init.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/defaults/init.go b/pkg/defaults/init.go index f37f9db..c53c080 100644 --- a/pkg/defaults/init.go +++ b/pkg/defaults/init.go @@ -37,7 +37,7 @@ func InitIntegration(portClient *cli.PortClient, applicationConfig *port.Config) defaultIntegrationConfig = defaults.AppConfig } - klog.Infof("Could not get integration with state key %s, error: %s", applicationConfig.StateKey, err.Error()) + klog.warningf("Could not get integration with state key %s, error: %s", applicationConfig.StateKey, err.Error()) if err := integration.CreateIntegration(portClient, applicationConfig.StateKey, applicationConfig.EventListenerType, defaultIntegrationConfig); err != nil { return err } From 9ce88980ee463e765a3add06f31ba88377cd42e0 Mon Sep 17 00:00:00 2001 From: omby8888 <160610297+omby8888@users.noreply.github.com> Date: Thu, 16 Jan 2025 16:13:00 +0200 Subject: [PATCH 8/9] Update pkg/defaults/init.go Co-authored-by: Matan <51418643+matan84@users.noreply.github.com> --- pkg/defaults/init.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/defaults/init.go b/pkg/defaults/init.go index c53c080..a805346 100644 --- a/pkg/defaults/init.go +++ b/pkg/defaults/init.go @@ -57,7 +57,7 @@ func InitIntegration(portClient *cli.PortClient, applicationConfig *port.Config) } if applicationConfig.CreateDefaultResources { - klog.Infof("Creating default resources") + klog.Infof("Creating default resources (blueprints, pages, etc..)") if err := initializeDefaults(portClient, defaults); err != nil { klog.Warningf("Error initializing defaults: %s", err.Error()) klog.Warningf("Some default resources may not have been created. The integration will continue running.") From 8e5a816db8267f26de4a7276de12e597b839272e Mon Sep 17 00:00:00 2001 From: omribarouch Date: Thu, 16 Jan 2025 16:30:25 +0200 Subject: [PATCH 9/9] Fixed typo --- pkg/defaults/init.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/defaults/init.go b/pkg/defaults/init.go index a805346..7c3a2c1 100644 --- a/pkg/defaults/init.go +++ b/pkg/defaults/init.go @@ -37,7 +37,7 @@ func InitIntegration(portClient *cli.PortClient, applicationConfig *port.Config) defaultIntegrationConfig = defaults.AppConfig } - klog.warningf("Could not get integration with state key %s, error: %s", applicationConfig.StateKey, err.Error()) + klog.Warningf("Could not get integration with state key %s, error: %s", applicationConfig.StateKey, err.Error()) if err := integration.CreateIntegration(portClient, applicationConfig.StateKey, applicationConfig.EventListenerType, defaultIntegrationConfig); err != nil { return err }