mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-12-02 06:13:54 +00:00
Unregister group path from apiserver when the group no longer exists
After a CRD or an APIService was deleted, the corresponding group was never unregistered. It caused a stale entry to remain in the root path and could potentially lead to memory leak as the groupDiscoveryHandler was never released and the handledGroups was never cleaned up. The commit implements the cleanup. It tracks each group's usage and unregister the a group when there is no version for this group. Signed-off-by: Quan Tian <qtian@vmware.com>
This commit is contained in:
@@ -52,6 +52,7 @@ import (
|
||||
admissionapi "k8s.io/pod-security-admission/api"
|
||||
samplev1alpha1 "k8s.io/sample-apiserver/pkg/apis/wardle/v1alpha1"
|
||||
"k8s.io/utils/pointer"
|
||||
"k8s.io/utils/strings/slices"
|
||||
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
"github.com/onsi/gomega"
|
||||
@@ -736,6 +737,24 @@ func TestSampleAPIServer(ctx context.Context, f *framework.Framework, aggrclient
|
||||
framework.ExpectNoError(err, "failed to count the required APIServices")
|
||||
framework.Logf("APIService %s has been deleted.", apiServiceName)
|
||||
|
||||
ginkgo.By("Confirm that the group path of " + apiServiceName + " was removed from root paths")
|
||||
groupPath := "/apis/" + apiServiceGroupName
|
||||
err = wait.PollUntilContextTimeout(ctx, apiServiceRetryPeriod, apiServiceRetryTimeout, true, func(ctx context.Context) (done bool, err error) {
|
||||
rootPaths := metav1.RootPaths{}
|
||||
statusContent, err = restClient.Get().
|
||||
AbsPath("/").
|
||||
SetHeader("Accept", "application/json").DoRaw(ctx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
err = json.Unmarshal(statusContent, &rootPaths)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return !slices.Contains(rootPaths.Paths, groupPath), nil
|
||||
})
|
||||
framework.ExpectNoError(err, "Expected to not find %s from root paths", groupPath)
|
||||
|
||||
cleanupSampleAPIServer(ctx, client, aggrclient, n, apiServiceName)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user