Skip to content

Commit be44a8a

Browse files
author
OpenShift Bot
authored
Merge pull request #10057 from fabianofranz/issues_9979
Merged by openshift-bot
2 parents 052db6c + 6ef4c5f commit be44a8a

File tree

9 files changed

+44
-8
lines changed

9 files changed

+44
-8
lines changed

contrib/completions/bash/oc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ _oc_new-project()
444444

445445
flags+=("--description=")
446446
flags+=("--display-name=")
447+
flags+=("--skip-config-write")
447448
flags+=("--api-version=")
448449
flags+=("--as=")
449450
flags+=("--certificate-authority=")

contrib/completions/bash/openshift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4894,6 +4894,7 @@ _openshift_cli_new-project()
48944894

48954895
flags+=("--description=")
48964896
flags+=("--display-name=")
4897+
flags+=("--skip-config-write")
48974898
flags+=("--api-version=")
48984899
flags+=("--as=")
48994900
flags+=("--certificate-authority=")

contrib/completions/zsh/oc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ _oc_new-project()
605605
606606
flags+=("--description=")
607607
flags+=("--display-name=")
608+
flags+=("--skip-config-write")
608609
flags+=("--api-version=")
609610
flags+=("--as=")
610611
flags+=("--certificate-authority=")

contrib/completions/zsh/openshift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5055,6 +5055,7 @@ _openshift_cli_new-project()
50555055

50565056
flags+=("--description=")
50575057
flags+=("--display-name=")
5058+
flags+=("--skip-config-write")
50585059
flags+=("--api-version=")
50595060
flags+=("--as=")
50605061
flags+=("--certificate-authority=")

docs/man/man1/oc-new-project.1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ After your project is created it will become the default project in your config.
3232
\fB\-\-display\-name\fP=""
3333
Project display name
3434

35+
.PP
36+
\fB\-\-skip\-config\-write\fP=false
37+
If true, the project will not be set as a cluster entry in kubeconfig after being created
38+
3539

3640
.SH OPTIONS INHERITED FROM PARENT COMMANDS
3741
.PP

docs/man/man1/openshift-cli-new-project.1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ After your project is created it will become the default project in your config.
3232
\fB\-\-display\-name\fP=""
3333
Project display name
3434

35+
.PP
36+
\fB\-\-skip\-config\-write\fP=false
37+
If true, the project will not be set as a cluster entry in kubeconfig after being created
38+
3539

3640
.SH OPTIONS INHERITED FROM PARENT COMMANDS
3741
.PP

pkg/cmd/cli/cmd/request_project.go

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ type NewProjectOptions struct {
2121
DisplayName string
2222
Description string
2323

24-
Name string
24+
Name string
25+
Server string
26+
27+
SkipConfigWrite bool
2528

2629
Client client.Interface
2730

@@ -73,6 +76,7 @@ func NewCmdRequestProject(baseName, name, ocLoginName, ocProjectName string, f *
7376

7477
cmd.Flags().StringVar(&options.DisplayName, "display-name", "", "Project display name")
7578
cmd.Flags().StringVar(&options.Description, "description", "", "Project description")
79+
cmd.Flags().BoolVar(&options.SkipConfigWrite, "skip-config-write", false, "If true, the project will not be set as a cluster entry in kubeconfig after being created")
7680

7781
return cmd
7882
}
@@ -86,10 +90,18 @@ func (o *NewProjectOptions) complete(cmd *cobra.Command, f *clientcmd.Factory) e
8690

8791
o.ProjectName = args[0]
8892

89-
o.ProjectOptions = &ProjectOptions{}
90-
o.ProjectOptions.PathOptions = cliconfig.NewPathOptions(cmd)
91-
if err := o.ProjectOptions.Complete(f, []string{""}, o.Out); err != nil {
92-
return err
93+
if !o.SkipConfigWrite {
94+
o.ProjectOptions = &ProjectOptions{}
95+
o.ProjectOptions.PathOptions = cliconfig.NewPathOptions(cmd)
96+
if err := o.ProjectOptions.Complete(f, []string{""}, o.Out); err != nil {
97+
return err
98+
}
99+
} else {
100+
clientConfig, err := f.OpenShiftClientConfig.ClientConfig()
101+
if err != nil {
102+
return err
103+
}
104+
o.Server = clientConfig.Host
93105
}
94106

95107
return nil
@@ -121,15 +133,22 @@ func (o *NewProjectOptions) Run() error {
121133
if err := o.ProjectOptions.RunProject(); err != nil {
122134
return err
123135
}
124-
}
125136

126-
fmt.Fprintf(o.Out, `
137+
fmt.Fprintf(o.Out, `
127138
You can add applications to this project with the 'new-app' command. For example, try:
128139
129140
%[1]s new-app centos/ruby-22-centos7~https://github.com/openshift/ruby-ex.git
130141
131142
to build a new example application in Ruby.
132143
`, o.Name)
144+
} else {
145+
fmt.Fprintf(o.Out, `Project %[2]q created on server %[3]q.
146+
147+
To switch to this project and start adding applications, use:
148+
149+
%[1]s project %[2]s
150+
`, o.Name, o.ProjectName, o.Server)
151+
}
133152

134153
return nil
135154
}

test/cmd/basicresources.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,4 +355,3 @@ echo "patch: ok"
355355
os::test::junit::declare_suite_end
356356

357357
os::test::junit::declare_suite_end
358-

test/cmd/projects.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,11 @@ os::cmd::expect_success_and_text 'oc projects' 'You are not a member of any proj
1717
# add a project and expect text for a single project
1818
os::cmd::expect_success_and_text 'oc new-project test4; sleep 2; oc projects' 'You have one project on this server: "test4".'
1919
os::cmd::expect_success_and_text 'oc new-project test5; sleep 2; oc projects' 'You have access'
20+
# test --skip-config-write
21+
os::cmd::expect_success_and_text 'oc new-project test6 --skip-config-write' 'To switch to this project and start adding applications, use'
22+
os::cmd::expect_failure 'oc config view | grep "namespace: test6"'
23+
os::cmd::expect_success 'sleep 2; oc projects | grep test6'
24+
os::cmd::expect_success_and_text 'oc project test6' 'Now using project "test6"'
25+
os::cmd::expect_success 'oc config view | grep "namespace: test6"'
2026
echo 'projects command ok'
2127
os::test::junit::declare_suite_end

0 commit comments

Comments
 (0)