Skip to content

Commit c134635

Browse files
committed
Add condition cleaning
1 parent 4a4809b commit c134635

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

pkg/reconciler/apis/apiexport/apiexport_controller_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131

3232
"github.com/kcp-dev/logicalcluster/v3"
3333

34+
kcpfeatures "github.com/kcp-dev/kcp/pkg/features"
3435
apisv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1"
3536
apisv1alpha2 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha2"
3637
corev1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1"
@@ -39,6 +40,9 @@ import (
3940
)
4041

4142
func TestReconcile(t *testing.T) {
43+
// Save original feature gate value
44+
originalFeatureGate := kcpfeatures.DefaultFeatureGate.Enabled(kcpfeatures.EnableDeprecatedAPIExportVirtualWorkspacesUrls)
45+
4246
tests := map[string]struct {
4347
secretRefSet bool
4448
secretExists bool
@@ -63,6 +67,7 @@ func TestReconcile(t *testing.T) {
6367
wantVerifyFailure bool
6468
wantIdentityValid bool
6569
wantCreateAPIExportEndpointSlice bool
70+
wantVirtualWorkspaceURLs bool
6671
}{
6772
"create secret when ref is nil and secret doesn't exist": {
6873
secretExists: false,
@@ -144,10 +149,32 @@ func TestReconcile(t *testing.T) {
144149
wantIdentityValid: true,
145150
skipEndpointSliceAnnotation: true,
146151
},
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+
},
147169
}
148170

149171
for name, tc := range tests {
150172
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+
151178
createSecretCalled := false
152179
createEndpointSliceCalled := false
153180

@@ -311,6 +338,15 @@ func TestReconcile(t *testing.T) {
311338
}
312339

313340
require.Equal(t, tc.wantCreateAPIExportEndpointSlice, createEndpointSliceCalled, "expected createEndpointSliceCalled to be %v", tc.wantCreateAPIExportEndpointSlice)
341+
342+
if tc.wantVirtualWorkspaceURLs {
343+
require.NotNil(t, apiExport.Status.VirtualWorkspaces, "expected virtual workspace URLs to be set")
344+
require.Len(t, apiExport.Status.VirtualWorkspaces, 2, "expected 2 virtual workspace URLs")
345+
require.True(t, conditions.IsTrue(apiExport, apisv1alpha2.APIExportVirtualWorkspaceURLsReady), "expected virtual workspace URLs to be ready")
346+
} else {
347+
require.Nil(t, apiExport.Status.VirtualWorkspaces, "expected virtual workspace URLs to be nil")
348+
require.False(t, conditions.Has(apiExport, apisv1alpha2.APIExportVirtualWorkspaceURLsReady), "expected virtual workspace URLs condition to not exist")
349+
}
314350
})
315351
}
316352
}

pkg/reconciler/apis/apiexport/apiexport_reconcile.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ func (c *controller) reconcile(ctx context.Context, apiExport *apisv1alpha2.APIE
134134
}
135135
}
136136

137-
// Ensure the APIExportEndpointSlice has a virtual workspace URL
138-
// TODO(mjudeikis): Remove this and move to batteries.
137+
// Ensure the APIExport has a virtual workspace URL
138+
// TODO(mjudeikis): Remove this once we remove feature gate.
139139
if kcpfeatures.DefaultFeatureGate.Enabled(kcpfeatures.EnableDeprecatedAPIExportVirtualWorkspacesUrls) {
140140
if err := c.updateVirtualWorkspaceURLs(ctx, apiExport); err != nil {
141141
conditions.MarkFalse(
@@ -147,6 +147,10 @@ func (c *controller) reconcile(ctx context.Context, apiExport *apisv1alpha2.APIE
147147
err,
148148
)
149149
}
150+
} else {
151+
// Remove the condition and status.virtualWorkspaces if the feature gate is disabled.
152+
conditions.Delete(apiExport, apisv1alpha2.APIExportVirtualWorkspaceURLsReady)
153+
apiExport.Status.VirtualWorkspaces = nil
150154
}
151155

152156
return nil

0 commit comments

Comments
 (0)