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

Support for BlueGreen rollout preview endpoint #199

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add unit test
Signed-off-by: nbn01 <[email protected]>
nbn01 committed Apr 1, 2022
commit c97ed13fa432df2b5b1225f29f38170fea158ef7
77 changes: 77 additions & 0 deletions admiral/pkg/clusters/serviceentry_test.go
Original file line number Diff line number Diff line change
@@ -1161,6 +1161,83 @@ func TestCreateServiceEntryForBlueGreenRolloutsUsecase(t *testing.T) {
}
}

func TestUpdateEndpointsForBlueGreen(t *testing.T) {
const CLUSTER_INGRESS_1 = "ingress1.com"
const ACTIVE_SERVICE = "activeService"
const PREVIEW_SERVICE = "previewService"
const NAMESPACE = "namespace"
const ACTIVE_MESH_HOST = "qal.example.mesh"
const PREVIEW_MESH_HOST = "preview.qal.example.mesh"

rollout := argo.Rollout{}
rollout.Spec.Strategy = argo.RolloutStrategy{
BlueGreen: &argo.BlueGreenStrategy{
ActiveService: ACTIVE_SERVICE,
PreviewService: PREVIEW_SERVICE,
},
}
rollout.Spec.Template.Annotations = map[string]string{}
rollout.Spec.Template.Annotations[common.SidecarEnabledPorts] = "8080"

endpoint := istionetworkingv1alpha3.ServiceEntry_Endpoint{
Labels: map[string]string{}, Address: CLUSTER_INGRESS_1, Ports: map[string]uint32{"http": 15443},
}

meshPorts := map[string]uint32{"http": 8080}

weightedServices := map[string]*WeightedService{
ACTIVE_SERVICE: {Service: &v1.Service{ObjectMeta: v12.ObjectMeta{Name: ACTIVE_SERVICE, Namespace: NAMESPACE}}},
PREVIEW_SERVICE: {Service: &v1.Service{ObjectMeta: v12.ObjectMeta{Name: PREVIEW_SERVICE, Namespace: NAMESPACE}}},
}

activeWantedEndpoints := istionetworkingv1alpha3.ServiceEntry_Endpoint{
Address: ACTIVE_SERVICE + common.Sep + NAMESPACE + common.DotLocalDomainSuffix, Ports: meshPorts,
}

previewWantedEndpoints := istionetworkingv1alpha3.ServiceEntry_Endpoint{
Address: PREVIEW_SERVICE + common.Sep + NAMESPACE + common.DotLocalDomainSuffix, Ports: meshPorts,
}

testCases := []struct {
name string
rollout argo.Rollout
inputEndpoint istionetworkingv1alpha3.ServiceEntry_Endpoint
weightedServices map[string]*WeightedService
clusterIngress string
meshPorts map[string]uint32
meshHost string
wantedEndpoints istionetworkingv1alpha3.ServiceEntry_Endpoint
}{
{
name: "should return endpoint with active service address",
rollout: rollout,
inputEndpoint: endpoint,
weightedServices: weightedServices,
meshPorts: meshPorts,
meshHost: ACTIVE_MESH_HOST,
wantedEndpoints: activeWantedEndpoints,
},
{
name: "should return endpoint with preview service address",
rollout: rollout,
inputEndpoint: endpoint,
weightedServices: weightedServices,
meshPorts: meshPorts,
meshHost: PREVIEW_MESH_HOST,
wantedEndpoints: previewWantedEndpoints,
},
}

for _, c := range testCases {
t.Run(c.name, func(t *testing.T) {
updateEndpointsForBlueGreen(&c.rollout, c.weightedServices, map[string]string{}, &c.inputEndpoint, "test", c.meshHost)
if c.inputEndpoint.Address != c.wantedEndpoints.Address {
t.Errorf("Wanted %s endpoint, got: %s", c.wantedEndpoints.Address, c.inputEndpoint.Address)
}
})
}
}

func TestUpdateEndpointsForWeightedServices(t *testing.T) {
t.Parallel()