From 792f33d4715fd4f6bbbaf2c2a47ccd96ecab5ab5 Mon Sep 17 00:00:00 2001 From: Somefive Date: Wed, 12 Apr 2023 20:25:24 +0800 Subject: [PATCH] Feat: migrate prism cluster (#5836) Signed-off-by: Somefive --- apis/types/multicluster.go | 3 --- go.mod | 3 +-- go.sum | 6 ++---- pkg/addon/addon.go | 4 ++-- pkg/cmd/completion.go | 5 ++--- pkg/multicluster/cluster_management.go | 13 ++++++------ pkg/multicluster/utils.go | 2 -- pkg/multicluster/virtual_cluster.go | 14 ++++++++----- pkg/multicluster/virtual_cluster_test.go | 25 ++++++++++++------------ pkg/policy/topology.go | 5 ++--- pkg/utils/common/common.go | 2 -- references/cli/auth.go | 8 +++----- references/cli/cluster.go | 9 ++++----- references/cli/top/model/cluster.go | 4 +--- 14 files changed, 45 insertions(+), 58 deletions(-) diff --git a/apis/types/multicluster.go b/apis/types/multicluster.go index 1b2b55090..de051b542 100644 --- a/apis/types/multicluster.go +++ b/apis/types/multicluster.go @@ -37,9 +37,6 @@ const ( ) var ( - // AnnotationClusterAlias the annotation key for cluster alias - AnnotationClusterAlias = config.MetaApiGroupName + "/cluster-alias" - // AnnotationClusterVersion the annotation key for cluster version AnnotationClusterVersion = config.MetaApiGroupName + "/cluster-version" ) diff --git a/go.mod b/go.mod index 4a17d33d6..48a258779 100644 --- a/go.mod +++ b/go.mod @@ -51,7 +51,6 @@ require ( github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174 github.com/imdario/mergo v0.3.13 github.com/kubevela/pkg v1.8.1-0.20230410075324-9f0ba3b09495 - github.com/kubevela/prism v1.7.0-alpha.1.0.20230403030519-b7e45f7f842e github.com/kubevela/workflow v0.5.1-0.20230410054920-9c36c21ea8fb github.com/kyokomi/emoji v2.2.4+incompatible github.com/mitchellh/hashstructure/v2 v2.0.2 @@ -113,7 +112,7 @@ require ( github.com/dave/jennifer v1.6.0 github.com/ettle/strcase v0.1.1 github.com/google/go-containerregistry v0.13.0 - github.com/oam-dev/cluster-gateway v1.9.0-alpha.1 + github.com/oam-dev/cluster-gateway v1.9.0-alpha.1.0.20230412030221-d9666385607f golang.org/x/tools v0.7.0 ) diff --git a/go.sum b/go.sum index 2b1c07473..179bfbd2f 100644 --- a/go.sum +++ b/go.sum @@ -954,8 +954,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kubevela/pkg v1.8.1-0.20230410075324-9f0ba3b09495 h1:maT6E7JSrZgv4T1grgTBL69px7oUldc+tHIPxJ5SD9Y= github.com/kubevela/pkg v1.8.1-0.20230410075324-9f0ba3b09495/go.mod h1:dGT23SGBw16frh5ReEYMFraxjppkX6jPCltBgTeLUhE= -github.com/kubevela/prism v1.7.0-alpha.1.0.20230403030519-b7e45f7f842e h1:hc3ctkLfQVERra9IKDoAgMK4iMCY3XpXEJ0TfP9FhSQ= -github.com/kubevela/prism v1.7.0-alpha.1.0.20230403030519-b7e45f7f842e/go.mod h1:bEPKTha7KhDhJAPXYBNAHTMRyqffDvf9UqWZV2BtQtI= github.com/kubevela/workflow v0.5.1-0.20230410054920-9c36c21ea8fb h1:5/J8Aleqi+rdllhfvRRP40W2kdakpyYmPYnMcvbsK3Q= github.com/kubevela/workflow v0.5.1-0.20230410054920-9c36c21ea8fb/go.mod h1:0GhIWFIPP+Zt31m4Aslx9mihoyNz3HrOvCV69ljMIBo= github.com/kylelemons/godebug v0.0.0-20160406211939-eadb3ce320cb/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= @@ -1131,8 +1129,8 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= -github.com/oam-dev/cluster-gateway v1.9.0-alpha.1 h1:1V9nm8XO4ZqJK6rkJ7c1kglQN8biQtrFiHaJnAtjjLE= -github.com/oam-dev/cluster-gateway v1.9.0-alpha.1/go.mod h1:g8ivuGBu1MwtvM0AKGc81TvsLvEsosoUXENhbBFJgtc= +github.com/oam-dev/cluster-gateway v1.9.0-alpha.1.0.20230412030221-d9666385607f h1:cAxFYiCtbeCwS/u6MopqDO3czrzLlgH8VS3c10nrUtw= +github.com/oam-dev/cluster-gateway v1.9.0-alpha.1.0.20230412030221-d9666385607f/go.mod h1:Yu4jc+Yu7xAi3aDXDPtPduEsV2ALo5SJutqI2uSGB9A= github.com/oam-dev/cluster-register v1.0.4-0.20220928064144-5f76a9d7ca8c h1:RE/33gzs9hoyegcTaUXDG/hayffJ197ljMUGNP6I/5A= github.com/oam-dev/cluster-register v1.0.4-0.20220928064144-5f76a9d7ca8c/go.mod h1:nKEUMfuEB8pHKsaSah9IA+UQzezrPYebBdRozyNtlZc= github.com/oam-dev/stern v1.13.2 h1:jlGgtJbKmIVhzkH44ft5plkgs8XEfvxbFrQdX60CQR4= diff --git a/pkg/addon/addon.go b/pkg/addon/addon.go index b3e2ed1db..c1cd474ce 100644 --- a/pkg/addon/addon.go +++ b/pkg/addon/addon.go @@ -34,7 +34,6 @@ import ( "github.com/Masterminds/semver/v3" "github.com/google/go-github/v32/github" "github.com/imdario/mergo" - prismclusterv1alpha1 "github.com/kubevela/prism/pkg/apis/cluster/v1alpha1" "github.com/kubevela/workflow/pkg/cue/model/value" "github.com/pkg/errors" "github.com/xanzy/go-gitlab" @@ -64,6 +63,7 @@ import ( "github.com/oam-dev/kubevela/pkg/config" "github.com/oam-dev/kubevela/pkg/cue/script" "github.com/oam-dev/kubevela/pkg/definition" + "github.com/oam-dev/kubevela/pkg/multicluster" "github.com/oam-dev/kubevela/pkg/oam" "github.com/oam-dev/kubevela/pkg/oam/util" "github.com/oam-dev/kubevela/pkg/utils" @@ -640,7 +640,7 @@ func checkDeployClusters(ctx context.Context, k8sClient client.Client, args map[ return nil, nil } - clusters, err := prismclusterv1alpha1.NewClusterClient(k8sClient).List(ctx) + clusters, err := multicluster.NewClusterClient(k8sClient).List(ctx) if err != nil { return nil, errors.Wrap(err, "fail to get registered cluster") } diff --git a/pkg/cmd/completion.go b/pkg/cmd/completion.go index d0bb0cea2..b1d687d01 100644 --- a/pkg/cmd/completion.go +++ b/pkg/cmd/completion.go @@ -26,9 +26,8 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/controller-runtime/pkg/client" - prismclusterv1alpha1 "github.com/kubevela/prism/pkg/apis/cluster/v1alpha1" - "github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1" + "github.com/oam-dev/kubevela/pkg/multicluster" "github.com/oam-dev/kubevela/pkg/oam" ) @@ -84,7 +83,7 @@ func GetApplicationsForCompletion(ctx context.Context, f Factory, namespace stri // GetClustersForCompletion auto-complete the cluster func GetClustersForCompletion(ctx context.Context, f Factory, toComplete string) ([]string, cobra.ShellCompDirective) { - clusters, err := prismclusterv1alpha1.NewClusterClient(f.Client()).List(ctx) + clusters, err := multicluster.NewClusterClient(f.Client()).List(ctx) if err != nil { return nil, cobra.ShellCompDirectiveError } diff --git a/pkg/multicluster/cluster_management.go b/pkg/multicluster/cluster_management.go index 2080c44af..8db139aea 100644 --- a/pkg/multicluster/cluster_management.go +++ b/pkg/multicluster/cluster_management.go @@ -25,7 +25,6 @@ import ( "github.com/briandowns/spinner" "github.com/kubevela/pkg/util/k8s" - prismclusterv1alpha1 "github.com/kubevela/prism/pkg/apis/cluster/v1alpha1" clusterv1alpha1 "github.com/oam-dev/cluster-gateway/pkg/apis/cluster/v1alpha1" clustercommon "github.com/oam-dev/cluster-gateway/pkg/common" "github.com/oam-dev/cluster-register/pkg/hub" @@ -154,7 +153,7 @@ func (clusterConfig *KubeClusterConfig) createOrUpdateClusterSecret(ctx context. // RegisterByVelaSecret create cluster secrets for KubeVela to use func (clusterConfig *KubeClusterConfig) RegisterByVelaSecret(ctx context.Context, cli client.Client) error { - cluster, err := prismclusterv1alpha1.NewClusterClient(cli).Get(ctx, clusterConfig.ClusterName) + cluster, err := NewClusterClient(cli).Get(ctx, clusterConfig.ClusterName) if client.IgnoreNotFound(err) != nil { return err } @@ -165,7 +164,7 @@ func (clusterConfig *KubeClusterConfig) RegisterByVelaSecret(ctx context.Context if !clusterConfig.ClusterAlreadyExistCallback(clusterConfig.ClusterName) { return nil } - if cluster.Spec.CredentialType == prismclusterv1alpha1.CredentialTypeInternal || cluster.Spec.CredentialType == prismclusterv1alpha1.CredentialTypeOCMManagedCluster { + if cluster.Spec.CredentialType == clusterv1alpha1.CredentialTypeInternal || cluster.Spec.CredentialType == clusterv1alpha1.CredentialTypeOCMManagedCluster { return fmt.Errorf("cannot override %s typed cluster", cluster.Spec.CredentialType) } } @@ -478,7 +477,7 @@ func DetachCluster(ctx context.Context, cli client.Client, clusterName string, o if clusterName == ClusterLocalName { return ErrReservedLocalClusterName } - vc, err := prismclusterv1alpha1.NewClusterClient(cli).Get(ctx, clusterName) + vc, err := NewClusterClient(cli).Get(ctx, clusterName) if err != nil { return err } @@ -492,7 +491,7 @@ func DetachCluster(ctx context.Context, cli client.Client, clusterName string, o if err := cli.Delete(ctx, clusterSecret); err != nil { return errors.Wrapf(err, "failed to detach cluster %s", clusterName) } - case prismclusterv1alpha1.CredentialTypeOCMManagedCluster: + case clusterv1alpha1.CredentialTypeOCMManagedCluster: if args.managedClusterKubeConfigPath == "" { return errors.New("kubeconfig-path must be set to detach ocm managed cluster") } @@ -515,6 +514,8 @@ func DetachCluster(ctx context.Context, cli client.Client, clusterName string, o return err } } + case clusterv1alpha1.CredentialTypeInternal: + return fmt.Errorf("cannot detach internal cluster `local`") } return nil } @@ -561,7 +562,7 @@ func AliasCluster(ctx context.Context, cli client.Client, clusterName string, al // ensureClusterNotExists will check the cluster is not existed in control plane func ensureClusterNotExists(ctx context.Context, c client.Client, clusterName string) error { - _, err := prismclusterv1alpha1.NewClusterClient(c).Get(ctx, clusterName) + _, err := NewClusterClient(c).Get(ctx, clusterName) if err != nil { return client.IgnoreNotFound(err) } diff --git a/pkg/multicluster/utils.go b/pkg/multicluster/utils.go index 2addaee40..072e0db52 100644 --- a/pkg/multicluster/utils.go +++ b/pkg/multicluster/utils.go @@ -24,7 +24,6 @@ import ( "time" pkgmulticluster "github.com/kubevela/pkg/multicluster" - prismclusterv1alpha1 "github.com/kubevela/prism/pkg/apis/cluster/v1alpha1" "github.com/oam-dev/cluster-gateway/pkg/apis/cluster/v1alpha1" clustercommon "github.com/oam-dev/cluster-gateway/pkg/common" errors2 "github.com/pkg/errors" @@ -137,7 +136,6 @@ func Initialize(restConfig *rest.Config, autoUpgrade bool) (client.Client, error return nil, ErrDetectClusterGateway } ClusterGatewaySecretNamespace = svc.Namespace - prismclusterv1alpha1.StorageNamespace = ClusterGatewaySecretNamespace if autoUpgrade { if err = UpgradeExistingClusterSecret(context.Background(), c); err != nil { // this error do not affect the running of current version diff --git a/pkg/multicluster/virtual_cluster.go b/pkg/multicluster/virtual_cluster.go index 68bda0c8f..b18e8cd4a 100644 --- a/pkg/multicluster/virtual_cluster.go +++ b/pkg/multicluster/virtual_cluster.go @@ -40,7 +40,6 @@ import ( clusterv1 "open-cluster-management.io/api/cluster/v1" "sigs.k8s.io/controller-runtime/pkg/client" - prismclusterv1alpha1 "github.com/kubevela/prism/pkg/apis/cluster/v1alpha1" "github.com/oam-dev/cluster-gateway/pkg/apis/cluster/v1alpha1" clustercommon "github.com/oam-dev/cluster-gateway/pkg/common" @@ -59,7 +58,7 @@ func InitClusterInfo(cfg *rest.Config) error { return err } if !utilfeature.DefaultMutableFeatureGate.Enabled(features.DisableBootstrapClusterInfo) { - clusters, err := prismclusterv1alpha1.NewClusterClient(singleton.KubeClient.Get()).List(ctx) + clusters, err := NewClusterClient(singleton.KubeClient.Get()).List(ctx) if err != nil { return errors.Wrap(err, "fail to get registered clusters") } @@ -96,7 +95,7 @@ func (vc *VirtualCluster) FullName() string { func getClusterAlias(o client.Object) string { if annots := o.GetAnnotations(); annots != nil { - return annots[types.AnnotationClusterAlias] + return annots[v1alpha1.AnnotationClusterAlias] } return "" } @@ -106,7 +105,7 @@ func setClusterAlias(o client.Object, alias string) { if annots == nil { annots = map[string]string{} } - annots[types.AnnotationClusterAlias] = alias + annots[v1alpha1.AnnotationClusterAlias] = alias o.SetAnnotations(annots) } @@ -293,7 +292,7 @@ func (cm clusterAliasMapper) GetClusterName(cluster string) string { // NewClusterNameMapper load all clusters and return the mapper of their names func NewClusterNameMapper(ctx context.Context, c client.Client) (ClusterNameMapper, error) { cm := clusterAliasMapper(make(map[string]string)) - clusters := &prismclusterv1alpha1.ClusterList{} + clusters := &v1alpha1.VirtualClusterList{} if err := c.List(ctx, clusters); err == nil { for _, cluster := range clusters.Items { cm[cluster.Name] = cluster.Spec.Alias @@ -411,3 +410,8 @@ func RequestRawK8sAPIForCluster(ctx context.Context, path, clusterName string, c } return versioned.NewForConfigOrDie(cfg).ClusterV1alpha1().ClusterGateways().RESTClient(clusterName).Get().AbsPath(path).DoRaw(ctx) } + +// NewClusterClient create virtual cluster client +func NewClusterClient(cli client.Client) v1alpha1.VirtualClusterClient { + return v1alpha1.NewVirtualClusterClient(cli, ClusterGatewaySecretNamespace, true) +} diff --git a/pkg/multicluster/virtual_cluster_test.go b/pkg/multicluster/virtual_cluster_test.go index 1d344d6bc..3c26335e0 100644 --- a/pkg/multicluster/virtual_cluster_test.go +++ b/pkg/multicluster/virtual_cluster_test.go @@ -29,7 +29,6 @@ import ( clusterv1 "open-cluster-management.io/api/cluster/v1" "sigs.k8s.io/controller-runtime/pkg/client" - prismclusterv1alpha1 "github.com/kubevela/prism/pkg/apis/cluster/v1alpha1" "github.com/oam-dev/cluster-gateway/pkg/apis/cluster/v1alpha1" clustercommon "github.com/oam-dev/cluster-gateway/pkg/common" @@ -53,7 +52,7 @@ var _ = Describe("Test Virtual Cluster", func() { clustercommon.LabelKeyClusterEndpointType: string(v1alpha1.ClusterEndpointTypeConst), "key": "value", }, - Annotations: map[string]string{types.AnnotationClusterAlias: "test-alias"}, + Annotations: map[string]string{v1alpha1.AnnotationClusterAlias: "test-alias"}, }, })).Should(Succeed()) Expect(k8sClient.Create(ctx, &v1.Secret{ @@ -98,7 +97,7 @@ var _ = Describe("Test Virtual Cluster", func() { Name: "ocm-cluster", Namespace: ClusterGatewaySecretNamespace, Labels: map[string]string{"key": "value"}, - Annotations: map[string]string{types.AnnotationClusterAlias: "ocm-alias"}, + Annotations: map[string]string{v1alpha1.AnnotationClusterAlias: "ocm-alias"}, }, Spec: clusterv1.ManagedClusterSpec{ ManagedClusterClientConfigs: []clusterv1.ClientConfig{{URL: "test-url"}}, @@ -125,7 +124,7 @@ var _ = Describe("Test Virtual Cluster", func() { Expect(err).Should(Succeed()) Expect(len(vcs)).Should(Equal(2)) - By("Test prism cluster list for clusterNameMapper") + By("Test virtual cluster list for clusterNameMapper") cli := fakeClient{Client: k8sClient} cnm, err := NewClusterNameMapper(ctx, cli) Expect(err).Should(Succeed()) @@ -135,14 +134,14 @@ var _ = Describe("Test Virtual Cluster", func() { _, err = NewClusterNameMapper(ctx, cli) Expect(err).Should(Satisfy(errors.IsBadRequest)) cli.returnBadRequest = false - cli.prismNotRegistered = true + cli.virtualClusterNotRegistered = true cnm, err = NewClusterNameMapper(ctx, cli) Expect(err).Should(Succeed()) Expect(cnm.GetClusterName("example")).Should(Equal("example")) Expect(cnm.GetClusterName("test-cluster")).Should(Equal("test-cluster (test-alias)")) Expect(cnm.GetClusterName("ocm-cluster")).Should(Equal("ocm-cluster (ocm-alias)")) cli.returnBadRequest = true - cli.prismNotRegistered = true + cli.virtualClusterNotRegistered = true _, err = NewClusterNameMapper(ctx, cli) Expect(err).ShouldNot(Succeed()) }) @@ -160,21 +159,21 @@ var _ = Describe("Test Virtual Cluster", func() { type fakeClient struct { client.Client - returnBadRequest bool - prismNotRegistered bool + returnBadRequest bool + virtualClusterNotRegistered bool } func (c fakeClient) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error { - if !c.prismNotRegistered && c.returnBadRequest { + if !c.virtualClusterNotRegistered && c.returnBadRequest { return errors.NewBadRequest("") } - if src, ok := list.(*prismclusterv1alpha1.ClusterList); ok { - if c.prismNotRegistered { + if src, ok := list.(*v1alpha1.VirtualClusterList); ok { + if c.virtualClusterNotRegistered { return runtime.NewNotRegisteredErrForKind("", schema.GroupVersionKind{}) } - objs := &prismclusterv1alpha1.ClusterList{Items: []prismclusterv1alpha1.Cluster{{ + objs := &v1alpha1.VirtualClusterList{Items: []v1alpha1.VirtualCluster{{ ObjectMeta: metav1.ObjectMeta{Name: "example"}, - Spec: prismclusterv1alpha1.ClusterSpec{Alias: "example-alias"}, + Spec: v1alpha1.VirtualClusterSpec{Alias: "example-alias"}, }, { ObjectMeta: metav1.ObjectMeta{Name: "no-alias"}, }}} diff --git a/pkg/policy/topology.go b/pkg/policy/topology.go index 04463bb9e..91d2adbd5 100644 --- a/pkg/policy/topology.go +++ b/pkg/policy/topology.go @@ -21,7 +21,6 @@ import ( "fmt" pkgmulticluster "github.com/kubevela/pkg/multicluster" - prismclusterv1alpha1 "github.com/kubevela/prism/pkg/apis/cluster/v1alpha1" "github.com/pkg/errors" utilfeature "k8s.io/apiserver/pkg/util/feature" "sigs.k8s.io/controller-runtime/pkg/client" @@ -50,7 +49,7 @@ func GetPlacementsFromTopologyPolicies(ctx context.Context, cli client.Client, a placementMap := map[string]struct{}{} addCluster := func(cluster string, ns string, validateCluster bool) error { if validateCluster { - if _, e := prismclusterv1alpha1.NewClusterClient(cli).Get(ctx, cluster); e != nil { + if _, e := multicluster.NewClusterClient(cli).Get(ctx, cluster); e != nil { return errors.Wrapf(e, "failed to get cluster %s", cluster) } } @@ -85,7 +84,7 @@ func GetPlacementsFromTopologyPolicies(ctx context.Context, cli client.Client, a } } case clusterLabelSelector != nil: - clusterList, err := prismclusterv1alpha1.NewClusterClient(cli).List(ctx, client.MatchingLabels(clusterLabelSelector)) + clusterList, err := multicluster.NewClusterClient(cli).List(ctx, client.MatchingLabels(clusterLabelSelector)) if err != nil { return nil, errors.Wrapf(err, "failed to find clusters in topology %s", policy.Name) } diff --git a/pkg/utils/common/common.go b/pkg/utils/common/common.go index 460aa63fe..7bf667c9b 100644 --- a/pkg/utils/common/common.go +++ b/pkg/utils/common/common.go @@ -60,7 +60,6 @@ import ( gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" "sigs.k8s.io/yaml" - prismclusterv1alpha1 "github.com/kubevela/prism/pkg/apis/cluster/v1alpha1" "github.com/kubevela/workflow/pkg/cue/model/value" clustergatewayapi "github.com/oam-dev/cluster-gateway/pkg/apis/cluster/v1alpha1" terraformapiv1 "github.com/oam-dev/terraform-controller/api/v1beta1" @@ -118,7 +117,6 @@ func init() { _ = clustergatewayapi.AddToScheme(Scheme) _ = metricsV1beta1api.AddToScheme(Scheme) _ = kruisev1alpha1.AddToScheme(Scheme) - _ = prismclusterv1alpha1.AddToScheme(Scheme) _ = cloudshellv1alpha1.AddToScheme(Scheme) _ = gatewayv1alpha2.AddToScheme(Scheme) // +kubebuilder:scaffold:scheme diff --git a/references/cli/auth.go b/references/cli/auth.go index c1d768ddb..dda8d895f 100644 --- a/references/cli/auth.go +++ b/references/cli/auth.go @@ -31,8 +31,6 @@ import ( "k8s.io/kubectl/pkg/util/i18n" "k8s.io/kubectl/pkg/util/templates" - prismclusterv1alpha1 "github.com/kubevela/prism/pkg/apis/cluster/v1alpha1" - "github.com/oam-dev/kubevela/apis/types" "github.com/oam-dev/kubevela/pkg/auth" velacmd "github.com/oam-dev/kubevela/pkg/cmd" @@ -198,7 +196,7 @@ func (opt *ListPrivilegesOptions) Validate(f velacmd.Factory, cmd *cobra.Command return err } for _, cluster := range opt.Clusters { - if _, err := prismclusterv1alpha1.NewClusterClient(f.Client()).Get(cmd.Context(), cluster); err != nil { + if _, err := multicluster.NewClusterClient(f.Client()).Get(cmd.Context(), cluster); err != nil { return fmt.Errorf("failed to find cluster %s: %w", cluster, err) } } @@ -334,7 +332,7 @@ func (opt *GrantPrivilegesOptions) Validate(f velacmd.Factory, cmd *cobra.Comman return fmt.Errorf("at least one idenity (user/group/serviceaccount) should be set") } for _, cluster := range opt.GrantClusters { - if _, err := prismclusterv1alpha1.NewClusterClient(f.Client()).Get(cmd.Context(), cluster); err != nil { + if _, err := multicluster.NewClusterClient(f.Client()).Get(cmd.Context(), cluster); err != nil { return fmt.Errorf("failed to find cluster %s: %w", cluster, err) } if !opt.CreateNamespace { @@ -353,7 +351,7 @@ func (opt *GrantPrivilegesOptions) Run(f velacmd.Factory, cmd *cobra.Command) er ctx := cmd.Context() if opt.CreateNamespace { for _, cluster := range opt.GrantClusters { - if _, err := prismclusterv1alpha1.NewClusterClient(f.Client()).Get(cmd.Context(), cluster); err != nil { + if _, err := multicluster.NewClusterClient(f.Client()).Get(cmd.Context(), cluster); err != nil { return fmt.Errorf("failed to find cluster %s: %w", cluster, err) } for _, namespace := range opt.GrantNamespaces { diff --git a/references/cli/cluster.go b/references/cli/cluster.go index 9b80cf48c..b2e33edc3 100644 --- a/references/cli/cluster.go +++ b/references/cli/cluster.go @@ -26,7 +26,6 @@ import ( "github.com/fatih/color" "github.com/kubevela/pkg/util/runtime" "github.com/kubevela/pkg/util/slices" - prismclusterv1alpha1 "github.com/kubevela/prism/pkg/apis/cluster/v1alpha1" clustergatewayapi "github.com/oam-dev/cluster-gateway/pkg/apis/cluster/v1alpha1" "github.com/oam-dev/cluster-gateway/pkg/config" "github.com/pkg/errors" @@ -114,7 +113,7 @@ func NewClusterListCommand(c *common.Args) *cobra.Command { if err != nil { return err } - clusters, err := prismclusterv1alpha1.NewClusterClient(client).List(context.Background()) + clusters, err := multicluster.NewClusterClient(client).List(context.Background()) if err != nil { return errors.Wrap(err, "fail to get registered cluster") } @@ -488,13 +487,13 @@ func NewClusterExportConfigCommand(f velacmd.Factory, ioStreams cmdutil.IOStream if err != nil { return fmt.Errorf("invalid selector %s: %w", labelSelector, err) } - clusters, err := prismclusterv1alpha1.NewClusterClient(f.Client()).List(cmd.Context(), client.MatchingLabelsSelector{Selector: selector}) + clusters, err := multicluster.NewClusterClient(f.Client()).List(cmd.Context(), client.MatchingLabelsSelector{Selector: selector}) if err != nil { return fmt.Errorf("failed to load clusters: %w", err) } clusterNames := slices.Filter( - slices.Map(clusters.Items, func(cluster prismclusterv1alpha1.Cluster) string { return cluster.Name }), - func(s string) bool { return s != prismclusterv1alpha1.ClusterLocalName }) + slices.Map(clusters.Items, func(cluster clustergatewayapi.VirtualCluster) string { return cluster.Name }), + func(s string) bool { return s != multicluster.ClusterLocalName }) if len(clusterNames) == 0 { return fmt.Errorf("no cluster found") diff --git a/references/cli/top/model/cluster.go b/references/cli/top/model/cluster.go index dd7f14042..ad70d596c 100644 --- a/references/cli/top/model/cluster.go +++ b/references/cli/top/model/cluster.go @@ -23,8 +23,6 @@ import ( "github.com/oam-dev/cluster-gateway/pkg/config" "sigs.k8s.io/controller-runtime/pkg/client" - prismclusterv1alpha1 "github.com/kubevela/prism/pkg/apis/cluster/v1alpha1" - "github.com/oam-dev/kubevela/pkg/multicluster" ) @@ -64,7 +62,7 @@ func ListClusters(ctx context.Context, c client.Client) (ClusterList, error) { clusterInfo := Cluster{ name: key, } - cluster, err := prismclusterv1alpha1.NewClusterClient(c).Get(context.Background(), key) + cluster, err := multicluster.NewClusterClient(c).Get(context.Background(), key) if err != nil { continue } else {