Skip to content

Commit

Permalink
Rename service router to Kubernetes router
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprodan committed Mar 5, 2019
1 parent 42b850c commit 9680ca9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (c *Controller) advanceCanary(name string, namespace string, skipLivenessCh
meshRouter = rf.IstioRouter()

// create ClusterIP services and virtual service if needed
if err := rf.ServiceRouter().Sync(cd); err != nil {
if err := rf.KubernetesRouter().Sync(cd); err != nil {
c.recordEventWarningf(cd, "%v", err)
return
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/router/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func NewFactory(kubeClient kubernetes.Interface,
}
}

func (factory *Factory) ServiceRouter() *ServiceRouter {
return &ServiceRouter{
func (factory *Factory) KubernetesRouter() *KubernetesRouter {
return &KubernetesRouter{
logger: factory.logger,
flaggerClient: factory.flaggerClient,
kubeClient: factory.kubeClient,
Expand Down
40 changes: 20 additions & 20 deletions pkg/router/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,20 @@ func (ir *IstioRouter) Sync(cd *flaggerv1.Canary) error {
}

// GetRoutes returns the destinations weight for primary and canary
func (ir *IstioRouter) GetRoutes(cd *flaggerv1.Canary) (
func (ir *IstioRouter) GetRoutes(canary *flaggerv1.Canary) (
primaryWeight int,
canaryWeight int,
err error,
) {
targetName := cd.Spec.TargetRef.Name
targetName := canary.Spec.TargetRef.Name
vs := &istiov1alpha3.VirtualService{}
vs, err = ir.istioClient.NetworkingV1alpha3().VirtualServices(cd.Namespace).Get(targetName, v1.GetOptions{})
vs, err = ir.istioClient.NetworkingV1alpha3().VirtualServices(canary.Namespace).Get(targetName, v1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
err = fmt.Errorf("VirtualService %s.%s not found", targetName, cd.Namespace)
err = fmt.Errorf("VirtualService %s.%s not found", targetName, canary.Namespace)
return
}
err = fmt.Errorf("VirtualService %s.%s query error %v", targetName, cd.Namespace, err)
err = fmt.Errorf("VirtualService %s.%s query error %v", targetName, canary.Namespace, err)
return
}

Expand All @@ -156,42 +156,42 @@ func (ir *IstioRouter) GetRoutes(cd *flaggerv1.Canary) (

if primaryWeight == 0 && canaryWeight == 0 {
err = fmt.Errorf("VirtualService %s.%s does not contain routes for %s-primary and %s-canary",
targetName, cd.Namespace, targetName, targetName)
targetName, canary.Namespace, targetName, targetName)
}

return
}

// SetRoutes updates the destinations weight for primary and canary
func (ir *IstioRouter) SetRoutes(
cd *flaggerv1.Canary,
canary *flaggerv1.Canary,
primaryWeight int,
canaryWeight int,
) error {
targetName := cd.Spec.TargetRef.Name
vs, err := ir.istioClient.NetworkingV1alpha3().VirtualServices(cd.Namespace).Get(targetName, v1.GetOptions{})
targetName := canary.Spec.TargetRef.Name
vs, err := ir.istioClient.NetworkingV1alpha3().VirtualServices(canary.Namespace).Get(targetName, v1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return fmt.Errorf("VirtualService %s.%s not found", targetName, cd.Namespace)
return fmt.Errorf("VirtualService %s.%s not found", targetName, canary.Namespace)

}
return fmt.Errorf("VirtualService %s.%s query error %v", targetName, cd.Namespace, err)
return fmt.Errorf("VirtualService %s.%s query error %v", targetName, canary.Namespace, err)
}

vsCopy := vs.DeepCopy()
vsCopy.Spec.Http = []istiov1alpha3.HTTPRoute{
{
Match: cd.Spec.Service.Match,
Rewrite: cd.Spec.Service.Rewrite,
Timeout: cd.Spec.Service.Timeout,
Retries: cd.Spec.Service.Retries,
AppendHeaders: cd.Spec.Service.AppendHeaders,
Match: canary.Spec.Service.Match,
Rewrite: canary.Spec.Service.Rewrite,
Timeout: canary.Spec.Service.Timeout,
Retries: canary.Spec.Service.Retries,
AppendHeaders: canary.Spec.Service.AppendHeaders,
Route: []istiov1alpha3.DestinationWeight{
{
Destination: istiov1alpha3.Destination{
Host: fmt.Sprintf("%s-primary", targetName),
Port: istiov1alpha3.PortSelector{
Number: uint32(cd.Spec.Service.Port),
Number: uint32(canary.Spec.Service.Port),
},
},
Weight: primaryWeight,
Expand All @@ -200,7 +200,7 @@ func (ir *IstioRouter) SetRoutes(
Destination: istiov1alpha3.Destination{
Host: fmt.Sprintf("%s-canary", targetName),
Port: istiov1alpha3.PortSelector{
Number: uint32(cd.Spec.Service.Port),
Number: uint32(canary.Spec.Service.Port),
},
},
Weight: canaryWeight,
Expand All @@ -209,9 +209,9 @@ func (ir *IstioRouter) SetRoutes(
},
}

vs, err = ir.istioClient.NetworkingV1alpha3().VirtualServices(cd.Namespace).Update(vsCopy)
vs, err = ir.istioClient.NetworkingV1alpha3().VirtualServices(canary.Namespace).Update(vsCopy)
if err != nil {
return fmt.Errorf("VirtualService %s.%s update failed: %v", targetName, cd.Namespace, err)
return fmt.Errorf("VirtualService %s.%s update failed: %v", targetName, canary.Namespace, err)

}
return nil
Expand Down
10 changes: 5 additions & 5 deletions pkg/router/service.go → pkg/router/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import (
"k8s.io/client-go/kubernetes"
)

// ServiceRouter is managing ClusterIP services
type ServiceRouter struct {
// KubernetesRouter is managing ClusterIP services
type KubernetesRouter struct {
kubeClient kubernetes.Interface
flaggerClient clientset.Interface
logger *zap.SugaredLogger
}

// Sync creates to updates the primary and canary services
func (c *ServiceRouter) Sync(cd *flaggerv1.Canary) error {
func (c *KubernetesRouter) Sync(cd *flaggerv1.Canary) error {
targetName := cd.Spec.TargetRef.Name
primaryName := fmt.Sprintf("%s-primary", targetName)
canaryService, err := c.kubeClient.CoreV1().Services(cd.Namespace).Get(targetName, metav1.GetOptions{})
Expand Down Expand Up @@ -143,10 +143,10 @@ func (c *ServiceRouter) Sync(cd *flaggerv1.Canary) error {
return nil
}

func (c *ServiceRouter) SetRoutes(canary flaggerv1.Canary, primaryRoute int, canaryRoute int) error {
func (c *KubernetesRouter) SetRoutes(canary *flaggerv1.Canary, primaryRoute int, canaryRoute int) error {
return nil
}

func (c *ServiceRouter) GetRoutes(canary flaggerv1.Canary) (primaryRoute int, canaryRoute int, err error) {
func (c *KubernetesRouter) GetRoutes(canary *flaggerv1.Canary) (primaryRoute int, canaryRoute int, err error) {
return 0, 0, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

func TestServiceRouter_Sync(t *testing.T) {
mocks := setupfakeClients()
router := &ServiceRouter{
router := &KubernetesRouter{
kubeClient: mocks.kubeClient,
flaggerClient: mocks.flaggerClient,
logger: mocks.logger,
Expand Down

0 comments on commit 9680ca9

Please sign in to comment.