From 3f8392ba75cb05518c2c27d7c94f4bffcaa64b9c Mon Sep 17 00:00:00 2001 From: Yavor16 Date: Fri, 13 Sep 2024 14:38:46 +0300 Subject: [PATCH] Add --apply-namespace-as-suffix parameter --- commands/blue_green_deploy_command.go | 3 ++- commands/deploy_command.go | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/commands/blue_green_deploy_command.go b/commands/blue_green_deploy_command.go index 1ad2af0..5a6b3dc 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] [--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] + 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] [--apply-namespace-as-suffix 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]`, @@ -49,6 +49,7 @@ func (c *BlueGreenDeployCommand) GetPluginCommand() plugin.Command { 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(applyNamespaceAsSuffix): "(EXPERIMENTAL) Apply namespace at the end of the application name: (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 62903c1..000af29 100644 --- a/commands/deploy_command.go +++ b/commands/deploy_command.go @@ -50,6 +50,8 @@ const ( applyNamespaceAppNamesOpt = "apply-namespace-app-names" applyNamespaceServiceNamesOpt = "apply-namespace-service-names" applyNamespaceAppRoutesOpt = "apply-namespace-app-routes" + applyNamespaceAsSuffix = "apply-namespace-as-suffix" + maxNamespaceSize = 36 ) type listFlag struct { @@ -102,14 +104,14 @@ func (c *DeployCommand) GetPluginCommand() plugin.Command { 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] [--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] + 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] [--apply-namespace-as-suffix 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] [--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]`, + | 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] [--apply-namespace-as-suffix 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", @@ -125,6 +127,7 @@ func (c *DeployCommand) GetPluginCommand() plugin.Command { 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(applyNamespaceAsSuffix): "(EXPERIMENTAL) Apply namespace at the end of the application name: (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", @@ -202,6 +205,7 @@ func (c *DeployCommand) defineCommandOptions(flags *flag.FlagSet) { flags.String(applyNamespaceAppNamesOpt, "", "") flags.String(applyNamespaceServiceNamesOpt, "", "") flags.String(applyNamespaceAppRoutesOpt, "", "") + flags.String(applyNamespaceAsSuffix, "", "") flags.Bool(deleteServiceKeysOpt, false, "") flags.Bool(deleteServiceBrokersOpt, false, "") flags.Bool(keepFilesOpt, false, "") @@ -351,6 +355,7 @@ func (c *DeployCommand) executeInternal(positionalArgs []string, dsHost string, processBuilder.Parameter("applyNamespaceAppNames", GetStringOpt(applyNamespaceAppNamesOpt, flags)) processBuilder.Parameter("applyNamespaceServiceNames", GetStringOpt(applyNamespaceServiceNamesOpt, flags)) processBuilder.Parameter("applyNamespaceAppRoutes", GetStringOpt(applyNamespaceAppRoutesOpt, flags)) + processBuilder.Parameter("applyNamespaceAsSuffix", GetStringOpt(applyNamespaceAsSuffix, flags)) processBuilder.Parameter("appArchiveId", strings.Join(uploadedArchivePartIds, ",")) processBuilder.Parameter("mtaExtDescriptorId", strings.Join(uploadedExtDescriptorIDs, ",")) @@ -668,12 +673,19 @@ 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 namespaceOpt: + fmt.Sprint(namespaceOpt) + if len(f.Value.String()) > maxNamespaceSize { + err = fmt.Errorf("Invalid value for namespace. The namespace cannot be more than %d symbols.", maxNamespaceSize) + return + } + //case case timeoutOpt, startTimeoutOpt, stageTimeoutOpt, uploadTimeoutOpt, taskExecutionTimeoutOpt: if e := ValidateTimeoutOption(f.Name, flags, 259200); e != nil { err = e return } - case applyNamespaceAppNamesOpt, applyNamespaceServiceNamesOpt, applyNamespaceAppRoutesOpt: + case applyNamespaceAppNamesOpt, applyNamespaceServiceNamesOpt, applyNamespaceAppRoutesOpt, applyNamespaceAsSuffix: if e := ValidateBooleanFlag(f.Name, flags); e != nil { err = e return