@@ -31,6 +31,7 @@ import (
31
31
32
32
"github.com/kcp-dev/logicalcluster/v3"
33
33
34
+ kcpfeatures "github.com/kcp-dev/kcp/pkg/features"
34
35
apisv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1"
35
36
apisv1alpha2 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha2"
36
37
corev1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1"
@@ -39,6 +40,9 @@ import (
39
40
)
40
41
41
42
func TestReconcile (t * testing.T ) {
43
+ // Save original feature gate value
44
+ originalFeatureGate := kcpfeatures .DefaultFeatureGate .Enabled (kcpfeatures .EnableDeprecatedAPIExportVirtualWorkspacesUrls )
45
+
42
46
tests := map [string ]struct {
43
47
secretRefSet bool
44
48
secretExists bool
@@ -50,6 +54,7 @@ func TestReconcile(t *testing.T) {
50
54
hasPreexistingVerifyFailure bool
51
55
listShardsError error
52
56
apiExportEndpointSliceNotFound bool
57
+ skipEndpointSliceAnnotation bool
53
58
54
59
apiBindings []interface {}
55
60
@@ -62,6 +67,7 @@ func TestReconcile(t *testing.T) {
62
67
wantVerifyFailure bool
63
68
wantIdentityValid bool
64
69
wantCreateAPIExportEndpointSlice bool
70
+ wantVirtualWorkspaceURLs bool
65
71
}{
66
72
"create secret when ref is nil and secret doesn't exist" : {
67
73
secretExists : false ,
@@ -133,11 +139,44 @@ func TestReconcile(t *testing.T) {
133
139
wantCreateAPIExportEndpointSlice : true ,
134
140
wantIdentityValid : true ,
135
141
},
142
+ "skip APIExportEndpointSlice creation when skip annotation is present" : {
143
+ secretRefSet : true ,
144
+ secretExists : true ,
145
+
146
+ wantStatusHashSet : true ,
147
+ apiExportEndpointSliceNotFound : true ,
148
+ wantCreateAPIExportEndpointSlice : false ,
149
+ wantIdentityValid : true ,
150
+ skipEndpointSliceAnnotation : true ,
151
+ },
152
+ "virtual workspace URLs when feature gate enabled" : {
153
+ secretRefSet : true ,
154
+ secretExists : true ,
155
+
156
+ wantStatusHashSet : true ,
157
+ wantIdentityValid : true ,
158
+ wantVirtualWorkspaceURLs : true ,
159
+ },
160
+ "error listing shards with feature gate enabled" : {
161
+ secretRefSet : true ,
162
+ secretExists : true ,
163
+
164
+ wantStatusHashSet : true ,
165
+ wantIdentityValid : true ,
166
+ wantVirtualWorkspaceURLs : false ,
167
+ listShardsError : errors .New ("foo" ),
168
+ },
136
169
}
137
170
138
171
for name , tc := range tests {
139
172
t .Run (name , func (t * testing.T ) {
173
+ // Skip virtual workspace URL tests if feature gate is not enabled
174
+ if tc .wantVirtualWorkspaceURLs && ! originalFeatureGate {
175
+ t .Skip ("Skipping test that requires EnableDeprecatedAPIExportVirtualWorkspacesUrls feature gate" )
176
+ }
177
+
140
178
createSecretCalled := false
179
+ createEndpointSliceCalled := false
141
180
142
181
expectedKey := "abc"
143
182
expectedHash := fmt .Sprintf ("%x" , sha256 .Sum256 ([]byte (expectedKey )))
@@ -158,6 +197,7 @@ func TestReconcile(t *testing.T) {
158
197
return & apisv1alpha1.APIExportEndpointSlice {}, nil
159
198
},
160
199
createAPIExportEndpointSlice : func (ctx context.Context , clusterName logicalcluster.Path , apiExportEndpointSlice * apisv1alpha1.APIExportEndpointSlice ) error {
200
+ createEndpointSliceCalled = true
161
201
return nil
162
202
},
163
203
getSecret : func (ctx context.Context , clusterName logicalcluster.Name , ns , name string ) (* corev1.Secret , error ) {
@@ -242,6 +282,10 @@ func TestReconcile(t *testing.T) {
242
282
conditions .MarkFalse (apiExport , apisv1alpha2 .APIExportIdentityValid , apisv1alpha2 .IdentityVerificationFailedReason , conditionsv1alpha1 .ConditionSeverityError , "" )
243
283
}
244
284
285
+ if tc .skipEndpointSliceAnnotation {
286
+ apiExport .Annotations [apisv1alpha2 .APIExportEndpointSliceSkipAnnotation ] = "true"
287
+ }
288
+
245
289
err := c .reconcile (context .Background (), apiExport )
246
290
if tc .wantError {
247
291
require .Error (t , err , "expected an error" )
@@ -292,6 +336,20 @@ func TestReconcile(t *testing.T) {
292
336
if tc .wantIdentityValid {
293
337
requireConditionMatches (t , apiExport , conditions .TrueCondition (apisv1alpha2 .APIExportIdentityValid ))
294
338
}
339
+
340
+ require .Equal (t , tc .wantCreateAPIExportEndpointSlice , createEndpointSliceCalled , "expected createEndpointSliceCalled to be %v" , tc .wantCreateAPIExportEndpointSlice )
341
+
342
+ if tc .wantVirtualWorkspaceURLs {
343
+ //nolint:staticcheck
344
+ require .NotNil (t , apiExport .Status .VirtualWorkspaces , "expected virtual workspace URLs to be set" )
345
+ //nolint:staticcheck
346
+ require .Len (t , apiExport .Status .VirtualWorkspaces , 2 , "expected 2 virtual workspace URLs" )
347
+ require .True (t , conditions .IsTrue (apiExport , apisv1alpha2 .APIExportVirtualWorkspaceURLsReady ), "expected virtual workspace URLs to be ready" )
348
+ } else {
349
+ //nolint:staticcheck
350
+ require .Nil (t , apiExport .Status .VirtualWorkspaces , "expected virtual workspace URLs to be nil" )
351
+ require .False (t , conditions .Has (apiExport , apisv1alpha2 .APIExportVirtualWorkspaceURLsReady ), "expected virtual workspace URLs condition to not exist" )
352
+ }
295
353
})
296
354
}
297
355
}
0 commit comments