Fix: it does not check the same name for 'vela env init' (#4798)

Signed-off-by: wuzhongjian <wuzhongjian_yewu@cmss.chinamobile.com>
(cherry picked from commit a38e6d401b)

Co-authored-by: wuzhongjian <wuzhongjian_yewu@cmss.chinamobile.com>
This commit is contained in:
github-actions[bot]
2022-09-28 10:59:26 +08:00
committed by GitHub
parent 4c525f8e5d
commit caf09b81b0

11
pkg/utils/env/env.go vendored
View File

@@ -73,6 +73,17 @@ func CreateEnv(envArgs *types.EnvMeta) error {
}
}
ctx := context.TODO()
var nsList v1.NamespaceList
err = c.List(ctx, &nsList, client.MatchingLabels{oam.LabelControlPlaneNamespaceUsage: oam.VelaNamespaceUsageEnv,
oam.LabelNamespaceOfEnvName: envArgs.Name})
if err != nil {
return err
}
if len(nsList.Items) > 0 {
return fmt.Errorf("env name %s already exists", envArgs.Name)
}
namespace, err := utils.GetNamespace(ctx, c, envArgs.Namespace)
if err != nil && !apierrors.IsNotFound(err) {
return err