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..3c22911 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 {