Fix: Vela CLI 纳管集群后,无法通过APi接口对该集群创建namespace #4421 (#4507)

* Fix: Vela CLI 纳管集群后,无法通过APi接口对该集群创建namespace #4421

Signed-off-by: yanxiaodong <yanxd0818@cmbchina.com>

* Fix: Vela CLI 纳管集群后,无法通过APi接口对该集群创建namespace #4421

Signed-off-by: yanxiaodong <yanxd0818@cmbchina.com>
This commit is contained in:
Yan Xiaodong
2022-08-08 12:02:25 +08:00
committed by GitHub
parent 0b03f99765
commit ad879dadfb
+13 -3
View File
@@ -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