Skip to content

Commit

Permalink
Merge pull request #67 from port-labs/PORT-8228-add_update_entity_onl…
Browse files Browse the repository at this point in the history
…y_on_diff_to_mapping

PORT-8228 Add UpdateEntityOnlyOnDiff to mapping
  • Loading branch information
razsamuel authored May 21, 2024
2 parents b5002ea + cef8599 commit ef7be1d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/handlers/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/k8s/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}
}
Expand Down
11 changes: 8 additions & 3 deletions pkg/k8s/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand All @@ -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),
}
}

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pkg/port/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ef7be1d

Please sign in to comment.