From 60d3d54b9083af4d7650785525cc9a411e8a13f9 Mon Sep 17 00:00:00 2001 From: GaoXiaodong <13814823514@163.com> Date: Fri, 25 Feb 2022 16:50:29 +0800 Subject: [PATCH] fix(platform): rm get cc form labelselector (#1777) Co-authored-by: xdonggao --- pkg/application/util/helmclient.go | 11 +---------- pkg/platform/util/addon/client.go | 12 +---------- pkg/platform/util/credential/credential.go | 23 ++-------------------- 3 files changed, 4 insertions(+), 42 deletions(-) diff --git a/pkg/application/util/helmclient.go b/pkg/application/util/helmclient.go index caf549ac7..3b98a0793 100644 --- a/pkg/application/util/helmclient.go +++ b/pkg/application/util/helmclient.go @@ -24,7 +24,6 @@ import ( "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/fields" platformversionedclient "tkestack.io/tke/api/client/clientset/versioned/typed/platform/v1" platformv1 "tkestack.io/tke/api/platform/v1" helmaction "tkestack.io/tke/pkg/application/helm/action" @@ -50,15 +49,7 @@ func NewHelmClient(ctx context.Context, return nil, fmt.Errorf("get cluster's credential error: %w", err) } } else { - fieldSelector := fields.OneTermEqualSelector("clusterName", clusterID).String() - list, err := platformClient.ClusterCredentials().List(ctx, metav1.ListOptions{FieldSelector: fieldSelector}) - if err != nil { - return nil, fmt.Errorf("get cluster's credential error: %w", err) - } - if len(list.Items) == 0 { - return nil, fmt.Errorf("get cluster's credential error, no cluster credential") - } - credential = &list.Items[0] + return nil, fmt.Errorf("get cluster's credential error, no cluster credential") } restConfig := credential.RESTConfig(cluster) restClientGetter := &helmconfig.RESTClientGetter{RestConfig: restConfig} diff --git a/pkg/platform/util/addon/client.go b/pkg/platform/util/addon/client.go index 4f05cc64c..bad3fdc39 100644 --- a/pkg/platform/util/addon/client.go +++ b/pkg/platform/util/addon/client.go @@ -28,7 +28,6 @@ import ( apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/fields" "k8s.io/client-go/kubernetes" kubeaggregatorclientset "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset" @@ -156,16 +155,7 @@ func GetClusterCredentialV1(ctx context.Context, client platformversionedclient. return nil, err } } else { - clusterName := cluster.Name - fieldSelector := fields.OneTermEqualSelector("clusterName", clusterName).String() - clusterCredentials, err := client.ClusterCredentials().List(ctx, metav1.ListOptions{FieldSelector: fieldSelector}) - if err != nil { - return nil, err - } - if len(clusterCredentials.Items) == 0 { - return nil, errors.NewNotFound(platform.Resource("ClusterCredential"), clusterName) - } - credential = &clusterCredentials.Items[0] + return nil, errors.NewNotFound(platform.Resource("ClusterCredential"), cluster.Name) } return credential, nil diff --git a/pkg/platform/util/credential/credential.go b/pkg/platform/util/credential/credential.go index 91697f23f..e956ebfd0 100644 --- a/pkg/platform/util/credential/credential.go +++ b/pkg/platform/util/credential/credential.go @@ -23,7 +23,6 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/fields" platforminternalclient "tkestack.io/tke/api/client/clientset/internalversion/typed/platform/internalversion" platformversionedclient "tkestack.io/tke/api/client/clientset/versioned/typed/platform/v1" "tkestack.io/tke/api/platform" @@ -43,16 +42,7 @@ func GetClusterCredential(ctx context.Context, client platforminternalclient.Pla return nil, err } } else if client != nil { - clusterName := cluster.Name - fieldSelector := fields.OneTermEqualSelector("clusterName", clusterName).String() - clusterCredentials, err := client.ClusterCredentials().List(ctx, metav1.ListOptions{FieldSelector: fieldSelector}) - if err != nil && !apierrors.IsNotFound(err) { - return nil, err - } - if clusterCredentials == nil || clusterCredentials.Items == nil || len(clusterCredentials.Items) == 0 { - return nil, apierrors.NewNotFound(platform.Resource("ClusterCredential"), clusterName) - } - credential = &clusterCredentials.Items[0] + return nil, apierrors.NewNotFound(platform.Resource("ClusterCredential"), cluster.Name) } return credential, nil @@ -71,16 +61,7 @@ func GetClusterCredentialV1(ctx context.Context, client platformversionedclient. return nil, err } } else if client != nil { - clusterName := cluster.Name - fieldSelector := fields.OneTermEqualSelector("clusterName", clusterName).String() - clusterCredentials, err := client.ClusterCredentials().List(ctx, metav1.ListOptions{FieldSelector: fieldSelector}) - if err != nil { - return nil, err - } - if clusterCredentials == nil || clusterCredentials.Items == nil || len(clusterCredentials.Items) == 0 { - return nil, apierrors.NewNotFound(platform.Resource("ClusterCredential"), clusterName) - } - credential = &clusterCredentials.Items[0] + return nil, apierrors.NewNotFound(platform.Resource("ClusterCredential"), cluster.Name) } return credential, nil