Skip to content

Commit 66f07b4

Browse files
committed
service create/update: add support of --deployment-strategy in the definition
1 parent 8b03fdf commit 66f07b4

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

pkg/koyeb/services.go

+53
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ func (h *ServiceHandler) addServiceDefinitionFlagsForAllSources(flags *pflag.Fla
318318
"To delete an environment variable, prefix its name with '!', for example --env '!FOO'\n",
319319
)
320320
flags.String("instance-type", "nano", "Instance type")
321+
flags.String("deployment-strategy", "rolling", "Deployment strategy")
321322
flags.Int64("scale", 1, "Set both min-scale and max-scale")
322323
flags.Int64("min-scale", 1, "Min scale")
323324
flags.Int64("max-scale", 1, "Max scale")
@@ -387,6 +388,8 @@ func (h *ServiceHandler) addServiceDefinitionFlagsForAllSources(flags *pflag.Fla
387388
"health-checks-graee": "checks-grace-period",
388389
"health-checks-grace-period": "checks-grace-period",
389390

391+
"strategy": "deployment-strategy",
392+
390393
"route": "routes",
391394
"volume": "volumes",
392395
"region": "regions",
@@ -466,6 +469,12 @@ func (h *ServiceHandler) parseServiceDefinitionFlags(ctx *CLIContext, flags *pfl
466469
}
467470
definition.SetType(type_)
468471

472+
strategy, err := h.parseDeploymentStrategy(flags, definition.GetStrategy())
473+
if err != nil {
474+
return err
475+
}
476+
definition.SetStrategy(strategy)
477+
469478
skipCache, _ := flags.GetBool("skip-cache")
470479
definition.SetSkipCache(skipCache)
471480

@@ -582,6 +591,50 @@ func (h *ServiceHandler) parseInstanceType(flags *pflag.FlagSet, currentInstance
582591
return []koyeb.DeploymentInstanceType{*ret}
583592
}
584593

594+
// Parse --deployment-strategy
595+
func (h *ServiceHandler) parseDeploymentStrategy(flags *pflag.FlagSet, currentStrategy koyeb.DeploymentStrategy) (koyeb.DeploymentStrategy, error) {
596+
if !flags.Lookup("deployment-strategy").Changed {
597+
// New service: return the default value
598+
if currentStrategy.Type == nil {
599+
value := flags.Lookup("deployment-strategy").DefValue
600+
enum := fmt.Sprintf("DEPLOYMENT_STRATEGY_TYPE_%s", strings.ToUpper(strings.ReplaceAll(value, "-", "_")))
601+
kind, err := koyeb.NewDeploymentStrategyTypeFromValue(enum)
602+
if err != nil {
603+
panic(err)
604+
}
605+
ret := koyeb.DeploymentStrategy{
606+
Type: kind,
607+
}
608+
return ret, nil
609+
}
610+
// Existing service: return the strategy currently configured
611+
return currentStrategy, nil
612+
}
613+
614+
value, _ := flags.GetString("deployment-strategy")
615+
enum := fmt.Sprintf("DEPLOYMENT_STRATEGY_TYPE_%s", strings.ToUpper(strings.ReplaceAll(value, "-", "_")))
616+
kind, err := koyeb.NewDeploymentStrategyTypeFromValue(enum)
617+
if err != nil {
618+
return koyeb.DeploymentStrategy{}, &errors.CLIError{
619+
What: "Error while updating the service",
620+
Why: "the --deployment-strategy flag is not valid",
621+
Additional: []string{
622+
"The --deployment-strategy flag must be one of the following:",
623+
" - rolling",
624+
" - canary",
625+
" - blue-green",
626+
" - immediate",
627+
},
628+
Orig: nil,
629+
Solution: "Fix the --deployment-strategy flag and try again",
630+
}
631+
}
632+
ret := koyeb.DeploymentStrategy{
633+
Type: kind,
634+
}
635+
return ret, nil
636+
}
637+
585638
// parseListFlags is the generic function parsing --env, --port, --routes, --checks, --regions and --volumes
586639
// It gets the arguments given from the command line for the given flag, then
587640
// builds a list of flags_list.Flag entries, and update the service

0 commit comments

Comments
 (0)