From ec0505f52ee53752c80f27eb247f3b1532a53212 Mon Sep 17 00:00:00 2001 From: WhereAreBugs <2572414306@qq.com> Date: Wed, 22 Nov 2023 16:28:01 +0800 Subject: [PATCH] add deploy type Signed-off-by: WhereAreBugs <2572414306@qq.com> --- cli/command/deploy.go | 21 +++++++++++++++++++-- internal/errno/errno.go | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/cli/command/deploy.go b/cli/command/deploy.go index c4f9f3e69..299554fa2 100644 --- a/cli/command/deploy.go +++ b/cli/command/deploy.go @@ -109,6 +109,14 @@ var ( CAN_SKIP_ROLES = []string{ ROLE_SNAPSHOTCLONE, } + SUPPORTED_DEPLOY_TYPES = []string{ + "default", + "prod", + "staging", + "test", + "beta", + "dev", + } ) type deployOptions struct { @@ -117,6 +125,7 @@ type deployOptions struct { poolset string poolsetDiskType string debug bool + deployType string } func checkDeployOptions(options deployOptions) error { @@ -127,6 +136,12 @@ func checkDeployOptions(options deployOptions) error { F("skip role: %s", role) } } + // check deploy type + supportDeployType := utils.Slice2Map(SUPPORTED_DEPLOY_TYPES) + if !supportDeployType[options.deployType] { + return errno.ERR_UNSUPPORT_DEPLOY_TYPE. + F("deploy type: %s", options.deployType) + } return nil } @@ -152,6 +167,7 @@ func NewDeployCommand(curveadm *cli.CurveAdm) *cobra.Command { flags.StringVar(&options.poolset, "poolset", "default", "poolset name") flags.StringVar(&options.poolsetDiskType, "poolset-disktype", "ssd", "Specify the disk type of physical pool") flags.BoolVar(&options.debug, "debug", false, "Debug deploy progress") + flags.StringVar(&options.deployType, "deploy-type", "default", "Specify the type of deploy") return cmd } @@ -285,10 +301,11 @@ func serviceStats(dcs []*topology.DeployConfig) string { return serviceStats } -func displayDeployTitle(curveadm *cli.CurveAdm, dcs []*topology.DeployConfig) { +func displayDeployTitle(curveadm *cli.CurveAdm, dcs []*topology.DeployConfig, options deployOptions) { curveadm.WriteOutln("Cluster Name : %s", curveadm.ClusterName()) curveadm.WriteOutln("Cluster Kind : %s", dcs[0].GetKind()) curveadm.WriteOutln("Cluster Services: %s", serviceStats(dcs)) + curveadm.WriteOutln("Cluster Type : %s", options.deployType) curveadm.WriteOutln("") } @@ -336,7 +353,7 @@ func runDeploy(curveadm *cli.CurveAdm, options deployOptions) error { } // 6) display title - displayDeployTitle(curveadm, dcs) + displayDeployTitle(curveadm, dcs, options) // 7) run playground if err = pb.Run(); err != nil { diff --git a/internal/errno/errno.go b/internal/errno/errno.go index fd40bbc00..13074bf2f 100644 --- a/internal/errno/errno.go +++ b/internal/errno/errno.go @@ -261,7 +261,7 @@ var ( ERR_UNSUPPORT_CLEAN_ITEM = EC(210005, "unsupport clean item") ERR_NO_SERVICES_MATCHED = EC(210006, "no services matched") ERR_INVALID_DISK_TYPE = EC(210007, "diskType must be lowercase and only can only be one of ssd, hdd and nvme") - + ERR_UNSUPPORT_DEPLOY_TYPE = EC(210008, "unknown deploy type") // 220: commad options (client common) ERR_UNSUPPORT_CLIENT_KIND = EC(220000, "unsupport client kind") // 221: command options (client/bs)