Skip to content

Commit

Permalink
Merge pull request #18477 from damemi/iss17941
Browse files Browse the repository at this point in the history
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
  • Loading branch information
openshift-merge-robot authored Feb 8, 2018
2 parents f90b369 + 658ce04 commit 56efdb0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions contrib/completions/bash/oc

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

2 changes: 2 additions & 0 deletions contrib/completions/zsh/oc

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

1 change: 1 addition & 0 deletions pkg/oc/cli/cmd/newbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
13 changes: 13 additions & 0 deletions pkg/oc/generate/cmd/newapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type AppConfig struct {

AllowSecretUse bool
SourceSecret string
PushSecret string
AllowNonNumericExposedPorts bool
SecretAccessor app.SecretAccessor

Expand Down Expand Up @@ -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},
Expand Down
3 changes: 3 additions & 0 deletions test/cmd/newapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 56efdb0

Please sign in to comment.