From 84fb4ffcd482e011a0dcce85ea575c6260725352 Mon Sep 17 00:00:00 2001 From: razsamuel Date: Tue, 21 May 2024 12:05:04 +0300 Subject: [PATCH 1/2] Add UpdateEntityOnlyOnDiff to mapping --- pkg/config/config.go | 1 + pkg/handlers/controllers.go | 2 +- pkg/k8s/controller.go | 4 ++-- pkg/k8s/controller_test.go | 11 ++++++++--- pkg/port/models.go | 2 ++ 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 7e78a2d..260b290 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -57,6 +57,7 @@ func NewConfiguration() (*port.Config, error) { OverwriteConfigurationOnRestart: ApplicationConfig.OverwriteConfigurationOnRestart, CreateMissingRelatedEntities: ApplicationConfig.CreateMissingRelatedEntities, DeleteDependents: ApplicationConfig.DeleteDependents, + UpdateEntityOnlyOnDiff: ApplicationConfig.UpdateEntityOnlyOnDiff, } v, err := os.ReadFile(ApplicationConfig.ConfigFilePath) diff --git a/pkg/handlers/controllers.go b/pkg/handlers/controllers.go index bb4da4b..ec28fa8 100644 --- a/pkg/handlers/controllers.go +++ b/pkg/handlers/controllers.go @@ -50,7 +50,7 @@ func NewControllersHandler(exporterConfig *port.Config, portConfig *port.Integra } informer := informersFactory.ForResource(gvr) - controller := k8s.NewController(port.AggregatedResource{Kind: kind, KindConfigs: kindConfigs}, portClient, informer) + controller := k8s.NewController(port.AggregatedResource{Kind: kind, KindConfigs: kindConfigs}, portClient, informer, portConfig) controllers = append(controllers, controller) } diff --git a/pkg/k8s/controller.go b/pkg/k8s/controller.go index 1284021..7650bc9 100644 --- a/pkg/k8s/controller.go +++ b/pkg/k8s/controller.go @@ -47,7 +47,7 @@ type Controller struct { workqueue workqueue.RateLimitingInterface } -func NewController(resource port.AggregatedResource, portClient *cli.PortClient, informer informers.GenericInformer) *Controller { +func NewController(resource port.AggregatedResource, portClient *cli.PortClient, informer informers.GenericInformer, integrationConfig *port.IntegrationAppConfig) *Controller { controller := &Controller{ resource: resource, portClient: portClient, @@ -73,7 +73,7 @@ func NewController(resource port.AggregatedResource, portClient *cli.PortClient, item.Key, err = cache.MetaNamespaceKeyFunc(new) if err == nil { - if controller.shouldSendUpdateEvent(old, new, config.ApplicationConfig.UpdateEntityOnlyOnDiff) { + if controller.shouldSendUpdateEvent(old, new, integrationConfig.UpdateEntityOnlyOnDiff) { controller.workqueue.Add(item) } } diff --git a/pkg/k8s/controller_test.go b/pkg/k8s/controller_test.go index 18e2f09..be345fd 100644 --- a/pkg/k8s/controller_test.go +++ b/pkg/k8s/controller_test.go @@ -36,6 +36,11 @@ type fixture struct { } func newFixture(t *testing.T, portClientId string, portClientSecret string, userAgent string, resource port.Resource, objects []runtime.Object) *fixture { + interationConfig := &port.IntegrationAppConfig{ + DeleteDependents: true, + CreateMissingRelatedEntities: true, + Resources: []port.Resource{resource}, + } kubeclient := k8sfake.NewSimpleDynamicClient(runtime.NewScheme()) if portClientId == "" { @@ -56,7 +61,7 @@ func newFixture(t *testing.T, portClientId string, portClientSecret string, user return &fixture{ t: t, - controller: newController(resource, objects, portClient, kubeclient), + controller: newController(resource, objects, portClient, kubeclient, interationConfig), } } @@ -146,13 +151,13 @@ func newUnstructured(obj interface{}) *unstructured.Unstructured { return &unstructured.Unstructured{Object: res} } -func newController(resource port.Resource, objects []runtime.Object, portClient *cli.PortClient, kubeclient *k8sfake.FakeDynamicClient) *Controller { +func newController(resource port.Resource, objects []runtime.Object, portClient *cli.PortClient, kubeclient *k8sfake.FakeDynamicClient, integrationConfig *port.IntegrationAppConfig) *Controller { k8sI := dynamicinformer.NewDynamicSharedInformerFactory(kubeclient, noResyncPeriodFunc()) s := strings.SplitN(resource.Kind, "/", 3) gvr := schema.GroupVersionResource{Group: s[0], Version: s[1], Resource: s[2]} informer := k8sI.ForResource(gvr) kindConfig := port.KindConfig{Selector: resource.Selector, Port: resource.Port} - c := NewController(port.AggregatedResource{Kind: resource.Kind, KindConfigs: []port.KindConfig{kindConfig}}, portClient, informer) + c := NewController(port.AggregatedResource{Kind: resource.Kind, KindConfigs: []port.KindConfig{kindConfig}}, portClient, informer, integrationConfig) for _, d := range objects { informer.Informer().GetIndexer().Add(d) diff --git a/pkg/port/models.go b/pkg/port/models.go index dc0e64e..ea97c68 100644 --- a/pkg/port/models.go +++ b/pkg/port/models.go @@ -269,6 +269,7 @@ type IntegrationAppConfig struct { Resources []Resource `json:"resources,omitempty" yaml:"resources,omitempty"` CRDSToDiscover string `json:"crdsToDiscover,omitempty"` OverwriteCRDsActions bool `json:"overwriteCrdsActions,omitempty"` + UpdateEntityOnlyOnDiff bool `json:"updateEntityOnlyOnDiff,omitempty"` } type Config struct { @@ -283,4 +284,5 @@ type Config struct { OverwriteCRDsActions bool `yaml:"overwriteCrdsActions,omitempty"` DeleteDependents bool `yaml:"deleteDependents,omitempty"` CreateMissingRelatedEntities bool `yaml:"createMissingRelatedEntities,omitempty"` + UpdateEntityOnlyOnDiff bool `yaml:"updateEntityOnlyOnDiff,omitempty"` } From cef8599dde91e86fd24d41898aef36ef68682903 Mon Sep 17 00:00:00 2001 From: razsamuel Date: Tue, 21 May 2024 12:26:32 +0300 Subject: [PATCH 2/2] CR fixes - remove deprecated params --- pkg/config/config.go | 1 - pkg/port/models.go | 1 - 2 files changed, 2 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 260b290..7e78a2d 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -57,7 +57,6 @@ func NewConfiguration() (*port.Config, error) { OverwriteConfigurationOnRestart: ApplicationConfig.OverwriteConfigurationOnRestart, CreateMissingRelatedEntities: ApplicationConfig.CreateMissingRelatedEntities, DeleteDependents: ApplicationConfig.DeleteDependents, - UpdateEntityOnlyOnDiff: ApplicationConfig.UpdateEntityOnlyOnDiff, } v, err := os.ReadFile(ApplicationConfig.ConfigFilePath) diff --git a/pkg/port/models.go b/pkg/port/models.go index ea97c68..3c22911 100644 --- a/pkg/port/models.go +++ b/pkg/port/models.go @@ -284,5 +284,4 @@ type Config struct { OverwriteCRDsActions bool `yaml:"overwriteCrdsActions,omitempty"` DeleteDependents bool `yaml:"deleteDependents,omitempty"` CreateMissingRelatedEntities bool `yaml:"createMissingRelatedEntities,omitempty"` - UpdateEntityOnlyOnDiff bool `yaml:"updateEntityOnlyOnDiff,omitempty"` }