Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use controllers.DataPlane interface instead of concrete *dataplane.KongClient #4383

Merged
merged 1 commit into from
Jul 21, 2023

Conversation

programmer04
Copy link
Member

What this PR does / why we need it:

This PR decouples controllers from concrete *dataplane.KongClient in favor of using interface controllers.DataPlane..

Which issue this PR fixes:

closes #3794

Special notes for your reviewer:

The interface has to be extended to fit all use cases.

The only usage of concrete *dataplane.KongClient is left in

// setupKonnectNodeAgentWithMgr creates and adds Konnect NodeAgent as the manager's Runnable.
// Returns error if failed to create Konnect NodeAgent.
func setupKonnectNodeAgentWithMgr(
c *Config,
mgr manager.Manager,
konnectNodeAPIClient *nodes.Client,
dataplaneClient *dataplane.KongClient,
clientsManager *clients.AdminAPIClientsManager,
logger logr.Logger,
instanceIDProvider *InstanceIDProvider,
) error {
var hostname string
nn, err := util.GetPodNN()
if err != nil {
logger.Error(err, "Failed getting pod name and/or namespace, fallback to use hostname as node name in Konnect")
hostname, _ = os.Hostname()
} else {
hostname = nn.String()
logger.Info(fmt.Sprintf("Using %s as controller's node name in Konnect", hostname))
}
version := metadata.Release
// Set channel to send config status.
configStatusNotifier := clients.NewChannelConfigNotifier(logger)
dataplaneClient.SetConfigStatusNotifier(configStatusNotifier)
agent := konnect.NewNodeAgent(
hostname,
version,
c.Konnect.RefreshNodePeriod,
logger,
konnectNodeAPIClient,
configStatusNotifier,
konnect.NewGatewayClientGetter(logger, clientsManager),
clientsManager,
instanceIDProvider,
)
if err := mgr.Add(agent); err != nil {
return fmt.Errorf("failed adding konnect.NodeAgent runnable to the manager: %w", err)
}
return nil
}

that is ok, otherwise, interface would have to be extended with the method

SetConfigStatusNotifier(clients.ConfigStatusNotifier)

that is only used in the above function. It would pollute the interface.

@codecov
Copy link

codecov bot commented Jul 21, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.1 ⚠️

Comparison is base (e5969be) 65.3% compared to head (40aa94e) 65.3%.

Additional details and impacted files
@@           Coverage Diff           @@
##            main   #4383     +/-   ##
=======================================
- Coverage   65.3%   65.3%   -0.1%     
=======================================
  Files        154     154             
  Lines      17866   17866             
=======================================
- Hits       11678   11675      -3     
- Misses      5455    5456      +1     
- Partials     733     735      +2     
Impacted Files Coverage Δ
...nal/controllers/configuration/object_references.go 87.3% <ø> (ø)
...nal/controllers/configuration/secret_controller.go 28.1% <ø> (ø)
...trollers/configuration/zz_generated_controllers.go 26.2% <ø> (ø)
...ternal/controllers/gateway/grpcroute_controller.go 16.0% <ø> (ø)
...l/controllers/gateway/referencegrant_controller.go 23.2% <ø> (ø)
...nternal/controllers/gateway/tcproute_controller.go 15.7% <ø> (ø)
...nternal/controllers/gateway/tlsroute_controller.go 16.1% <ø> (ø)
...nternal/controllers/gateway/udproute_controller.go 15.8% <ø> (ø)
internal/controllers/knative/knative.go 48.9% <ø> (ø)
internal/dataplane/kong_client.go 85.1% <ø> (-1.1%) ⬇️
... and 1 more

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@programmer04 programmer04 merged commit 5f4dee3 into main Jul 21, 2023
30 checks passed
@programmer04 programmer04 deleted the decouple-concrete branch July 21, 2023 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reconcilers should use an interface for dataplane client instead of tightly coupling with dataplane.KongClient
2 participants