ResourceGetter v1beta1 (#5416)

* add resource getter & reader

Signed-off-by: Wenhao Zhou <wenhaozhou@yunify.com>

* add resource v1beta1 handler

* delete gvrToGvk map instead of using the dynamicRESTMapper for getting gvk, and rename the ResourceLister to ResourceGetter

* add unregisteredMiddleware filter

Signed-off-by: wenhaozhou <wenhaozhou@yunify.com>

* add secret contains benchmark & add fieldSelector to resourcev1beta1

Signed-off-by: Wenhao Zhou <wenhaozhou@yunify.com>

* delete crds models

Signed-off-by: wenhaozhou <wenhaozhou@yunify.com>

* delete parameterExtractor and instead of requestInfo

Signed-off-by: Wenhao Zhou <wenhaozhou@yunify.com>

* add benchmark test

* move fieldSelector to DefaultObjectMetaFilter

Signed-off-by: wenhaozhou <wenhaozhou@yunify.com>

* move fieldSelector to DefaultObjectMetaFilter

* change registeredGv type to set

Signed-off-by: wenhaozhou <wenhaozhou@yunify.com>

* update filter chains

Signed-off-by: wenhaozhou <wenhaozhou@yunify.com>

* fix fieldSelector cannot work

Signed-off-by: wenhaozhou <wenhaozhou@yunify.com>

* fix: list known type do not need served label

Signed-off-by: wenhaozhou <wenhaozhou@yunify.com>

---------

Signed-off-by: Wenhao Zhou <wenhaozhou@yunify.com>
Signed-off-by: wenhaozhou <wenhaozhou@yunify.com>
This commit is contained in:
Wenhao Zhou
2023-02-08 15:00:15 +08:00
committed by GitHub
parent 1c49fcd57e
commit 23df7b051b
14 changed files with 566 additions and 804 deletions

View File

@@ -0,0 +1,119 @@
package secret
import (
"testing"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/rand"
"kubesphere.io/kubesphere/pkg/apiserver/query"
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha3"
)
var testSecret = &v1.Secret{
TypeMeta: metav1.TypeMeta{
Kind: "Secret",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "prometheus-k8s",
Namespace: "kube-system",
ResourceVersion: "1234567",
Labels: map[string]string{
"modifiedAt": "1670227209",
"name": "snapshot-controller",
"owner": "helm",
"status": "superseded",
"version": "2",
},
},
Data: map[string][]byte{
"testdata": []byte("thisisatestsecret"),
},
Type: "helm.sh/release.v1",
}
func BenchmarkContains(b *testing.B) {
for i := 0; i < b.N; i++ {
if contains(testSecret, "metadata.labels.status!=superseded") {
b.Error("test failed")
}
}
}
func BenchmarkDefaultListWith1000(b *testing.B) {
s := &secretSearcher{}
q := query.New()
q.Filters[query.ParameterFieldSelector] = "metadata.resourceVersion=1234567"
expectedListCount := rand.Intn(20)
list := prepareList(testSecret, 1000, expectedListCount)
for i := 0; i < b.N; i++ {
list := v1alpha3.DefaultList(list, q, s.compare, s.filter)
if list.TotalItems != expectedListCount {
b.Error("test failed")
}
}
}
func BenchmarkDefaultListWith5000(b *testing.B) {
s := &secretSearcher{}
q := query.New()
q.Filters[query.ParameterFieldSelector] = "metadata.resourceVersion=1234567"
expectedListCount := rand.Intn(20)
list := prepareList(testSecret, 5000, expectedListCount)
for i := 0; i < b.N; i++ {
list := v1alpha3.DefaultList(list, q, s.compare, s.filter)
if list.TotalItems != expectedListCount {
b.Error("test failed")
}
}
}
func BenchmarkDefaultListWith10000(b *testing.B) {
s := &secretSearcher{}
q := query.New()
q.Filters[query.ParameterFieldSelector] = "metadata.resourceVersion=1234567"
expectedListCount := rand.Intn(20)
list := prepareList(testSecret, 100000, expectedListCount)
for i := 0; i < b.N; i++ {
list := v1alpha3.DefaultList(list, q, s.compare, s.filter)
if list.TotalItems != expectedListCount {
b.Error("test failed")
}
}
}
func BenchmarkDefaultListWith50000(b *testing.B) {
s := &secretSearcher{}
q := query.New()
q.Filters[query.ParameterFieldSelector] = "metadata.resourceVersion=1234567"
expectedListCount := rand.Intn(20)
for i := 0; i < b.N; i++ {
list := v1alpha3.DefaultList(prepareList(testSecret, 50000, expectedListCount), q, s.compare, s.filter)
if list.TotalItems != expectedListCount {
b.Error("test failed")
}
}
}
func prepareList(testSecret *v1.Secret, listLen, expected int) []runtime.Object {
secretList := make([]runtime.Object, listLen)
for i := 0; i < listLen; i++ {
secret := testSecret.DeepCopy()
secret.Name = rand.String(20)
secret.ObjectMeta.ResourceVersion = rand.String(10)
secretList[i] = secret
}
for i := 0; i < expected; i++ {
secretList[rand.Intn(listLen-1)] = testSecret
}
return secretList
}