From ad879dadfbbd7fb7a6cd3191f6446ca168161a78 Mon Sep 17 00:00:00 2001 From: Yan Xiaodong <103547839+sheldon-yan@users.noreply.github.com> Date: Mon, 8 Aug 2022 12:02:25 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20Vela=20CLI=20=E7=BA=B3=E7=AE=A1=E9=9B=86?= =?UTF-8?q?=E7=BE=A4=E5=90=8E=EF=BC=8C=E6=97=A0=E6=B3=95=E9=80=9A=E8=BF=87?= =?UTF-8?q?APi=E6=8E=A5=E5=8F=A3=E5=AF=B9=E8=AF=A5=E9=9B=86=E7=BE=A4?= =?UTF-8?q?=E5=88=9B=E5=BB=BAnamespace=20#4421=20(#4507)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix: Vela CLI 纳管集群后,无法通过APi接口对该集群创建namespace #4421 Signed-off-by: yanxiaodong * Fix: Vela CLI 纳管集群后,无法通过APi接口对该集群创建namespace #4421 Signed-off-by: yanxiaodong --- pkg/apiserver/domain/service/cluster.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/apiserver/domain/service/cluster.go b/pkg/apiserver/domain/service/cluster.go index 6f584cac1..5ab731158 100644 --- a/pkg/apiserver/domain/service/cluster.go +++ b/pkg/apiserver/domain/service/cluster.go @@ -405,10 +405,20 @@ func (c *clusterServiceImpl) DeleteKubeCluster(ctx context.Context, clusterName func (c *clusterServiceImpl) CreateClusterNamespace(ctx context.Context, clusterName string, req apis.CreateClusterNamespaceRequest) (*apis.CreateClusterNamespaceResponse, error) { _, err := c.getClusterFromDataStore(ctx, clusterName) if err != nil { - if errors.Is(err, datastore.ErrRecordNotExist) { - return nil, bcode.ErrClusterNotFoundInDataStore + if !errors.Is(err, datastore.ErrRecordNotExist) { + return nil, errors.Wrapf(err, "failed to find cluster %s in data store", clusterName) + } + prismCluster, err := prismclusterv1alpha1.NewClusterClient(c.K8sClient).Get(ctx, clusterName) + if err != nil { + if kerrors.IsNotFound(err) { + return nil, bcode.ErrClusterNotFoundInDataStore + } + return nil, errors.Wrapf(err, "failed to find cluster %s in control plane", clusterName) + } + cluster := newClusterModelFromPrismCluster(prismCluster) + if err = c.Store.Add(ctx, cluster); err != nil { + return nil, errors.Wrapf(err, "failed to add cluster %s from existing prism cluster", clusterName) } - return nil, errors.Wrapf(err, "failed to found cluster %s in data store", clusterName) } ns := &v12.Namespace{} ns.Name = req.Namespace