Skip to content

Commit

Permalink
fix(platform): rm get cc form labelselector (#1777)
Browse files Browse the repository at this point in the history
Co-authored-by: xdonggao <xdonggao@tencent.com>
  • Loading branch information
GaoXiaodong and xdonggao authored Feb 25, 2022
1 parent a77aefd commit 60d3d54
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 42 deletions.
11 changes: 1 addition & 10 deletions pkg/application/util/helmclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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}
Expand Down
12 changes: 1 addition & 11 deletions pkg/platform/util/addon/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
23 changes: 2 additions & 21 deletions pkg/platform/util/credential/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 60d3d54

Please sign in to comment.