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

Issue 17941: Add oc new-build --push-secret option #18477

Merged
merged 1 commit into from
Feb 8, 2018
Merged
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
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