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

chore: Improve KubernetesRouter selection based on apiGroup #1750

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/controller/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (c *Controller) finalize(old interface{}) error {
}

// Revert the Kubernetes service
router := c.routerFactory.KubernetesRouter(canary.Spec.TargetRef.Kind, labelSelector, labelValue, ports)
router := c.routerFactory.KubernetesRouter(canary.Spec.TargetRef.APIVersion, canary.Spec.TargetRef.Kind, labelSelector, labelValue, ports)
if err := router.Finalize(canary); err != nil {
return fmt.Errorf("failed revert router: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (c *Controller) advanceCanary(name string, namespace string) {
}

// init Kubernetes router
kubeRouter := c.routerFactory.KubernetesRouter(cd.Spec.TargetRef.Kind, labelSelector, labelValue, ports)
kubeRouter := c.routerFactory.KubernetesRouter(cd.Spec.TargetRef.APIVersion, cd.Spec.TargetRef.Kind, labelSelector, labelValue, ports)

// reconcile the canary/primary services
if err := kubeRouter.Initialize(cd); err != nil {
Expand Down
13 changes: 8 additions & 5 deletions pkg/router/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ func NewFactory(kubeConfig *restclient.Config, kubeClient kubernetes.Interface,
}

// KubernetesRouter returns a KubernetesRouter interface implementation
func (factory *Factory) KubernetesRouter(kind string, labelSelector string, labelValue string, ports map[string]int32) KubernetesRouter {
switch kind {
case "Service":
return &KubernetesNoopRouter{}
default: // Daemonset or Deployment
func (factory *Factory) KubernetesRouter(apiVersion string, kind string, labelSelector string, labelValue string, ports map[string]int32) KubernetesRouter {
group := strings.Split(apiVersion, "/")[0]

switch {
case group == "apps" && (kind == "Deployment" || kind == "DaemonSet"):
return &KubernetesDefaultRouter{
logger: factory.logger,
flaggerClient: factory.flaggerClient,
Expand All @@ -71,6 +71,9 @@ func (factory *Factory) KubernetesRouter(kind string, labelSelector string, labe
labelValue: labelValue,
ports: ports,
}

default:
return &KubernetesNoopRouter{}
}
}

Expand Down
Loading