8000 Merge pull request #122129 from liggitt/root-conformance · kubernetes/kubernetes@55f2bc1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 55f2bc1

Browse files
authored
Merge pull request #122129 from liggitt/root-conformance
Remove conformance test calls to `/`
2 parents 22cb314 + 233949e commit 55f2bc1

File tree

3 files changed

+35
-22
lines changed

3 files changed

+35
-22
lines changed

test/e2e/apimachinery/aggregator.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import (
5252
admissionapi "k8s.io/pod-security-admission/api"
5353
samplev1alpha1 "k8s.io/sample-apiserver/pkg/apis/wardle/v1alpha1"
5454
"k8s.io/utils/pointer"
55-
"k8s.io/utils/strings/slices"
5655

5756
"github.com/onsi/ginkgo/v2"
5857
"github.com/onsi/gomega"
@@ -737,24 +736,6 @@ func TestSampleAPIServer(ctx context.Context, f *framework.Framework, aggrclient
737736
framework.ExpectNoError(err, "failed to count the required APIServices")
738737
framework.Logf("APIService %s has been deleted.", apiServiceName)
739738

740-
ginkgo.By("Confirm that the group path of " + apiServiceName + " was removed from root paths")
741-
groupPath := "/apis/" + apiServiceGroupName
742-
err = wait.PollUntilContextTimeout(ctx, apiServiceRetryPeriod, apiServiceRetryTimeout, true, func(ctx context.Context) (done bool, err error) {
743-
rootPaths := metav1.RootPaths{}
744-
statusContent, err = restClient.Get().
745-
AbsPath("/").
746-
SetHeader("Accept", "application/json").DoRaw(ctx)
747-
if err != nil {
748-
return false, err
749-
}
750-
err = json.Unmarshal(statusContent, &rootPaths)
751-
if err != nil {
752-
return false, err
753-
}
754-
return !slices.Contains(rootPaths.Paths, groupPath), nil
755-
})
756-
framework.ExpectNoError(err, "Expected to not find %s from root paths", groupPath)
757-
758739
cleanupSampleAPIServer(ctx, client, aggrclient, n, apiServiceName)
759740
}
760741

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.New("/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.New("/apis/"+basicTestGroup.Name)))
259266
}
260267

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

test/integration/apiserver/discovery/framework.go

8000
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 < 6D40 span class=pl-c1>*testing.T, ctx context.Context, client testClient, requirePaths, forbidPaths sets.Set[string]) error {
579+
return wait.PollUntilContextTimeout(ctx, 250*time.Millisecond, maxTimeout, true, 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.New(rootPaths.Paths...)
589+
if missing := requirePaths.Difference(paths); len(missing) > 0 {
590+
t.Logf("missing required root paths %v", sets.List(missing))
591+
return false, nil
592+
}
593+
if present := forbidPaths.Intersection(paths); len(present) > 0 {
594+
t.Logf("present forbidden root paths %v", sets.List(present))
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