Skip to content

Commit a23ff80

Browse files
authored
Merge pull request #108 from zhiying-lin/add-conformance-test
test: add conformance test for the externalName type service
2 parents 38bab5b + 6415203 commit a23ff80

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

conformance/conformance_suite.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,22 @@ func (t *testDriver) ensureServiceImport(c *clusterClients, name, nonConformance
267267
}, 5*time.Second, 100*time.Millisecond).ShouldNot(HaveOccurred(), reportNonConformant(nonConformanceMsg))
268268
}
269269

270-
func (t *testDriver) awaitServiceExportCondition(c *clusterClients, condType string) {
270+
func (t *testDriver) ensureNoServiceImport(c *clusterClients, name, nonConformanceMsg string) {
271+
Consistently(func() bool {
272+
_, err := c.mcs.MulticlusterV1alpha1().ServiceImports(t.namespace).Get(ctx, name, metav1.GetOptions{})
273+
return apierrors.IsNotFound(err)
274+
}, 5*time.Second, 100*time.Millisecond).Should(BeTrue(), reportNonConformant(nonConformanceMsg))
275+
}
276+
277+
func (t *testDriver) awaitServiceExportCondition(c *clusterClients, condType string, wantStatus metav1.ConditionStatus) {
271278
Eventually(func() bool {
272279
se, err := c.mcs.MulticlusterV1alpha1().ServiceExports(t.namespace).Get(ctx, helloServiceName, metav1.GetOptions{})
273280
Expect(err).ToNot(HaveOccurred())
274281

275-
return meta.FindStatusCondition(se.Status.Conditions, condType) != nil
282+
cond := meta.FindStatusCondition(se.Status.Conditions, condType)
283+
return cond != nil && cond.Status == wantStatus
276284
}, 20*time.Second, 100*time.Millisecond).Should(BeTrue(),
277-
reportNonConformant(fmt.Sprintf("The %s condition was not set", condType)))
285+
reportNonConformant(fmt.Sprintf("The %s condition was not set to %s", condType, wantStatus)))
278286
}
279287

280288
func (t *testDriver) startRequestPod(ctx context.Context, client clusterClients) {

conformance/report.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const (
4040
ConnectivityLabel = "Connectivity"
4141
ClusterIPLabel = "ClusterIP"
4242
HeadlessLabel = "Headless"
43+
ExternalNameLabel = "ExternalName"
4344
EndpointSliceLabel = "EndpointSlice"
4445
ExportedLabelsLabel = "ExportedLabels"
4546
SpecRefReportEntry = "spec-ref"

conformance/service_import.go

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ import (
2424
. "github.com/onsi/ginkgo/v2"
2525
. "github.com/onsi/gomega"
2626
corev1 "k8s.io/api/core/v1"
27+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2728
"sigs.k8s.io/mcs-api/pkg/apis/v1alpha1"
2829
)
2930

3031
var (
3132
_ = Describe("", testGeneralServiceImport)
3233
_ = Describe("", Label(ClusterIPLabel), testClusterIPServiceImport)
3334
_ = Describe("", Label(HeadlessLabel), testHeadlessServiceImport)
35+
_ = Describe("", Label(ExternalNameLabel), testExternalNameService)
3436
)
3537

3638
func testGeneralServiceImport() {
@@ -136,8 +138,8 @@ func testGeneralServiceImport() {
136138
Label(OptionalLabel), Label(ExportedLabelsLabel), func() {
137139
AddReportEntry(SpecRefReportEntry, "https://github.com/kubernetes/enhancements/tree/master/keps/sig-multicluster/1645-multi-cluster-services-api#labels-and-annotations")
138140

139-
t.awaitServiceExportCondition(&clients[0], v1alpha1.ServiceExportConflict)
140-
t.awaitServiceExportCondition(&clients[1], v1alpha1.ServiceExportConflict)
141+
t.awaitServiceExportCondition(&clients[0], v1alpha1.ServiceExportConflict, metav1.ConditionTrue)
142+
t.awaitServiceExportCondition(&clients[1], v1alpha1.ServiceExportConflict, metav1.ConditionTrue)
141143

142144
serviceImport := t.awaitServiceImport(&clients[0], t.helloService.Name, func(serviceImport *v1alpha1.ServiceImport) bool {
143145
return len(serviceImport.Labels) > 0
@@ -263,8 +265,8 @@ func testClusterIPServiceImport() {
263265
Specify("should apply the conflict resolution policy and report a Conflict condition on each ServiceExport", func() {
264266
AddReportEntry(SpecRefReportEntry, "https://github.com/kubernetes/enhancements/tree/master/keps/sig-multicluster/1645-multi-cluster-services-api#service-port")
265267

266-
t.awaitServiceExportCondition(&clients[0], v1alpha1.ServiceExportConflict)
267-
t.awaitServiceExportCondition(&clients[1], v1alpha1.ServiceExportConflict)
268+
t.awaitServiceExportCondition(&clients[0], v1alpha1.ServiceExportConflict, metav1.ConditionTrue)
269+
t.awaitServiceExportCondition(&clients[1], v1alpha1.ServiceExportConflict, metav1.ConditionTrue)
268270

269271
serviceImport := t.awaitServiceImport(&clients[0], t.helloService.Name, func(serviceImport *v1alpha1.ServiceImport) bool {
270272
return len(serviceImport.Spec.Ports) == len(t.helloService.Spec.Ports)
@@ -323,3 +325,24 @@ func testHeadlessServiceImport() {
323325
}).Within(5*time.Second).ProbeEvery(time.Second).Should(BeEmpty(), reportNonConformant(""))
324326
})
325327
}
328+
329+
func testExternalNameService() {
330+
t := newTestDriver()
331+
332+
BeforeEach(func() {
333+
t.helloService.Spec.Type = corev1.ServiceTypeExternalName
334+
t.helloService.Spec.ExternalName = "example.com"
335+
})
336+
337+
JustBeforeEach(func() {
338+
t.createServiceExport(&clients[0], newHelloServiceExport())
339+
})
340+
341+
Specify("Exporting an ExternalName service should set ServiceExport Valid condition to False", Label(RequiredLabel), func() {
342+
AddReportEntry(SpecRefReportEntry, "https://github.com/kubernetes/enhancements/blob/master/keps/sig-multicluster/1645-multi-cluster-services-api/README.md#service-types")
343+
344+
t.awaitServiceExportCondition(&clients[0], v1alpha1.ServiceExportValid, metav1.ConditionFalse)
345+
t.ensureNoServiceImport(&clients[0], helloServiceName,
346+
"the ServiceImport should not exist for an ExternalName service")
347+
})
348+
}

0 commit comments

Comments
 (0)