Skip to content

Commit

Permalink
Add UpdateEntityOnlyOnDiff to mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
razsamuel committed May 21, 2024
1 parent b5002ea commit 84fb4ff
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
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
2 changes: 2 additions & 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 All @@ -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"`
}

0 comments on commit 84fb4ff

Please sign in to comment.