@@ -17,7 +17,6 @@ limitations under the License.
17
17
package conformance
18
18
19
19
import (
20
- "context"
21
20
"fmt"
22
21
"time"
23
22
@@ -26,7 +25,6 @@ import (
26
25
discoveryv1 "k8s.io/api/discovery/v1"
27
26
apierrors "k8s.io/apimachinery/pkg/api/errors"
28
27
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29
- "k8s.io/apimachinery/pkg/util/wait"
30
28
"sigs.k8s.io/mcs-api/pkg/apis/v1alpha1"
31
29
)
32
30
@@ -47,24 +45,19 @@ var _ = Describe("", Label(OptionalLabel, EndpointSliceLabel), func() {
47
45
endpointSlices := make ([]* discoveryv1.EndpointSlice , len (clients ))
48
46
49
47
for i , client := range clients {
50
- eps := t .awaitMCSEndpointSlice (& client )
51
- Expect (eps ).ToNot (BeNil (), reportNonConformant (fmt .Sprintf (
48
+ eps := t .awaitMCSEndpointSlice (& client , discoveryv1 .AddressTypeIPv4 , nil , reportNonConformant (fmt .Sprintf (
52
49
"an MCS EndpointSlice was not found on cluster %q. An MCS EndpointSlice is identified by the presence " +
53
- "of at least one of the required MCS labels, whose names are prefixed with \" multicluster.kubernetes.io \" . " +
50
+ "of the required MCS labels (%q and %q) . " +
54
51
"If the MCS implementation does not use MCS EndpointSlices, you can specify a Ginkgo label filter using " +
55
52
"the %q label where appropriate to skip this test." ,
56
- client .name , EndpointSliceLabel )))
53
+ client .name , v1alpha1 . LabelServiceName , v1alpha1 . LabelSourceCluster , EndpointSliceLabel )))
57
54
58
55
endpointSlices [i ] = eps
59
56
60
57
Expect (eps .Labels ).To (HaveKeyWithValue (v1alpha1 .LabelServiceName , t .helloService .Name ),
61
58
reportNonConformant (fmt .Sprintf ("the MCS EndpointSlice %q does not contain the %q label referencing the service name" ,
62
59
eps .Name , v1alpha1 .LabelServiceName )))
63
60
64
- Expect (eps .Labels ).To (HaveKey (v1alpha1 .LabelSourceCluster ),
65
- reportNonConformant (fmt .Sprintf ("the MCS EndpointSlice %q does not contain the %q label" ,
66
- eps .Name , v1alpha1 .LabelSourceCluster )))
67
-
68
61
Expect (eps .Labels ).To (HaveKey (discoveryv1 .LabelManagedBy ),
69
62
reportNonConformant (fmt .Sprintf ("the MCS EndpointSlice %q does not contain the %q label" ,
70
63
eps .Name , discoveryv1 .LabelManagedBy )))
@@ -90,32 +83,38 @@ var _ = Describe("", Label(OptionalLabel, EndpointSliceLabel), func() {
90
83
})
91
84
})
92
85
93
- func (t * testDriver ) awaitMCSEndpointSlice (c * clusterClients ) * discoveryv1.EndpointSlice {
86
+ func (t * testDriver ) awaitMCSEndpointSlice (c * clusterClients , addressType discoveryv1.AddressType ,
87
+ verify func (Gomega , * discoveryv1.EndpointSlice ), desc ... any ) * discoveryv1.EndpointSlice {
94
88
var endpointSlice * discoveryv1.EndpointSlice
95
89
96
90
hasLabel := func (eps * discoveryv1.EndpointSlice , label string ) bool {
97
91
_ , exists := eps .Labels [label ]
98
92
return exists
99
93
}
100
94
101
- _ = wait .PollUntilContextTimeout (ctx , 100 * time .Millisecond ,
102
- 20 * time .Second , true , func (ctx context.Context ) (bool , error ) {
103
- defer GinkgoRecover ()
95
+ Eventually (func (g Gomega ) {
96
+ list , err := c .k8s .DiscoveryV1 ().EndpointSlices (t .namespace ).List (ctx , metav1.ListOptions {})
97
+ g .Expect (err ).ToNot (HaveOccurred (), "Error retrieving EndpointSlices" )
98
+
99
+ endpointSlice = nil
104
100
105
- list , err := c . k8s . DiscoveryV1 (). EndpointSlices ( t . namespace ). List ( ctx , metav1. ListOptions {})
106
- Expect ( err ). ToNot ( HaveOccurred (), "Error retrieving EndpointSlices" )
101
+ for i := range list . Items {
102
+ eps := & list . Items [ i ]
107
103
108
- for i := range list . Items {
109
- eps := & list . Items [ i ]
104
+ if hasLabel ( eps , v1alpha1 . LabelServiceName ) && hasLabel ( eps , v1alpha1 . LabelSourceCluster ) && eps . AddressType == addressType {
105
+ endpointSlice = eps
110
106
111
- if hasLabel (eps , v1alpha1 .LabelServiceName ) || hasLabel (eps , v1alpha1 .LabelSourceCluster ) {
112
- endpointSlice = eps
113
- return true , nil
107
+ if verify != nil {
108
+ verify (g , endpointSlice )
114
109
}
115
110
}
111
+ }
112
+
113
+ g .Expect (endpointSlice ).ToNot (BeNil (), desc ... )
116
114
117
- return false , nil
118
- })
115
+ // The final run succeeded so cancel any prior non-conformance reported.
116
+ cancelNonConformanceReport ()
117
+ }).Within (20 * time .Second ).ProbeEvery (100 * time .Millisecond ).Should (Succeed ())
119
118
120
119
return endpointSlice
121
120
}
0 commit comments