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

feat: allow mta extension descriptors as list #4948

Closed
wants to merge 6 commits into from
Closed
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
16 changes: 13 additions & 3 deletions cmd/cloudFoundryDeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,13 @@ func deployMta(config *cloudFoundryDeployOptions, mtarFilePath string, command c
cfDeployParams = append(cfDeployParams, deployParams...)
}

extFileParams, extFiles := handleMtaExtensionDescriptors(config.MtaExtensionDescriptor)
var extFileParams []string
var extFiles []string
if len(config.MtaExtensionDescriptors) > 0 {
extFileParams, extFiles = handleMtaExtensionDescriptorsAsList(config.MtaExtensionDescriptors)
} else {
extFileParams, extFiles = handleMtaExtensionDescriptors(config.MtaExtensionDescriptor)
}

for _, extFile := range extFiles {
_, err := fileUtils.Copy(extFile, extFile+".original")
Expand Down Expand Up @@ -549,10 +555,10 @@ func toMap(keyValue []string, separator string) (map[string]string, error) {
return result, nil
}

func handleMtaExtensionDescriptors(mtaExtensionDescriptor string) ([]string, []string) {
func handleMtaExtensionDescriptorsAsList(mtaExtensionDescriptors []string) ([]string, []string) {
var result = []string{}
var extFiles = []string{}
for _, part := range strings.Fields(strings.Trim(mtaExtensionDescriptor, " ")) {
for _, part := range mtaExtensionDescriptors {
if part == "-e" || part == "" {
continue
}
Expand All @@ -566,6 +572,10 @@ func handleMtaExtensionDescriptors(mtaExtensionDescriptor string) ([]string, []s
return result, extFiles
}

func handleMtaExtensionDescriptors(mtaExtensionDescriptor string) ([]string, []string) {
return handleMtaExtensionDescriptorsAsList(strings.Fields(strings.Trim(mtaExtensionDescriptor, " ")))
}

func cfDeploy(
config *cloudFoundryDeployOptions,
cfDeployParams []string,
Expand Down
13 changes: 12 additions & 1 deletion cmd/cloudFoundryDeploy_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions cmd/cloudFoundryDeploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,14 @@ func TestExtensionDescriptorsWithMinusE(t *testing.T) {
extDesc, _ := handleMtaExtensionDescriptors("")
assert.Equal(t, []string{}, extDesc)
})

t.Run("ExtensionDescriptorsDefinedAsList", func(t *testing.T) {
extDesc, _ := handleMtaExtensionDescriptorsAsList([]string{"1.yaml", "2.yaml"})
assert.Equal(t, []string{
"-e",
"1.yaml,2.yaml",
}, extDesc)
})
}

func TestAppNameChecks(t *testing.T) {
Expand Down
11 changes: 10 additions & 1 deletion resources/metadata/cloudFoundryDeploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ spec:
default: "-f"
- name: mtaExtensionDescriptor
type: string
description: "Defines additional extension descriptor file for deployment with the mtaDeployPlugin"
description: "Defines additional extension descriptor file for deployment with the mtaDeployPlugin. Multiple files can be provided as a space separated string."
scope:
- PARAMETERS
- STAGES
Expand All @@ -284,6 +284,15 @@ spec:
aliases:
- name: cloudFoundry/mtaExtensionDescriptor
deprecated: true
- name: mtaExtensionDescriptors
type: "[]string"
description: "Defines additional extension descriptor file(s) for deployment with the mtaDeployPlugin provided as a list."
scope:
- PARAMETERS
- STAGES
- STEPS
- GENERAL
mandatory: false
- name: mtaExtensionCredentials
type: "map[string]interface{}"
description: "Defines a map of credentials that need to be replaced in the `mtaExtensionDescriptor`. This map needs to be created as `value-to-be-replaced`:`id-of-a-credential-in-jenkins`. The placeholders in the extension descriptor file(s) looks like: `<%= value-to-be-replaced %>`. When used outside Jenkins the secret which corresponds to `id-of-a-credential-in-jenkins` needs to be provided as environment variable in screaming snake case, e.g.: `export ID_OF_A_CREDENTIAL_IN_JENKINS=<secret>`. `id-of-a-credential-in-jenkins` needs to be provided in a way so that it can be translated into a valid environment variable name (e.g. don't start with a number). `value-to-be-replaced` must match this regex: `^[-_A-Za-z0-9]+$`."
Expand Down
Loading