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,27 +1,20 @@
/*
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 daemonset
import (
"context"
"strings"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/informers"
"kubesphere.io/kubesphere/pkg/api"
"kubesphere.io/kubesphere/pkg/apiserver/query"
@@ -35,34 +28,32 @@ const (
)
type daemonSetGetter struct {
sharedInformers informers.SharedInformerFactory
cache runtimeclient.Reader
}
func New(sharedInformers informers.SharedInformerFactory) v1alpha3.Interface {
return &daemonSetGetter{sharedInformers: sharedInformers}
func New(cache runtimeclient.Reader) v1alpha3.Interface {
return &daemonSetGetter{cache: cache}
}
func (d *daemonSetGetter) Get(namespace, name string) (runtime.Object, error) {
return d.sharedInformers.Apps().V1().DaemonSets().Lister().DaemonSets(namespace).Get(name)
daemonSet := &appsv1.DaemonSet{}
return daemonSet, d.cache.Get(context.Background(), types.NamespacedName{Namespace: namespace, Name: name}, daemonSet)
}
func (d *daemonSetGetter) List(namespace string, query *query.Query) (*api.ListResult, error) {
// first retrieves all daemonSets within given namespace
daemonSets, err := d.sharedInformers.Apps().V1().DaemonSets().Lister().DaemonSets(namespace).List(query.Selector())
if err != nil {
daemonSets := &appsv1.DaemonSetList{}
if err := d.cache.List(context.Background(), daemonSets, client.InNamespace(namespace),
client.MatchingLabelsSelector{Selector: query.Selector()}); err != nil {
return nil, err
}
var result []runtime.Object
for _, daemonSet := range daemonSets {
result = append(result, daemonSet)
for _, item := range daemonSets.Items {
result = append(result, item.DeepCopy())
}
return v1alpha3.DefaultList(result, query, d.compare, d.filter), nil
}
func (d *daemonSetGetter) compare(left runtime.Object, right runtime.Object, field query.Field) bool {
leftDaemonSet, ok := left.(*appsv1.DaemonSet)
if !ok {
return false
@@ -83,13 +74,13 @@ func (d *daemonSetGetter) filter(object runtime.Object, filter query.Filter) boo
}
switch filter.Field {
case query.FieldStatus:
return strings.Compare(daemonsetStatus(&daemonSet.Status), string(filter.Value)) == 0
return strings.Compare(daemonSetStatus(&daemonSet.Status), string(filter.Value)) == 0
default:
return v1alpha3.DefaultObjectMetaFilter(daemonSet.ObjectMeta, filter)
}
}
func daemonsetStatus(status *appsv1.DaemonSetStatus) string {
func daemonSetStatus(status *appsv1.DaemonSetStatus) string {
if status.DesiredNumberScheduled == 0 && status.NumberReady == 0 {
return statusStopped
} else if status.DesiredNumberScheduled == status.NumberReady {

View File

@@ -1,18 +1,11 @@
//go:build exclude
/*
Copyright 2019 The KubeSphere Authors.
* Please refer to the LICENSE file in the root directory of the project.
* https://github.com/kubesphere/kubesphere/blob/master/LICENSE
*/
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.
*/
// TODO refactor with fake controller runtime client
package daemonset