@@ -50,6 +50,7 @@ func TestReconcile(t *testing.T) {
5050 hasPreexistingVerifyFailure bool
5151 listShardsError error
5252 apiExportEndpointSliceNotFound bool
53+ skipEndpointSliceAnnotation bool
5354
5455 apiBindings []interface {}
5556
@@ -133,11 +134,22 @@ func TestReconcile(t *testing.T) {
133134 wantCreateAPIExportEndpointSlice : true ,
134135 wantIdentityValid : true ,
135136 },
137+ "skip APIExportEndpointSlice creation when skip annotation is present" : {
138+ secretRefSet : true ,
139+ secretExists : true ,
140+
141+ wantStatusHashSet : true ,
142+ apiExportEndpointSliceNotFound : true ,
143+ wantCreateAPIExportEndpointSlice : false ,
144+ wantIdentityValid : true ,
145+ skipEndpointSliceAnnotation : true ,
146+ },
136147 }
137148
138149 for name , tc := range tests {
139150 t .Run (name , func (t * testing.T ) {
140151 createSecretCalled := false
152+ createEndpointSliceCalled := false
141153
142154 expectedKey := "abc"
143155 expectedHash := fmt .Sprintf ("%x" , sha256 .Sum256 ([]byte (expectedKey )))
@@ -158,6 +170,7 @@ func TestReconcile(t *testing.T) {
158170 return & apisv1alpha1.APIExportEndpointSlice {}, nil
159171 },
160172 createAPIExportEndpointSlice : func (ctx context.Context , clusterName logicalcluster.Path , apiExportEndpointSlice * apisv1alpha1.APIExportEndpointSlice ) error {
173+ createEndpointSliceCalled = true
161174 return nil
162175 },
163176 getSecret : func (ctx context.Context , clusterName logicalcluster.Name , ns , name string ) (* corev1.Secret , error ) {
@@ -242,6 +255,10 @@ func TestReconcile(t *testing.T) {
242255 conditions .MarkFalse (apiExport , apisv1alpha2 .APIExportIdentityValid , apisv1alpha2 .IdentityVerificationFailedReason , conditionsv1alpha1 .ConditionSeverityError , "" )
243256 }
244257
258+ if tc .skipEndpointSliceAnnotation {
259+ apiExport .Annotations [apisv1alpha2 .APIExportEndpointSliceSkipAnnotation ] = "true"
260+ }
261+
245262 err := c .reconcile (context .Background (), apiExport )
246263 if tc .wantError {
247264 require .Error (t , err , "expected an error" )
@@ -292,6 +309,8 @@ func TestReconcile(t *testing.T) {
292309 if tc .wantIdentityValid {
293310 requireConditionMatches (t , apiExport , conditions .TrueCondition (apisv1alpha2 .APIExportIdentityValid ))
294311 }
312+
313+ require .Equal (t , tc .wantCreateAPIExportEndpointSlice , createEndpointSliceCalled , "expected createEndpointSliceCalled to be %v" , tc .wantCreateAPIExportEndpointSlice )
295314 })
296315 }
297316}
0 commit comments