Skip to content

Commit

Permalink
chore: Improve KubernetesRouter selection based on apiGroup
Browse files Browse the repository at this point in the history
Allow `.spec.targetRef` to specify custom resources, which typically use mesh routers.
Prevent unnecessary resources by strictly handling Deployment and DaemonSet based on apiGroup derived from apiVersion.

Signed-off-by: kahirokunn <okinakahiro@gmail.com>
  • Loading branch information
kahirokunn committed Dec 19, 2024
1 parent 9000136 commit 668c502
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
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

0 comments on commit 668c502

Please sign in to comment.