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,68 +1,57 @@
/*
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 globalrolebinding
import (
"k8s.io/apimachinery/pkg/runtime"
"context"
iamv1alpha2 "kubesphere.io/api/iam/v1alpha2"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
iamv1beta1 "kubesphere.io/api/iam/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/client"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
"kubesphere.io/kubesphere/pkg/api"
"kubesphere.io/kubesphere/pkg/apiserver/query"
informers "kubesphere.io/kubesphere/pkg/client/informers/externalversions"
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha3"
)
type globalrolebindingsGetter struct {
sharedInformers informers.SharedInformerFactory
type globalRoleBindingsGetter struct {
cache runtimeclient.Reader
}
func New(sharedInformers informers.SharedInformerFactory) v1alpha3.Interface {
return &globalrolebindingsGetter{sharedInformers: sharedInformers}
func New(cache runtimeclient.Reader) v1alpha3.Interface {
return &globalRoleBindingsGetter{cache: cache}
}
func (d *globalrolebindingsGetter) Get(_, name string) (runtime.Object, error) {
return d.sharedInformers.Iam().V1alpha2().GlobalRoleBindings().Lister().Get(name)
func (d *globalRoleBindingsGetter) Get(_, name string) (runtime.Object, error) {
globalRoleBinding := &iamv1beta1.GlobalRoleBinding{}
return globalRoleBinding, d.cache.Get(context.Background(), types.NamespacedName{Name: name}, globalRoleBinding)
}
func (d *globalrolebindingsGetter) List(_ string, query *query.Query) (*api.ListResult, error) {
globalRoleBindings, err := d.sharedInformers.Iam().V1alpha2().GlobalRoleBindings().Lister().List(query.Selector())
if err != nil {
func (d *globalRoleBindingsGetter) List(_ string, query *query.Query) (*api.ListResult, error) {
globalRoleBindings := &iamv1beta1.GlobalRoleBindingList{}
if err := d.cache.List(context.Background(), globalRoleBindings,
client.MatchingLabelsSelector{Selector: query.Selector()}); err != nil {
return nil, err
}
var result []runtime.Object
for _, globalRoleBinding := range globalRoleBindings {
result = append(result, globalRoleBinding)
for _, item := range globalRoleBindings.Items {
result = append(result, item.DeepCopy())
}
return v1alpha3.DefaultList(result, query, d.compare, d.filter), nil
}
func (d *globalrolebindingsGetter) compare(left runtime.Object, right runtime.Object, field query.Field) bool {
leftRoleBinding, ok := left.(*iamv1alpha2.GlobalRoleBinding)
func (d *globalRoleBindingsGetter) compare(left runtime.Object, right runtime.Object, field query.Field) bool {
leftRoleBinding, ok := left.(*iamv1beta1.GlobalRoleBinding)
if !ok {
return false
}
rightRoleBinding, ok := right.(*iamv1alpha2.GlobalRoleBinding)
rightRoleBinding, ok := right.(*iamv1beta1.GlobalRoleBinding)
if !ok {
return false
}
@@ -70,8 +59,8 @@ func (d *globalrolebindingsGetter) compare(left runtime.Object, right runtime.Ob
return v1alpha3.DefaultObjectMetaCompare(leftRoleBinding.ObjectMeta, rightRoleBinding.ObjectMeta, field)
}
func (d *globalrolebindingsGetter) filter(object runtime.Object, filter query.Filter) bool {
role, ok := object.(*iamv1alpha2.GlobalRoleBinding)
func (d *globalRoleBindingsGetter) filter(object runtime.Object, filter query.Filter) bool {
role, ok := object.(*iamv1beta1.GlobalRoleBinding)
if !ok {
return false

View File

@@ -1,114 +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 globalrolebinding
import (
"testing"
"github.com/google/go-cmp/cmp"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
iamv1alpha2 "kubesphere.io/api/iam/v1alpha2"
"kubesphere.io/kubesphere/pkg/api"
"kubesphere.io/kubesphere/pkg/apiserver/query"
"kubesphere.io/kubesphere/pkg/client/clientset/versioned/fake"
informers "kubesphere.io/kubesphere/pkg/client/informers/externalversions"
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha3"
)
func TestListRoles(t *testing.T) {
tests := []struct {
description string
query *query.Query
expected *api.ListResult
expectedErr error
}{
{
"test name filter",
&query.Query{
Pagination: &query.Pagination{
Limit: 1,
Offset: 0,
},
SortBy: query.FieldName,
Ascending: false,
Filters: map[query.Field]query.Value{query.FieldName: query.Value("foo2")},
},
&api.ListResult{
Items: []interface{}{
foo2,
},
TotalItems: 1,
},
nil,
},
}
getter := prepare()
for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
got, err := getter.List("", test.query)
if test.expectedErr != nil && err != test.expectedErr {
t.Errorf("expected error, got nothing")
} else if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(got, test.expected); diff != "" {
t.Errorf("%T differ (-got, +want): %s", test.expected, diff)
}
})
}
}
var (
foo1 = &iamv1alpha2.GlobalRoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: "foo1",
Namespace: "bar",
},
}
foo2 = &iamv1alpha2.GlobalRoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: "foo2",
Namespace: "bar",
},
}
bar1 = &iamv1alpha2.GlobalRoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: "bar1",
Namespace: "bar",
},
}
globalRoleBindings = []interface{}{foo1, foo2, bar1}
)
func prepare() v1alpha3.Interface {
client := fake.NewSimpleClientset()
informer := informers.NewSharedInformerFactory(client, 0)
for _, globalRoleBinding := range globalRoleBindings {
informer.Iam().V1alpha2().GlobalRoleBindings().Informer().GetIndexer().Add(globalRoleBinding)
}
return New(informer)
}