8000 Add an integration test to verify root path cleanup · kubernetes/kubernetes@cfa7932 · GitHub
[go: up one dir, main page]

Skip to content

Commit cfa7932

Browse files
committed
Add an integration test to verify root path cleanup
1 parent c769c2d commit cfa7932

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

test/integration/apiserver/discovery/discovery_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"k8s.io/apimachinery/pkg/runtime/schema"
3838
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
3939
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
40+
"k8s.io/apimachinery/pkg/util/sets"
4041
discoveryendpoint "k8s.io/apiserver/pkg/endpoints/discovery/aggregated"
4142
genericfeatures "k8s.io/apiserver/pkg/features"
4243
utilfeature "k8s.io/apiserver/pkg/util/feature"
@@ -241,21 +242,27 @@ func TestAggregatedAPIServiceDiscovery(t *testing.T) {
241242

242243
// For each groupversion served by our resourcemanager, create an APIService
243244
// object connected to our fake APIServer
245+
var groupVersions []metav1.GroupVersion
244246
for _, versionInfo := range basicTestGroup.Versions {
245247
groupVersion := metav1.GroupVersion{
246248
Group: basicTestGroup.Name,
247249
Version: versionInfo.Version,
248250
}
249251

250252
require.NoError(t, registerAPIService(ctx, client, groupVersion, service))
251-
defer func() {
252-
require.NoError(t, unregisterAPIService(ctx, client, groupVersion))
253-
}()
253+
groupVersions = append(groupVersions, groupVersion)
254254
}
255255

256256
// Keep repeatedly fetching document from aggregator.
257257
// Check to see if it contains our service within a reasonable amount of time
258258
require.NoError(t, WaitForGroups(ctx, client, basicTestGroupWithFixup))
259+
require.NoError(t, WaitForRootPaths(t, ctx, client, sets.NewString("/apis/"+basicTestGroup.Name), nil))
260+
261+
// Unregister and ensure the group gets dropped from root paths
262+
for _, groupVersion := range groupVersions {
263+
require.NoError(t, unregisterAPIService(ctx, client, groupVersion))
264+
}
265+
require.NoError(t, WaitForRootPaths(t, ctx, client, nil, sets.NewString("/apis/"+basicTestGroup.Name)))
259266
}
260267

261268
func runTestCases(t *testing.T, cases []testCase) {

test/integration/apiserver/discovery/framework.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ import (
2222
"fmt"
2323
"reflect"
2424
"strings"
25+
"testing"
2526
"time"
2627

2728
apiextensions "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
2829
"k8s.io/apimachinery/pkg/api/errors"
2930
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3031
"k8s.io/apimachinery/pkg/runtime"
3132
"k8s.io/apimachinery/pkg/runtime/schema"
33+
"k8s.io/apimachinery/pkg/util/sets"
3234
"k8s.io/apimachinery/pkg/util/wait"
3335
"k8s.io/client-go/dynamic"
3436
"k8s.io/client-go/kubernetes"
@@ -573,6 +575,29 @@ func WaitForGroupsAbsent(ctx context.Context, client testClient, groups ...strin
573575

574576
}
575577

578+
func WaitForRootPaths(t *testing.T, ctx context.Context, client testClient, requirePaths, forbidPaths sets.String) error {
579+
return wait.PollWithContext(ctx, 250*time.Millisecond, maxTimeout, func(ctx context.Context) (done bool, err error) {
580+
statusContent, err := client.Discovery().RESTClient().Get().AbsPath("/").SetHeader("Accept", "application/json").DoRaw(ctx)
581+
if err != nil {
582+
return false, err
583+
}
584+
rootPaths := metav1.RootPaths{}
585+
if err := json.Unmarshal(statusContent, &rootPaths); err != nil {
586+
return false, err
587+
}
588+
paths := sets.NewString(rootPaths.Paths...)
589+
if missing := requirePaths.Difference(paths); len(missing) > 0 {
590+
t.Logf("missing required root paths %v", missing.List())
591+
return false, nil
592+
}
593+
if present := forbidPaths.Intersection(paths); len(present) > 0 {
594+
t.Logf("present forbidden root paths %v", present.List())
595+
return false, nil
596+
}
597+
return true, nil
598+
})
599+
}
600+
576601
func WaitForGroups(ctx context.Context, client testClient, groups ...apidiscoveryv2beta1.APIGroupDiscovery) error {
577602
return WaitForResultWithCondition(ctx, client, func(groupList apidiscoveryv2beta1.APIGroupDiscoveryList) bool {
578603
for _, searchGroup := range groups {

0 commit comments

Comments
 (0)
0