diff --git a/pkg/config/config.go b/pkg/config/config.go index 9222dea..625cff3 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -47,7 +47,7 @@ func Init() { } func NewConfiguration() (*port.Config, error) { - overrides := &port.Config{ + config := &port.Config{ StateKey: ApplicationConfig.StateKey, EventListenerType: ApplicationConfig.EventListenerType, CreateDefaultResources: ApplicationConfig.CreateDefaultResources, @@ -61,15 +61,15 @@ func NewConfiguration() (*port.Config, error) { if err != nil { v = []byte("{}") klog.Infof("Config file not found, using defaults") - return overrides, nil + return config, nil } klog.Infof("Config file found") - err = yaml.Unmarshal(v, &overrides) + err = yaml.Unmarshal(v, &config) if err != nil { return nil, fmt.Errorf("failed loading configuration: %w", err) } - overrides.StateKey = strings.ToLower(overrides.StateKey) + config.StateKey = strings.ToLower(config.StateKey) - return overrides, nil + return config, nil } diff --git a/pkg/config/models.go b/pkg/config/models.go index 05d94d1..8020d39 100644 --- a/pkg/config/models.go +++ b/pkg/config/models.go @@ -22,10 +22,8 @@ type ApplicationConfiguration struct { EventListenerType string CreateDefaultResources bool OverwriteConfigurationOnRestart bool - // Deprecated: use IntegrationAppConfig instead. Used for updating the Port integration config on startup. - Resources []port.Resource - // Deprecated: use IntegrationAppConfig instead. Used for updating the Port integration config on startup. - DeleteDependents bool `json:"deleteDependents,omitempty"` - // Deprecated: use IntegrationAppConfig instead. Used for updating the Port integration config on startup. + // These Configurations are used only for setting up the Integration on installation or when using OverwriteConfigurationOnRestart flag. + Resources []port.Resource + DeleteDependents bool `json:"deleteDependents,omitempty"` CreateMissingRelatedEntities bool `json:"createMissingRelatedEntities,omitempty"` } diff --git a/pkg/defaults/defaults_test.go b/pkg/defaults/defaults_test.go index 7a7c07e..a0ff870 100644 --- a/pkg/defaults/defaults_test.go +++ b/pkg/defaults/defaults_test.go @@ -192,7 +192,7 @@ func Test_InitIntegration_ExistingIntegration(t *testing.T) { checkResourcesDoesNotExist(f, []string{"workload", "namespace", "cluster"}, []string{"workload_overview_dashboard", "availability_scorecard_dashboard"}) } -func Test_InitIntegration_DeprecatedResourcesConfiguration(t *testing.T) { +func Test_InitIntegration_LocalResourcesConfiguration(t *testing.T) { f := NewFixture(t) err := integration.CreateIntegration(f.portClient, f.stateKey, "", nil) if err != nil { @@ -233,7 +233,7 @@ func Test_InitIntegration_DeprecatedResourcesConfiguration(t *testing.T) { checkResourcesDoesNotExist(f, []string{"workload", "namespace", "cluster"}, []string{"workload_overview_dashboard", "availability_scorecard_dashboard"}) } -func Test_InitIntegration_DeprecatedResourcesConfiguration_ExistingIntegration_EmptyConfiguration(t *testing.T) { +func Test_InitIntegration_LocalResourcesConfiguration_ExistingIntegration_EmptyConfiguration(t *testing.T) { f := NewFixture(t) err := integration.CreateIntegration(f.portClient, f.stateKey, "POLLING", nil) if err != nil { @@ -253,3 +253,49 @@ func Test_InitIntegration_DeprecatedResourcesConfiguration_ExistingIntegration_E checkResourcesDoesNotExist(f, []string{"workload", "namespace", "cluster"}, []string{"workload_overview_dashboard", "availability_scorecard_dashboard"}) } + +func Test_InitIntegration_LocalResourcesConfiguration_ExistingIntegration_WithConfiguration_WithOverwriteConfigurationOnRestartFlag(t *testing.T) { + f := NewFixture(t) + expectedResources := &port.IntegrationAppConfig{ + Resources: []port.Resource{ + { + Kind: "workload", + Port: port.Port{ + Entity: port.EntityMappings{ + Mappings: []port.EntityMapping{ + { + Identifier: "\"workload\"", + Title: "\"Workload\"", + Blueprint: "\"workload\"", + Icon: "\"Microservice\"", + Properties: map[string]string{ + "namespace": "\"default\"", + }, + }, + }, + }, + }, + }, + }, + } + err := integration.CreateIntegration(f.portClient, f.stateKey, "POLLING", expectedResources) + if err != nil { + t.Errorf("Error creating Port integration: %s", err.Error()) + } + + expectedResources.Resources[0].Kind = "namespace" + e := InitIntegration(f.portClient, &port.Config{ + StateKey: f.stateKey, + EventListenerType: "KAFKA", + Resources: expectedResources.Resources, + CreateDefaultResources: true, + OverwriteConfigurationOnRestart: true, + }) + assert.Nil(t, e) + + i, err := integration.GetIntegration(f.portClient, f.stateKey) + assert.Nil(t, err) + assert.Equal(t, expectedResources, i.Config.Resources) + + checkResourcesDoesNotExist(f, []string{"workload", "namespace", "cluster"}, []string{"workload_overview_dashboard", "availability_scorecard_dashboard"}) +} diff --git a/pkg/port/models.go b/pkg/port/models.go index 28a838a..57d1966 100644 --- a/pkg/port/models.go +++ b/pkg/port/models.go @@ -227,15 +227,13 @@ type IntegrationAppConfig struct { } type Config struct { - ResyncInterval uint `yaml:"resyncInterval,omitempty" json:"resyncInterval,omitempty"` - StateKey string `yaml:"stateKey,omitempty" json:"stateKey,omitempty"` - EventListenerType string `yaml:"eventListenerType,omitempty" json:"eventListenerType,omitempty"` - CreateDefaultResources bool `yaml:"createDefaultResources,omitempty" json:"createDefaultResources,omitempty"` - OverwriteConfigurationOnRestart bool `yaml:"overwriteConfigurationOnRestart,omitempty" json:"overwriteConfigurationOnRestart,omitempty"` - // Deprecated: use IntegrationAppConfig instead. Used for updating the Port integration config on startup. - Resources []Resource `yaml:"resources,omitempty" json:"resources,omitempty"` - // Deprecated: use IntegrationAppConfig instead. Used for updating the Port integration config on startup. - DeleteDependents bool `yaml:"deleteDependents,omitempty" json:"deleteDependents,omitempty"` - // Deprecated: use IntegrationAppConfig instead. Used for updating the Port integration config on startup. - CreateMissingRelatedEntities bool `yaml:"createMissingRelatedEntities,omitempty" json:"createMissingRelatedEntities,omitempty"` + ResyncInterval uint `yaml:"resyncInterval,omitempty"` + StateKey string `yaml:"stateKey,omitempty"` + EventListenerType string `yaml:"eventListenerType,omitempty"` + CreateDefaultResources bool `yaml:"createDefaultResources,omitempty"` + OverwriteConfigurationOnRestart bool `yaml:"overwriteConfigurationOnRestart,omitempty"` + // These Configurations are used only for setting up the Integration on installation or when using OverwriteConfigurationOnRestart flag. + Resources []Resource `yaml:"resources,omitempty"` + DeleteDependents bool `yaml:"deleteDependents,omitempty"` + CreateMissingRelatedEntities bool `yaml:"createMissingRelatedEntities,omitempty"` }