Skip to content

Commit 0eb3b28

Browse files
author
OpenShift Bot
committed
Merge pull request #8331 from bparees/newapp_label
Merged by openshift-bot
2 parents af412f2 + 92fce62 commit 0eb3b28

File tree

4 files changed

+496
-4
lines changed

4 files changed

+496
-4
lines changed

pkg/cmd/cli/cmd/newapp.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,15 @@ func (o *NewAppOptions) Run() error {
241241
return err
242242
}
243243

244+
// if the user has set the "app" label explicitly on their objects in the template,
245+
// we should not return a failure when we can't set it ourselves.
246+
ignoreLabelFailure := false
244247
if len(config.Labels) == 0 && len(result.Name) > 0 {
245248
config.Labels = map[string]string{"app": result.Name}
249+
ignoreLabelFailure = true
246250
}
247251

248-
if err := setLabels(config.Labels, result); err != nil {
252+
if err := setLabels(config.Labels, result, ignoreLabelFailure); err != nil {
249253
return err
250254
}
251255

@@ -518,10 +522,10 @@ func setAnnotations(annotations map[string]string, result *newcmd.AppResult) err
518522
return nil
519523
}
520524

521-
func setLabels(labels map[string]string, result *newcmd.AppResult) error {
525+
func setLabels(labels map[string]string, result *newcmd.AppResult, ignoreFailure bool) error {
522526
for _, object := range result.List.Items {
523527
err := util.AddObjectLabels(object, labels)
524-
if err != nil {
528+
if err != nil && !ignoreFailure {
525529
return err
526530
}
527531
}

pkg/cmd/cli/cmd/newbuild.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (o *NewBuildOptions) Run() error {
190190
config.Labels = map[string]string{"build": result.Name}
191191
}
192192

193-
if err := setLabels(config.Labels, result); err != nil {
193+
if err := setLabels(config.Labels, result, false); err != nil {
194194
return err
195195
}
196196
if err := setAnnotations(map[string]string{newcmd.GeneratedByNamespace: newcmd.GeneratedByNewBuild}, result); err != nil {

test/cmd/newapp.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample -o yaml' 'MY
6060
os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample -o yaml' 'ADMIN_USERNAME'
6161
os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample -o yaml' 'ADMIN_PASSWORD'
6262

63+
# verify we can create from a template when some objects in the template declare an app label
64+
# the app label should still be applied to the other objects in the template.
65+
os::cmd::expect_success_and_text 'oc new-app -f test/fixtures/template-with-app-label.json -o yaml' 'app: ruby-sample-build'
66+
os::cmd::expect_success_and_text 'oc new-app -f test/fixtures/template-with-app-label.json -o yaml' 'app: myapp'
67+
6368
# check search
6469
os::cmd::expect_success_and_text 'oc new-app --search mysql' "Tags:\s+5.5, 5.6, latest"
6570
os::cmd::expect_success_and_text 'oc new-app --search ruby-helloworld-sample' 'ruby-helloworld-sample'

0 commit comments

Comments
 (0)