Skip to content

Commit

Permalink
supporting delete dependents deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
yairsimantov20 committed Dec 27, 2023
1 parent 50f60c2 commit 7e18cab
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
14 changes: 10 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
12 changes: 5 additions & 7 deletions pkg/defaults/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions pkg/handlers/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion pkg/port/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

0 comments on commit 7e18cab

Please sign in to comment.