Skip to content

Commit 56efdb0

Browse files
Merge pull request #18477 from damemi/iss17941
Automatic merge from submit-queue. Issue 17941: Add oc new-build --push-secret option Adds a `--push-secret` option to `oc new-build` as requested in #17941 fixes #17941
2 parents f90b369 + 658ce04 commit 56efdb0

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

contrib/completions/bash/oc

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

contrib/completions/zsh/oc

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

pkg/oc/cli/cmd/newbuild.go

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func NewCmdNewBuild(name, baseName string, f *clientcmd.Factory, in io.Reader, o
114114
cmd.Flags().StringSliceVar(&config.DockerImages, "docker-image", config.DockerImages, "Name of a Docker image to use as a builder.")
115115
cmd.Flags().StringSliceVar(&config.Secrets, "build-secret", config.Secrets, "Secret and destination to use as an input for the build.")
116116
cmd.Flags().StringVar(&config.SourceSecret, "source-secret", "", "The name of an existing secret that should be used for cloning a private git repository.")
117+
cmd.Flags().StringVar(&config.PushSecret, "push-secret", "", "The name of an existing secret that should be used for pushing the output image.")
117118
cmd.Flags().StringVar(&config.Name, "name", "", "Set name to use for generated build artifacts.")
118119
cmd.Flags().StringVar(&config.To, "to", "", "Push built images to this image stream tag (or Docker image repository if --to-docker is set).")
119120
cmd.Flags().BoolVar(&config.OutputDocker, "to-docker", false, "If true, have the build output push to a Docker repository.")

pkg/oc/generate/cmd/newapp.go

+13
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ type AppConfig struct {
106106

107107
AllowSecretUse bool
108108
SourceSecret string
109+
PushSecret string
109110
AllowNonNumericExposedPorts bool
110111
SecretAccessor app.SecretAccessor
111112

@@ -909,6 +910,18 @@ func (c *AppConfig) Run() (*AppResult, error) {
909910
}
910911
}
911912
}
913+
if len(c.PushSecret) > 0 {
914+
if len(validation.ValidateSecretName(c.PushSecret, false)) != 0 {
915+
return nil, fmt.Errorf("push secret name %q is invalid", c.PushSecret)
916+
}
917+
for _, obj := range objects {
918+
if bc, ok := obj.(*buildapi.BuildConfig); ok {
919+
glog.V(4).Infof("Setting push secret for build config to: %v", c.SourceSecret)
920+
bc.Spec.Output.PushSecret = &kapi.LocalObjectReference{Name: c.PushSecret}
921+
break
922+
}
923+
}
924+
}
912925

913926
return &AppResult{
914927
List: &kapi.List{Items: objects},

test/cmd/newapp.sh

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ os::cmd::expect_failure_and_text 'oc new-app https://github.com/openshift/cakeph
6969
os::cmd::expect_success_and_text 'oc new-app -f examples/quickstarts/cakephp-mysql.json --source-secret=mysecret -o yaml' 'name: mysecret'
7070
os::cmd::expect_success 'oc new-app https://github.com/openshift/cakephp-ex --source-secret=mysecret'
7171
os::cmd::expect_success 'oc delete all --selector="label=cakephp-ex"'
72+
# setting push secret via the --push-secret flag
73+
os::cmd::expect_success_and_text 'oc new-build https://github.com/openshift/cakephp-ex --push-secret=mynewsecret -o yaml' 'name: mynewsecret'
74+
os::cmd::expect_failure_and_text 'oc new-build https://github.com/openshift/cakephp-ex --push-secret=InvalidSecretName -o yaml' 'error: push secret name "InvalidSecretName" is invalid'
7275

7376

7477
# check label creation

0 commit comments

Comments
 (0)