diff --git a/commands/blue_green_deploy_command.go b/commands/blue_green_deploy_command.go index 29a9661..1ad2af0 100644 --- a/commands/blue_green_deploy_command.go +++ b/commands/blue_green_deploy_command.go @@ -33,7 +33,7 @@ func (c *BlueGreenDeployCommand) GetPluginCommand() plugin.Command { HelpText: "Deploy a multi-target app using blue-green deployment", UsageDetails: plugin.Usage{ Usage: `Deploy a multi-target app using blue-green deployment - cf bg-deploy MTA [-e EXT_DESCRIPTOR[,...]] [-t TIMEOUT] [--version-rule VERSION_RULE] [-u URL] [-f] [--retries RETRIES] [--no-start] [--namespace NAMESPACE] [--delete-services] [--delete-service-keys] [--delete-service-brokers] [--keep-files] [--no-restart-subscribed-apps] [--no-confirm] [--skip-idle-start] [--do-not-fail-on-missing-permissions] [--abort-on-error] [--apps-start-timeout TIMEOUT] [--apps-stage-timeout TIMEOUT] [--apps-upload-timeout TIMEOUT] [--apps-task-execution-timeout TIMEOUT] + cf bg-deploy MTA [-e EXT_DESCRIPTOR[,...]] [-t TIMEOUT] [--version-rule VERSION_RULE] [-u URL] [-f] [--retries RETRIES] [--no-start] [--namespace NAMESPACE] [--apply-namespace-app-names true/false] [--apply-namespace-service-names true/false] [--apply-namespace-app-routes true/false] [--delete-services] [--delete-service-keys] [--delete-service-brokers] [--keep-files] [--no-restart-subscribed-apps] [--no-confirm] [--skip-idle-start] [--do-not-fail-on-missing-permissions] [--abort-on-error] [--apps-start-timeout TIMEOUT] [--apps-stage-timeout TIMEOUT] [--apps-upload-timeout TIMEOUT] [--apps-task-execution-timeout TIMEOUT] Perform action on an active deploy operation cf deploy -i OPERATION_ID -a ACTION [-u URL]`, @@ -45,7 +45,10 @@ func (c *BlueGreenDeployCommand) GetPluginCommand() plugin.Command { actionOpt: "Action to perform on active deploy operation (abort, retry, resume, monitor)", forceOpt: "Force deploy without confirmation for aborting conflicting processes", util.GetShortOption(noStartOpt): "Do not start apps", - util.GetShortOption(namespaceOpt): "(EXPERIMENTAL) Namespace for the mta, applied to app and service names as well", + util.GetShortOption(namespaceOpt): "(EXPERIMENTAL) Namespace for the MTA, applied on app names, app routes and service names", + util.GetShortOption(applyNamespaceAppNamesOpt): "(EXPERIMENTAL) Apply namespace to application names: (true, false)", + util.GetShortOption(applyNamespaceServiceNamesOpt): "(EXPERIMENTAL) Apply namespace to service names: (true, false)", + util.GetShortOption(applyNamespaceAppRoutesOpt): "(EXPERIMENTAL) Apply namespace to application routes: (true, false)", util.GetShortOption(deleteServicesOpt): "Recreate changed services / delete discontinued services", util.GetShortOption(deleteServiceKeysOpt): "Delete existing service keys and apply the new ones", util.GetShortOption(deleteServiceBrokersOpt): "Delete discontinued service brokers", diff --git a/commands/deploy_command.go b/commands/deploy_command.go index a6f501f..62903c1 100644 --- a/commands/deploy_command.go +++ b/commands/deploy_command.go @@ -47,6 +47,9 @@ const ( stageTimeoutOpt = "apps-stage-timeout" uploadTimeoutOpt = "apps-upload-timeout" taskExecutionTimeoutOpt = "apps-task-execution-timeout" + applyNamespaceAppNamesOpt = "apply-namespace-app-names" + applyNamespaceServiceNamesOpt = "apply-namespace-service-names" + applyNamespaceAppRoutesOpt = "apply-namespace-app-routes" ) type listFlag struct { @@ -98,13 +101,16 @@ func (c *DeployCommand) GetPluginCommand() plugin.Command { HelpText: "Deploy a new multi-target app or sync changes to an existing one", UsageDetails: plugin.Usage{ Usage: `Deploy a multi-target app archive - cf deploy MTA [-e EXT_DESCRIPTOR[,...]] [-t TIMEOUT] [--version-rule VERSION_RULE] [-u URL] [-f] [--retries RETRIES] [--no-start] [--namespace NAMESPACE] [--delete-services] [--delete-service-keys] [--delete-service-brokers] [--keep-files] [--no-restart-subscribed-apps] [--do-not-fail-on-missing-permissions] [--abort-on-error] [--strategy STRATEGY] [--skip-testing-phase] [--skip-idle-start] [--apps-start-timeout TIMEOUT] [--apps-stage-timeout TIMEOUT] [--apps-upload-timeout TIMEOUT] [--apps-task-execution-timeout TIMEOUT] + + cf deploy MTA [-e EXT_DESCRIPTOR[,...]] [-t TIMEOUT] [--version-rule VERSION_RULE] [-u URL] [-f] [--retries RETRIES] [--no-start] [--namespace NAMESPACE] [--apply-namespace-app-names true/false] [--apply-namespace-service-names true/false] [--apply-namespace-app-routes true/false] [--delete-services] [--delete-service-keys] [--delete-service-brokers] [--keep-files] [--no-restart-subscribed-apps] [--do-not-fail-on-missing-permissions] [--abort-on-error] [--strategy STRATEGY] [--skip-testing-phase] [--skip-idle-start] [--apps-start-timeout TIMEOUT] [--apps-stage-timeout TIMEOUT] [--apps-upload-timeout TIMEOUT] [--apps-task-execution-timeout TIMEOUT] + Perform action on an active deploy operation cf deploy -i OPERATION_ID -a ACTION [-u URL] (EXPERIMENTAL) Deploy a multi-target app archive referenced by a remote URL - | cf deploy [-e EXT_DESCRIPTOR[,...]] [-t TIMEOUT] [--version-rule VERSION_RULE] [-u MTA_CONTROLLER_URL] [--retries RETRIES] [--no-start] [--namespace NAMESPACE] [--delete-services] [--delete-service-keys] [--delete-service-brokers] [--keep-files] [--no-restart-subscribed-apps] [--do-not-fail-on-missing-permissions] [--abort-on-error] [--strategy STRATEGY] [--skip-testing-phase] [--skip-idle-start] [--apps-start-timeout TIMEOUT] [--apps-stage-timeout TIMEOUT] [--apps-upload-timeout TIMEOUT] [--apps-task-execution-timeout TIMEOUT]`, + | cf deploy [-e EXT_DESCRIPTOR[,...]] [-t TIMEOUT] [--version-rule VERSION_RULE] [-u MTA_CONTROLLER_URL] [--retries RETRIES] [--no-start] [--namespace NAMESPACE] [--apply-namespace-app-names true/false] [--apply-namespace-service-names true/false] [--apply-namespace-app-routes true/false] [--delete-services] [--delete-service-keys] [--delete-service-brokers] [--keep-files] [--no-restart-subscribed-apps] [--do-not-fail-on-missing-permissions] [--abort-on-error] [--strategy STRATEGY] [--skip-testing-phase] [--skip-idle-start] [--apps-start-timeout TIMEOUT] [--apps-stage-timeout TIMEOUT] [--apps-upload-timeout TIMEOUT] [--apps-task-execution-timeout TIMEOUT]`, + Options: map[string]string{ extDescriptorsOpt: "Extension descriptors", deployServiceURLOpt: "Deploy service URL, by default 'deploy-service.'", @@ -115,7 +121,10 @@ func (c *DeployCommand) GetPluginCommand() plugin.Command { moduleOpt: "Deploy list of modules which are contained in the deployment descriptor, in the current location", resourceOpt: "Deploy list of resources which are contained in the deployment descriptor, in the current location", util.GetShortOption(noStartOpt): "Do not start apps", - util.GetShortOption(namespaceOpt): "(EXPERIMENTAL) Namespace for the mta, applied to app and service names as well", + util.GetShortOption(namespaceOpt): "(EXPERIMENTAL) Namespace for the MTA, applied on app names, app routes and service names", + util.GetShortOption(applyNamespaceAppNamesOpt): "(EXPERIMENTAL) Apply namespace to application names: (true, false)", + util.GetShortOption(applyNamespaceServiceNamesOpt): "(EXPERIMENTAL) Apply namespace to service names: (true, false)", + util.GetShortOption(applyNamespaceAppRoutesOpt): "(EXPERIMENTAL) Apply namespace to application routes: (true, false)", util.GetShortOption(deleteServicesOpt): "Recreate changed services / delete discontinued services", util.GetShortOption(deleteServiceKeysOpt): "Delete existing service keys and apply the new ones", util.GetShortOption(deleteServiceBrokersOpt): "Delete discontinued service brokers", @@ -189,7 +198,10 @@ func (c *DeployCommand) defineCommandOptions(flags *flag.FlagSet) { flags.String(versionRuleOpt, "", "") flags.Bool(deleteServicesOpt, false, "") flags.Bool(noStartOpt, false, "") - flags.String(namespaceOpt, "", "") + flags.String(namespaceOpt, "", "") + flags.String(applyNamespaceAppNamesOpt, "", "") + flags.String(applyNamespaceServiceNamesOpt, "", "") + flags.String(applyNamespaceAppRoutesOpt, "", "") flags.Bool(deleteServiceKeysOpt, false, "") flags.Bool(deleteServiceBrokersOpt, false, "") flags.Bool(keepFilesOpt, false, "") @@ -336,6 +348,10 @@ func (c *DeployCommand) executeInternal(positionalArgs []string, dsHost string, // Build the process instance processBuilder := NewDeploymentStrategy(flags, c.processTypeProvider).CreateProcessBuilder() processBuilder.Namespace(namespace) + processBuilder.Parameter("applyNamespaceAppNames", GetStringOpt(applyNamespaceAppNamesOpt, flags)) + processBuilder.Parameter("applyNamespaceServiceNames", GetStringOpt(applyNamespaceServiceNamesOpt, flags)) + processBuilder.Parameter("applyNamespaceAppRoutes", GetStringOpt(applyNamespaceAppRoutesOpt, flags)) + processBuilder.Parameter("appArchiveId", strings.Join(uploadedArchivePartIds, ",")) processBuilder.Parameter("mtaExtDescriptorId", strings.Join(uploadedExtDescriptorIDs, ",")) processBuilder.Parameter("mtaId", mtaId) @@ -652,28 +668,13 @@ func (deployCommandFlagsValidator) ValidateParsedFlags(flags *flag.FlagSet) erro err = fmt.Errorf("%s is not a valid deployment strategy, available strategies: %v", f.Value.String(), AvailableStrategies()) return } - case timeoutOpt: - if e := ValidateTimeoutOption(f.Name, flags, 259200); e != nil { - err = e - return - } - case startTimeoutOpt: - if e := ValidateTimeoutOption(f.Name, flags, 259200); e != nil { - err = e - return - } - case stageTimeoutOpt: - if e := ValidateTimeoutOption(f.Name, flags, 259200); e != nil { - err = e - return - } - case uploadTimeoutOpt: + case timeoutOpt, startTimeoutOpt, stageTimeoutOpt, uploadTimeoutOpt, taskExecutionTimeoutOpt: if e := ValidateTimeoutOption(f.Name, flags, 259200); e != nil { err = e return } - case taskExecutionTimeoutOpt: - if e := ValidateTimeoutOption(f.Name, flags, 259200); e != nil { + case applyNamespaceAppNamesOpt, applyNamespaceServiceNamesOpt, applyNamespaceAppRoutesOpt: + if e := ValidateBooleanFlag(f.Name, flags); e != nil { err = e return } @@ -694,3 +695,17 @@ func ValidateTimeoutOption(optionName string, flags *flag.FlagSet, maxAllowedVal } return nil } + +func ValidateBooleanFlag(flagName string, flags *flag.FlagSet) error { + flagValueStr := flags.Lookup(flagName).Value.String() + + if flagValueStr == "" { + return fmt.Errorf("%s flag defined but no argument specified", flagName) + } + + if flagValueStr != "true" && flagValueStr != "false" { + return fmt.Errorf("Invalid value for %s: %s. Expected true or false.", flagName, flagValueStr) + } + + return nil +}