Skip to content

Commit ae879cd

Browse files
committed
chore: Improve KubernetesRouter selection based on apiGroup
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 <[email protected]>
1 parent 9000136 commit ae879cd

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

pkg/controller/finalizer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (c *Controller) finalize(old interface{}) error {
9999
}
100100

101101
// Revert the Kubernetes service
102-
router := c.routerFactory.KubernetesRouter(canary.Spec.TargetRef.Kind, labelSelector, labelValue, ports)
102+
router := c.routerFactory.KubernetesRouter(canary.Spec.TargetRef.APIVersion, canary.Spec.TargetRef.Kind, labelSelector, labelValue, ports)
103103
if err := router.Finalize(canary); err != nil {
104104
return fmt.Errorf("failed revert router: %w", err)
105105
}

pkg/controller/scheduler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func (c *Controller) advanceCanary(name string, namespace string) {
193193
}
194194

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

198198
// reconcile the canary/primary services
199199
if err := kubeRouter.Initialize(cd); err != nil {

pkg/router/factory.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ func NewFactory(kubeConfig *restclient.Config, kubeClient kubernetes.Interface,
5858
}
5959

6060
// KubernetesRouter returns a KubernetesRouter interface implementation
61-
func (factory *Factory) KubernetesRouter(kind string, labelSelector string, labelValue string, ports map[string]int32) KubernetesRouter {
62-
switch kind {
63-
case "Service":
64-
return &KubernetesNoopRouter{}
65-
default: // Daemonset or Deployment
61+
func (factory *Factory) KubernetesRouter(apiVersion string, kind string, labelSelector string, labelValue string, ports map[string]int32) KubernetesRouter {
62+
group := strings.Split(apiVersion, "/")[0]
63+
64+
switch {
65+
case group == "apps" && (kind == "Deployment" || kind == "DaemonSet"):
6666
return &KubernetesDefaultRouter{
6767
logger: factory.logger,
6868
flaggerClient: factory.flaggerClient,
@@ -71,6 +71,9 @@ func (factory *Factory) KubernetesRouter(kind string, labelSelector string, labe
7171
labelValue: labelValue,
7272
ports: ports,
7373
}
74+
75+
default:
76+
return &KubernetesNoopRouter{}
7477
}
7578
}
7679

0 commit comments

Comments
 (0)