From 7e18cab1ee3c7e0a72b0443c30aaf4997a93f18a Mon Sep 17 00:00:00 2001 From: yair Date: Wed, 27 Dec 2023 13:37:48 +0200 Subject: [PATCH] supporting delete dependents deprecated --- pkg/config/config.go | 14 ++++++++++---- pkg/config/models.go | 4 ++++ pkg/defaults/init.go | 12 +++++------- pkg/handlers/controllers.go | 4 ---- pkg/port/models.go | 6 +++++- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 309a6d6..aa753be 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -37,15 +37,21 @@ func Init() { NewString(&ApplicationConfig.PortClientSecret, "port-client-secret", "", "Port client secret. Required.") NewBool(&ApplicationConfig.CreateDefaultResources, "create-default-resources", true, "Create default resources on installation. Optional.") + // Deprecated + NewBool(&ApplicationConfig.DeleteDependents, "delete-dependents", false, "Delete dependents. Optional.") + NewBool(&ApplicationConfig.CreateMissingRelatedEntities, "create-missing-related-entities", false, "Create missing related entities. Optional.") + flag.Parse() } func NewConfiguration() (*port.Config, error) { overrides := &port.Config{ - StateKey: ApplicationConfig.StateKey, - EventListenerType: ApplicationConfig.EventListenerType, - CreateDefaultResources: ApplicationConfig.CreateDefaultResources, - ResyncInterval: ApplicationConfig.ResyncInterval, + StateKey: ApplicationConfig.StateKey, + EventListenerType: ApplicationConfig.EventListenerType, + CreateDefaultResources: ApplicationConfig.CreateDefaultResources, + ResyncInterval: ApplicationConfig.ResyncInterval, + CreateMissingRelatedEntities: ApplicationConfig.CreateMissingRelatedEntities, + DeleteDependents: ApplicationConfig.DeleteDependents, } c, err := GetConfigFile(ApplicationConfig.ConfigFilePath) diff --git a/pkg/config/models.go b/pkg/config/models.go index 8722390..4626e05 100644 --- a/pkg/config/models.go +++ b/pkg/config/models.go @@ -23,4 +23,8 @@ type ApplicationConfiguration struct { CreateDefaultResources 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. + CreateMissingRelatedEntities bool `json:"createMissingRelatedEntities,omitempty"` } diff --git a/pkg/defaults/init.go b/pkg/defaults/init.go index 7320a3f..2a04953 100644 --- a/pkg/defaults/init.go +++ b/pkg/defaults/init.go @@ -19,7 +19,9 @@ func getEventListenerConfig(eventListenerType string) *port.EventListenerSetting func InitIntegration(portClient *cli.PortClient, applicationConfig *port.Config) error { existingIntegration, err := integration.GetIntegration(portClient, applicationConfig.StateKey) defaultIntegrationConfig := &port.IntegrationAppConfig{ - Resources: applicationConfig.Resources, + Resources: applicationConfig.Resources, + DeleteDependents: applicationConfig.DeleteDependents, + CreateMissingRelatedEntities: applicationConfig.CreateMissingRelatedEntities, } if err != nil { @@ -44,12 +46,8 @@ func InitIntegration(portClient *cli.PortClient, applicationConfig *port.Config) // Handle a deprecated case where resources are provided in config file and integration exists from previous //versions without a config - if existingIntegration.Config == nil && defaultIntegrationConfig.Resources != nil { - integrationPatch.Config = &port.IntegrationAppConfig{ - DeleteDependents: defaultIntegrationConfig.DeleteDependents, - CreateMissingRelatedEntities: defaultIntegrationConfig.CreateMissingRelatedEntities, - Resources: defaultIntegrationConfig.Resources, - } + if existingIntegration.Config == nil { + integrationPatch.Config = defaultIntegrationConfig } return integration.PatchIntegration(portClient, applicationConfig.StateKey, integrationPatch) diff --git a/pkg/handlers/controllers.go b/pkg/handlers/controllers.go index 83437e4..4c14395 100644 --- a/pkg/handlers/controllers.go +++ b/pkg/handlers/controllers.go @@ -50,10 +50,6 @@ func NewControllersHandler(exporterConfig *port.Config, portConfig *port.Integra controllers = append(controllers, controller) } - if len(controllers) == 0 { - klog.Fatalf("Failed to initiate a controller for all resources, exiting...") - } - controllersHandler := &ControllersHandler{ controllers: controllers, informersFactory: informersFactory, diff --git a/pkg/port/models.go b/pkg/port/models.go index 87c1198..fa2c952 100644 --- a/pkg/port/models.go +++ b/pkg/port/models.go @@ -220,5 +220,9 @@ type Config struct { EventListenerType string CreateDefaultResources bool // Deprecated: use IntegrationAppConfig instead. Used for updating the Port integration config on startup. - Resources []Resource + Resources []Resource `json:"resources,omitempty"` + // 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. + CreateMissingRelatedEntities bool `json:"createMissingRelatedEntities,omitempty"` }