feat: kubesphere 4.0 (#6115)

* feat: kubesphere 4.0

Signed-off-by: ci-bot <ci-bot@kubesphere.io>

* feat: kubesphere 4.0

Signed-off-by: ci-bot <ci-bot@kubesphere.io>

---------

Signed-off-by: ci-bot <ci-bot@kubesphere.io>
Co-authored-by: ks-ci-bot <ks-ci-bot@example.com>
Co-authored-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
KubeSphere CI Bot
2024-09-06 11:05:52 +08:00
committed by GitHub
parent b5015ec7b9
commit 447a51f08b
8557 changed files with 546695 additions and 1146174 deletions

View File

@@ -1,26 +1,19 @@
/*
Copyright 2019 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
* Please refer to the LICENSE file in the root directory of the project.
* https://github.com/kubesphere/kubesphere/blob/master/LICENSE
*/
package customresourcedefinition
import (
"context"
"strings"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apiextensionsinformers "k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions"
"k8s.io/apimachinery/pkg/runtime"
"kubesphere.io/kubesphere/pkg/api"
@@ -29,30 +22,28 @@ import (
)
type crdGetter struct {
informers apiextensionsinformers.SharedInformerFactory
cache runtimeclient.Reader
}
func New(informers apiextensionsinformers.SharedInformerFactory) v1alpha3.Interface {
return &crdGetter{
informers: informers,
}
func New(cache runtimeclient.Reader) v1alpha3.Interface {
return &crdGetter{cache: cache}
}
func (c crdGetter) Get(_, name string) (runtime.Object, error) {
return c.informers.Apiextensions().V1().CustomResourceDefinitions().Lister().Get(name)
crd := &v1.CustomResourceDefinition{}
return crd, c.cache.Get(context.Background(), types.NamespacedName{Name: name}, crd)
}
func (c crdGetter) List(_ string, query *query.Query) (*api.ListResult, error) {
crds, err := c.informers.Apiextensions().V1().CustomResourceDefinitions().Lister().List(query.Selector())
if err != nil {
crds := &v1.CustomResourceDefinitionList{}
if err := c.cache.List(context.Background(), crds,
client.MatchingLabelsSelector{Selector: query.Selector()}); err != nil {
return nil, err
}
var result []runtime.Object
for _, crd := range crds {
result = append(result, crd)
for _, item := range crds.Items {
result = append(result, item.DeepCopy())
}
return v1alpha3.DefaultList(result, query, c.compare, c.filter), nil
}

View File

@@ -1,115 +0,0 @@
/*
Copyright 2019 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package customresourcedefinition
import (
"testing"
"github.com/google/go-cmp/cmp"
v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
fakeapiextensions "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/fake"
apiextensionsinformers "k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"kubesphere.io/kubesphere/pkg/api"
"kubesphere.io/kubesphere/pkg/apiserver/query"
)
var crds = []*v1.CustomResourceDefinition{
{
ObjectMeta: metav1.ObjectMeta{
Name: "clusters.cluster.kubesphere.io",
Labels: map[string]string{
"controller-tools.k8s.io": "1.0",
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "workspaces.tenant.kubesphere.io",
Labels: map[string]string{
"controller-tools.k8s.io": "1.0",
},
},
},
}
func crdsToRuntimeObjects(crds ...*v1.CustomResourceDefinition) []runtime.Object {
items := make([]runtime.Object, 0)
for _, crd := range crds {
items = append(items, crd)
}
return items
}
func crdsToInterface(crds ...*v1.CustomResourceDefinition) []interface{} {
items := make([]interface{}, 0)
for _, crd := range crds {
items = append(items, crd)
}
return items
}
func TestCrdGetterList(t *testing.T) {
var testCases = []struct {
description string
query *query.Query
expected *api.ListResult
}{
{
description: "Test normal case",
query: &query.Query{
Filters: map[query.Field]query.Value{
query.FieldName: "clusters.cluster.kubesphere.io",
},
},
expected: &api.ListResult{
TotalItems: 1,
Items: crdsToInterface(crds[0]),
},
},
}
client := fakeapiextensions.NewSimpleClientset(crdsToRuntimeObjects(crds...)...)
informers := apiextensionsinformers.NewSharedInformerFactory(client, 0)
for _, crd := range crds {
informers.Apiextensions().V1().CustomResourceDefinitions().Informer().GetIndexer().Add(crd)
}
for _, testCase := range testCases {
crdGetter := New(informers)
t.Run(testCase.description, func(t *testing.T) {
result, err := crdGetter.List("", testCase.query)
if err != nil {
t.Error(err)
}
if diff := cmp.Diff(result, testCase.expected); len(diff) != 0 {
t.Errorf("%T, got+ expected-, %s", testCase.expected, diff)
}
})
}
}