Skip to content

Commit c6946d3

Browse files
author
Noeva
committed
Added --apply-namespace option
1 parent 9969bcb commit c6946d3

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

clients/models/operation.go

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

commands/deploy_command.go

+42-5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ const (
4343
strategyOpt = "strategy"
4444
skipTestingPhase = "skip-testing-phase"
4545
skipIdleStart = "skip-idle-start"
46+
applyNamespaceAppNamesOpt = "apply-namespace-app-names"
47+
applyNamespaceServiceNamesOpt = "apply-namespace-service-names"
48+
applyNamespaceAppRoutesOpt = "apply-namespace-app-routes"
4649
)
4750

4851
type listFlag struct {
@@ -94,13 +97,13 @@ func (c *DeployCommand) GetPluginCommand() plugin.Command {
9497
HelpText: "Deploy a new multi-target app or sync changes to an existing one",
9598
UsageDetails: plugin.Usage{
9699
Usage: `Deploy a multi-target app archive
97-
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]
100+
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]
98101
99102
Perform action on an active deploy operation
100103
cf deploy -i OPERATION_ID -a ACTION [-u URL]
101104
102105
(EXPERIMENTAL) Deploy a multi-target app archive referenced by a remote URL
103-
<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]`,
106+
<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]`,
104107
Options: map[string]string{
105108
extDescriptorsOpt: "Extension descriptors",
106109
deployServiceURLOpt: "Deploy service URL, by default 'deploy-service.<system-domain>'",
@@ -112,7 +115,10 @@ func (c *DeployCommand) GetPluginCommand() plugin.Command {
112115
moduleOpt: "Deploy list of modules which are contained in the deployment descriptor, in the current location",
113116
resourceOpt: "Deploy list of resources which are contained in the deployment descriptor, in the current location",
114117
util.GetShortOption(noStartOpt): "Do not start apps",
115-
util.GetShortOption(namespaceOpt): "(EXPERIMENTAL) Namespace for the mta, applied to app and service names as well",
118+
util.GetShortOption(namespaceOpt): "(EXPERIMENTAL) Namespace for the mta, applied to app and service names as well",
119+
util.GetShortOption(applyNamespaceAppNamesOpt): "Apply namespace to application names",
120+
util.GetShortOption(applyNamespaceServiceNamesOpt): "Apply namespace to service names",
121+
util.GetShortOption(applyNamespaceAppRoutesOpt): "Apply namespace to application routes",
116122
util.GetShortOption(deleteServicesOpt): "Recreate changed services / delete discontinued services",
117123
util.GetShortOption(deleteServiceKeysOpt): "Delete existing service keys and apply the new ones",
118124
util.GetShortOption(deleteServiceBrokersOpt): "Delete discontinued service brokers",
@@ -161,7 +167,10 @@ func (c *DeployCommand) defineCommandOptions(flags *flag.FlagSet) {
161167
flags.String(versionRuleOpt, "", "")
162168
flags.Bool(deleteServicesOpt, false, "")
163169
flags.Bool(noStartOpt, false, "")
164-
flags.String(namespaceOpt, "", "")
170+
flags.String(namespaceOpt, "", "")
171+
flags.String(applyNamespaceAppNamesOpt, "", "")
172+
flags.String(applyNamespaceServiceNamesOpt, "", "")
173+
flags.String(applyNamespaceAppRoutesOpt, "", "")
165174
flags.Bool(deleteServiceKeysOpt, false, "")
166175
flags.Bool(deleteServiceBrokersOpt, false, "")
167176
flags.Bool(keepFilesOpt, false, "")
@@ -303,6 +312,15 @@ func (c *DeployCommand) executeInternal(positionalArgs []string, dsHost string,
303312
// Build the process instance
304313
processBuilder := NewDeploymentStrategy(flags, c.processTypeProvider).CreateProcessBuilder()
305314
processBuilder.Namespace(namespace)
315+
if(namespace == "") {
316+
processBuilder.Parameter("applyNamespaceAppNames", "false")
317+
processBuilder.Parameter("applyNamespaceServiceNames", "false")
318+
processBuilder.Parameter("applyNamespaceAppRoutes", "false")
319+
} else {
320+
processBuilder.Parameter("applyNamespaceAppNames", GetStringOpt(applyNamespaceAppNamesOpt, flags))
321+
processBuilder.Parameter("applyNamespaceServiceNames", GetStringOpt(applyNamespaceServiceNamesOpt, flags))
322+
processBuilder.Parameter("applyNamespaceAppRoutes", GetStringOpt(applyNamespaceAppRoutesOpt, flags))
323+
}
306324
processBuilder.Parameter("appArchiveId", strings.Join(uploadedArchivePartIds, ","))
307325
processBuilder.Parameter("mtaExtDescriptorId", strings.Join(uploadedExtDescriptorIDs, ","))
308326
processBuilder.Parameter("mtaId", mtaId)
@@ -609,12 +627,31 @@ type deployCommandFlagsValidator struct{}
609627
func (deployCommandFlagsValidator) ValidateParsedFlags(flags *flag.FlagSet) error {
610628
var err error
611629
flags.Visit(func(f *flag.Flag) {
612-
if f.Name == strategyOpt {
630+
switch f.Name {
631+
case strategyOpt:
613632
if f.Value.String() == "" {
614633
err = errors.New("strategy flag defined but no argument specified")
615634
} else if !util.Contains(AvailableStrategies(), f.Value.String()) {
616635
err = fmt.Errorf("%s is not a valid deployment strategy, available strategies: %v", f.Value.String(), AvailableStrategies())
617636
}
637+
case applyNamespaceAppNamesOpt:
638+
if f.Value.String() == "" {
639+
err = errors.New("ApplyNamespaceAppNames flag defined but no argument specified")
640+
} else if f.Value.String() != "true" && f.Value.String() != "false" {
641+
err = fmt.Errorf("invalid value for --%s, expected true or false", applyNamespaceAppNamesOpt)
642+
}
643+
case applyNamespaceServiceNamesOpt:
644+
if f.Value.String() == "" {
645+
err = errors.New("ApplyNamespaceServiceNames flag defined but no argument specified")
646+
} else if f.Value.String() != "true" && f.Value.String() != "false" {
647+
err = fmt.Errorf("invalid value for --%s, expected true or false", applyNamespaceServiceNamesOpt)
648+
}
649+
case applyNamespaceAppRoutesOpt:
650+
if f.Value.String() == "" {
651+
err = errors.New("ApplyNamespaceAppRoutes flag defined but no argument specified")
652+
} else if f.Value.String() != "true" && f.Value.String() != "false" {
653+
err = fmt.Errorf("invalid value for --%s, expected true or false", applyNamespaceAppRoutesOpt)
654+
}
618655
}
619656
})
620657
if err != nil {

0 commit comments

Comments
 (0)