Skip to content
Merged
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
15 changes: 15 additions & 0 deletions pkg/router/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,5 +395,20 @@ func makeDestination(canary *flaggerv1.Canary, host string, weight int) istiov1a
Weight: weight,
}

// set destination port when an ingress gateway is specified
if canary.Spec.Service.PortDiscovery &&
len(canary.Spec.Service.Gateways) > 0 &&
canary.Spec.Service.Gateways[0] != "mesh" {
dest = istiov1alpha3.DestinationWeight{
Destination: istiov1alpha3.Destination{
Host: host,
Port: &istiov1alpha3.PortSelector{
Number: uint32(canary.Spec.Service.Port),
},
},
Weight: weight,
}
}

return dest
}
37 changes: 33 additions & 4 deletions pkg/router/istio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,20 @@ func TestIstioRouter_Sync(t *testing.T) {
gateways := vsClone.Spec.Gateways
gateways = append(gateways, "test-gateway.istio-system")
vsClone.Spec.Gateways = gateways
totalGateways := len(mocks.canary.Spec.Service.Gateways)

vsGateways, err := mocks.meshClient.NetworkingV1alpha3().VirtualServices("default").Update(vsClone)
if err != nil {
t.Fatal(err.Error())
}
if len(vsGateways.Spec.Gateways) != 2 {
t.Errorf("Got Istio VS gateway %v wanted %v", vsGateways.Spec.Gateways, 2)

totalGateways++
if len(vsGateways.Spec.Gateways) != totalGateways {
t.Errorf("Got Istio VS gateway %v wanted %v", vsGateways.Spec.Gateways, totalGateways)
}

// undo change
totalGateways--
err = router.Reconcile(mocks.canary)
if err != nil {
t.Fatal(err.Error())
Expand All @@ -102,8 +106,8 @@ func TestIstioRouter_Sync(t *testing.T) {
if err != nil {
t.Fatal(err.Error())
}
if len(vs.Spec.Gateways) != 1 {
t.Errorf("Got Istio VS gateways %v wanted %v", vs.Spec.Gateways, 1)
if len(vs.Spec.Gateways) != totalGateways {
t.Errorf("Got Istio VS gateways %v wanted %v", vs.Spec.Gateways, totalGateways)
}
}

Expand Down Expand Up @@ -438,3 +442,28 @@ func TestIstioRouter_ABTest(t *testing.T) {
t.Errorf("Got mirror %v wanted nil", mirror)
}
}

func TestIstioRouter_GatewayPort(t *testing.T) {
mocks := newFixture()
router := &IstioRouter{
logger: mocks.logger,
flaggerClient: mocks.flaggerClient,
istioClient: mocks.meshClient,
kubeClient: mocks.kubeClient,
}

err := router.Reconcile(mocks.canary)
if err != nil {
t.Fatal(err.Error())
}

vs, err := mocks.meshClient.NetworkingV1alpha3().VirtualServices("default").Get("podinfo", metav1.GetOptions{})
if err != nil {
t.Fatal(err.Error())
}

port := vs.Spec.Http[0].Route[0].Destination.Port.Number
if port != uint32(mocks.canary.Spec.Service.Port) {
t.Fatalf("Got port %v wanted %v", port, mocks.canary.Spec.Service.Port)
}
}
7 changes: 6 additions & 1 deletion pkg/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ func newMockCanary() *flaggerv1.Canary {
Kind: "Deployment",
},
Service: flaggerv1.CanaryService{
Port: 9898,
Port: 9898,
PortDiscovery: true,
Headers: &istiov1alpha3.Headers{
Request: &istiov1alpha3.HeaderOperations{
Add: map[string]string{
Expand All @@ -136,6 +137,10 @@ func newMockCanary() *flaggerv1.Canary {
Attempts: 10,
PerTryTimeout: "30s",
},
Gateways: []string{
"public-gateway.istio",
"mesh",
},
}, CanaryAnalysis: flaggerv1.CanaryAnalysis{
Threshold: 10,
StepWeight: 10,
Expand Down