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,106 +0,0 @@
/*
Copyright 2020 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 k8s
import (
snapshotclient "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned"
promresourcesclient "github.com/prometheus-operator/prometheus-operator/pkg/client/versioned"
istioclient "istio.io/client-go/pkg/clientset/versioned"
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/client-go/discovery"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
kubesphere "kubesphere.io/kubesphere/pkg/client/clientset/versioned"
)
type FakeClient struct {
// kubernetes client interface
K8sClient kubernetes.Interface
// discovery client
DiscoveryClient *discovery.DiscoveryClient
// generated clientset
KubeSphereClient kubesphere.Interface
IstioClient istioclient.Interface
SnapshotClient snapshotclient.Interface
ApiExtensionClient apiextensionsclient.Interface
prometheusClient promresourcesclient.Interface
MasterURL string
KubeConfig *rest.Config
}
func NewFakeClientSets(k8sClient kubernetes.Interface, discoveryClient *discovery.DiscoveryClient,
kubeSphereClient kubesphere.Interface,
istioClient istioclient.Interface, snapshotClient snapshotclient.Interface,
apiextensionsclient apiextensionsclient.Interface, prometheusClient promresourcesclient.Interface,
masterURL string, kubeConfig *rest.Config) Client {
return &FakeClient{
K8sClient: k8sClient,
DiscoveryClient: discoveryClient,
KubeSphereClient: kubeSphereClient,
IstioClient: istioClient,
SnapshotClient: snapshotClient,
ApiExtensionClient: apiextensionsclient,
prometheusClient: prometheusClient,
MasterURL: masterURL,
KubeConfig: kubeConfig,
}
}
func (n *FakeClient) Kubernetes() kubernetes.Interface {
return n.K8sClient
}
func (n *FakeClient) KubeSphere() kubesphere.Interface {
return n.KubeSphereClient
}
func (n *FakeClient) Istio() istioclient.Interface {
return n.IstioClient
}
func (n *FakeClient) Snapshot() snapshotclient.Interface {
return nil
}
func (n *FakeClient) ApiExtensions() apiextensionsclient.Interface {
return n.ApiExtensionClient
}
func (n *FakeClient) Discovery() discovery.DiscoveryInterface {
return n.DiscoveryClient
}
func (n *FakeClient) Prometheus() promresourcesclient.Interface {
return n.prometheusClient
}
func (n *FakeClient) Master() string {
return n.MasterURL
}
func (n *FakeClient) Config() *rest.Config {
return n.KubeConfig
}

View File

@@ -1,68 +1,27 @@
/*
Copyright 2020 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 k8s
import (
"strings"
snapshotclient "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned"
promresourcesclient "github.com/prometheus-operator/prometheus-operator/pkg/client/versioned"
istioclient "istio.io/client-go/pkg/clientset/versioned"
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
kubesphere "kubesphere.io/kubesphere/pkg/client/clientset/versioned"
)
type Client interface {
Kubernetes() kubernetes.Interface
KubeSphere() kubesphere.Interface
Istio() istioclient.Interface
Snapshot() snapshotclient.Interface
ApiExtensions() apiextensionsclient.Interface
Prometheus() promresourcesclient.Interface
kubernetes.Interface
Master() string
Config() *rest.Config
}
type kubernetesClient struct {
// kubernetes client interface
k8s kubernetes.Interface
// generated clientset
ks kubesphere.Interface
istio istioclient.Interface
snapshot snapshotclient.Interface
apiextensions apiextensionsclient.Interface
prometheus promresourcesclient.Interface
kubernetes.Interface
master string
config *rest.Config
}
// NewKubernetesClientOrDie creates KubernetesClient and panic if there is an error
func NewKubernetesClientOrDie(options *KubernetesOptions) Client {
func NewKubernetesClientOrDie(options *Options) Client {
config, err := clientcmd.BuildConfigFromFlags("", options.KubeConfig)
if err != nil {
panic(err)
@@ -72,14 +31,9 @@ func NewKubernetesClientOrDie(options *KubernetesOptions) Client {
config.Burst = options.Burst
k := &kubernetesClient{
k8s: kubernetes.NewForConfigOrDie(config),
ks: kubesphere.NewForConfigOrDie(config),
istio: istioclient.NewForConfigOrDie(config),
snapshot: snapshotclient.NewForConfigOrDie(config),
apiextensions: apiextensionsclient.NewForConfigOrDie(config),
prometheus: promresourcesclient.NewForConfigOrDie(config),
master: config.Host,
config: config,
Interface: kubernetes.NewForConfigOrDie(config),
master: config.Host,
config: config,
}
if options.Master != "" {
@@ -95,78 +49,24 @@ func NewKubernetesClientOrDie(options *KubernetesOptions) Client {
}
// NewKubernetesClient creates a KubernetesClient
func NewKubernetesClient(options *KubernetesOptions) (Client, error) {
config, err := clientcmd.BuildConfigFromFlags("", options.KubeConfig)
func NewKubernetesClient(options *Options) (Client, error) {
config, err := clientcmd.BuildConfigFromFlags(options.Master, options.KubeConfig)
if err != nil {
return nil, err
}
config.QPS = options.QPS
config.Burst = options.Burst
var k kubernetesClient
k.k8s, err = kubernetes.NewForConfig(config)
var client kubernetesClient
client.Interface, err = kubernetes.NewForConfig(config)
if err != nil {
return nil, err
}
k.ks, err = kubesphere.NewForConfig(config)
if err != nil {
return nil, err
}
k.istio, err = istioclient.NewForConfig(config)
if err != nil {
return nil, err
}
k.snapshot, err = snapshotclient.NewForConfig(config)
if err != nil {
return nil, err
}
k.apiextensions, err = apiextensionsclient.NewForConfig(config)
if err != nil {
return nil, err
}
k.prometheus, err = promresourcesclient.NewForConfig(config)
if err != nil {
return nil, err
}
k.master = options.Master
k.config = config
return &k, nil
client.master = options.Master
client.config = config
return &client, nil
}
func (k *kubernetesClient) Kubernetes() kubernetes.Interface {
return k.k8s
}
func (k *kubernetesClient) KubeSphere() kubesphere.Interface {
return k.ks
}
func (k *kubernetesClient) Istio() istioclient.Interface {
return k.istio
}
func (k *kubernetesClient) Snapshot() snapshotclient.Interface {
return k.snapshot
}
func (k *kubernetesClient) ApiExtensions() apiextensionsclient.Interface {
return k.apiextensions
}
func (k *kubernetesClient) Prometheus() promresourcesclient.Interface {
return k.prometheus
}
// master address used to generate kubeconfig for downloading
// Master address used to generate kubeconfig for downloading
func (k *kubernetesClient) Master() string {
return k.master
}

View File

@@ -1,68 +1,18 @@
/*
Copyright 2020 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 k8s
import (
snapshotclient "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned"
promresourcesclient "github.com/prometheus-operator/prometheus-operator/pkg/client/versioned"
istio "istio.io/client-go/pkg/clientset/versioned"
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/client-go/discovery"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
kubesphere "kubesphere.io/kubesphere/pkg/client/clientset/versioned"
)
type nullClient struct {
kubernetes.Interface
}
func NewNullClient() Client {
return &nullClient{}
}
func (n nullClient) Kubernetes() kubernetes.Interface {
return nil
}
func (n nullClient) KubeSphere() kubesphere.Interface {
return nil
}
func (n nullClient) Istio() istio.Interface {
return nil
}
func (n nullClient) Snapshot() snapshotclient.Interface {
return nil
}
func (n nullClient) ApiExtensions() apiextensionsclient.Interface {
return nil
}
func (n nullClient) Discovery() discovery.DiscoveryInterface {
return nil
}
func (n *nullClient) Prometheus() promresourcesclient.Interface {
return nil
}
func (n nullClient) Master() string {
return ""
}

View File

@@ -1,19 +1,3 @@
/*
Copyright 2020 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 k8s
import (
@@ -24,11 +8,9 @@ import (
"k8s.io/client-go/util/homedir"
"github.com/spf13/pflag"
"kubesphere.io/kubesphere/pkg/utils/reflectutils"
)
type KubernetesOptions struct {
type Options struct {
// kubeconfig path, if not specified, will use
// in cluster way to create clientset
KubeConfig string `json:"kubeconfig" yaml:"kubeconfig"`
@@ -48,8 +30,8 @@ type KubernetesOptions struct {
}
// NewKubernetesOptions returns a `zero` instance
func NewKubernetesOptions() (option *KubernetesOptions) {
option = &KubernetesOptions{
func NewKubernetesOptions() (option *Options) {
option = &Options{
QPS: 1e6,
Burst: 1e6,
}
@@ -70,8 +52,8 @@ func NewKubernetesOptions() (option *KubernetesOptions) {
return
}
func (k *KubernetesOptions) Validate() []error {
errors := []error{}
func (k *Options) Validate() []error {
var errors []error
if k.KubeConfig != "" {
if _, err := os.Stat(k.KubeConfig); err != nil {
@@ -81,11 +63,7 @@ func (k *KubernetesOptions) Validate() []error {
return errors
}
func (k *KubernetesOptions) ApplyTo(options *KubernetesOptions) {
reflectutils.Override(options, k)
}
func (k *KubernetesOptions) AddFlags(fs *pflag.FlagSet, c *KubernetesOptions) {
func (k *Options) AddFlags(fs *pflag.FlagSet, c *Options) {
fs.StringVar(&k.KubeConfig, "kubeconfig", c.KubeConfig, ""+
"Path for kubernetes kubeconfig file, if left blank, will use "+
"in cluster way.")