Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added --apply-namespace option #204

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions commands/blue_green_deploy_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]`,
Expand All @@ -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",
Expand Down
59 changes: 37 additions & 22 deletions commands/deploy_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
<write MTA archive URL to STDOUT> | 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]`,
<write MTA archive URL to STDOUT> | 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.<system-domain>'",
Expand All @@ -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",
Expand Down Expand Up @@ -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, "")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
MNoeva marked this conversation as resolved.
Show resolved Hide resolved
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
}
Expand All @@ -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
}
Loading