diff --git a/contrib/completions/bash/oc b/contrib/completions/bash/oc index 80e6f0b3693c..35e47314ab1b 100644 --- a/contrib/completions/bash/oc +++ b/contrib/completions/bash/oc @@ -15283,6 +15283,8 @@ _oc_new-build() local_nonpersistent_flags+=("--output=") flags+=("--output-version=") local_nonpersistent_flags+=("--output-version=") + flags+=("--push-secret=") + local_nonpersistent_flags+=("--push-secret=") flags+=("--show-all") flags+=("-a") local_nonpersistent_flags+=("--show-all") diff --git a/contrib/completions/zsh/oc b/contrib/completions/zsh/oc index cb1b06a64f3b..68b240e0f2b2 100644 --- a/contrib/completions/zsh/oc +++ b/contrib/completions/zsh/oc @@ -15425,6 +15425,8 @@ _oc_new-build() local_nonpersistent_flags+=("--output=") flags+=("--output-version=") local_nonpersistent_flags+=("--output-version=") + flags+=("--push-secret=") + local_nonpersistent_flags+=("--push-secret=") flags+=("--show-all") flags+=("-a") local_nonpersistent_flags+=("--show-all") diff --git a/pkg/oc/cli/cmd/newbuild.go b/pkg/oc/cli/cmd/newbuild.go index e257c1e40be9..e47f9fa28117 100644 --- a/pkg/oc/cli/cmd/newbuild.go +++ b/pkg/oc/cli/cmd/newbuild.go @@ -114,6 +114,7 @@ func NewCmdNewBuild(name, baseName string, f *clientcmd.Factory, in io.Reader, o cmd.Flags().StringSliceVar(&config.DockerImages, "docker-image", config.DockerImages, "Name of a Docker image to use as a builder.") cmd.Flags().StringSliceVar(&config.Secrets, "build-secret", config.Secrets, "Secret and destination to use as an input for the build.") cmd.Flags().StringVar(&config.SourceSecret, "source-secret", "", "The name of an existing secret that should be used for cloning a private git repository.") + cmd.Flags().StringVar(&config.PushSecret, "push-secret", "", "The name of an existing secret that should be used for pushing the output image.") cmd.Flags().StringVar(&config.Name, "name", "", "Set name to use for generated build artifacts.") cmd.Flags().StringVar(&config.To, "to", "", "Push built images to this image stream tag (or Docker image repository if --to-docker is set).") cmd.Flags().BoolVar(&config.OutputDocker, "to-docker", false, "If true, have the build output push to a Docker repository.") diff --git a/pkg/oc/generate/cmd/newapp.go b/pkg/oc/generate/cmd/newapp.go index e8e7be48e56b..36f5fde42b60 100644 --- a/pkg/oc/generate/cmd/newapp.go +++ b/pkg/oc/generate/cmd/newapp.go @@ -106,6 +106,7 @@ type AppConfig struct { AllowSecretUse bool SourceSecret string + PushSecret string AllowNonNumericExposedPorts bool SecretAccessor app.SecretAccessor @@ -909,6 +910,18 @@ func (c *AppConfig) Run() (*AppResult, error) { } } } + if len(c.PushSecret) > 0 { + if len(validation.ValidateSecretName(c.PushSecret, false)) != 0 { + return nil, fmt.Errorf("push secret name %q is invalid", c.PushSecret) + } + for _, obj := range objects { + if bc, ok := obj.(*buildapi.BuildConfig); ok { + glog.V(4).Infof("Setting push secret for build config to: %v", c.SourceSecret) + bc.Spec.Output.PushSecret = &kapi.LocalObjectReference{Name: c.PushSecret} + break + } + } + } return &AppResult{ List: &kapi.List{Items: objects}, diff --git a/test/cmd/newapp.sh b/test/cmd/newapp.sh index 3b1540874ab1..62da8db08c4f 100755 --- a/test/cmd/newapp.sh +++ b/test/cmd/newapp.sh @@ -69,6 +69,9 @@ os::cmd::expect_failure_and_text 'oc new-app https://github.com/openshift/cakeph os::cmd::expect_success_and_text 'oc new-app -f examples/quickstarts/cakephp-mysql.json --source-secret=mysecret -o yaml' 'name: mysecret' os::cmd::expect_success 'oc new-app https://github.com/openshift/cakephp-ex --source-secret=mysecret' os::cmd::expect_success 'oc delete all --selector="label=cakephp-ex"' +# setting push secret via the --push-secret flag +os::cmd::expect_success_and_text 'oc new-build https://github.com/openshift/cakephp-ex --push-secret=mynewsecret -o yaml' 'name: mynewsecret' +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' # check label creation