| ... | ... |
@@ -32,6 +32,9 @@ type ProjectOptions struct {
|
| 32 | 32 |
ProjectName string |
| 33 | 33 |
ProjectOnly bool |
| 34 | 34 |
DisplayShort bool |
| 35 |
+ |
|
| 36 |
+ // SkipAccessValidation means that if a specific name is requested, don't bother checking for access to the project |
|
| 37 |
+ SkipAccessValidation bool |
|
| 35 | 38 |
} |
| 36 | 39 |
|
| 37 | 40 |
const ( |
| ... | ... |
@@ -177,40 +180,43 @@ func (o ProjectOptions) RunProject() error {
|
| 177 | 177 |
config.CurrentContext = argument |
| 178 | 178 |
|
| 179 | 179 |
} else {
|
| 180 |
- project, err := o.Client.Projects().Get(argument) |
|
| 181 |
- if err != nil {
|
|
| 182 |
- if isNotFound, isForbidden := kapierrors.IsNotFound(err), clientcmd.IsForbidden(err); isNotFound || isForbidden {
|
|
| 183 |
- var msg string |
|
| 184 |
- if isForbidden {
|
|
| 185 |
- msg = fmt.Sprintf("You are not a member of project %q.", argument)
|
|
| 186 |
- } else {
|
|
| 187 |
- msg = fmt.Sprintf("A project named %q does not exist on %q.", argument, clientCfg.Host)
|
|
| 188 |
- } |
|
| 180 |
+ if !o.SkipAccessValidation {
|
|
| 181 |
+ _, err := o.Client.Projects().Get(argument) |
|
| 182 |
+ if err != nil {
|
|
| 183 |
+ if isNotFound, isForbidden := kapierrors.IsNotFound(err), clientcmd.IsForbidden(err); isNotFound || isForbidden {
|
|
| 184 |
+ var msg string |
|
| 185 |
+ if isForbidden {
|
|
| 186 |
+ msg = fmt.Sprintf("You are not a member of project %q.", argument)
|
|
| 187 |
+ } else {
|
|
| 188 |
+ msg = fmt.Sprintf("A project named %q does not exist on %q.", argument, clientCfg.Host)
|
|
| 189 |
+ } |
|
| 189 | 190 |
|
| 190 |
- projects, err := getProjects(o.Client) |
|
| 191 |
- if err == nil {
|
|
| 192 |
- switch len(projects) {
|
|
| 193 |
- case 0: |
|
| 194 |
- msg += "\nYou are not a member of any projects. You can request a project to be created with the 'new-project' command." |
|
| 195 |
- case 1: |
|
| 196 |
- msg += fmt.Sprintf("\nYou have one project on this server: %s", api.DisplayNameAndNameForProject(&projects[0]))
|
|
| 197 |
- default: |
|
| 198 |
- msg += "\nYour projects are:" |
|
| 199 |
- for _, project := range projects {
|
|
| 200 |
- msg += fmt.Sprintf("\n* %s", api.DisplayNameAndNameForProject(&project))
|
|
| 191 |
+ projects, err := getProjects(o.Client) |
|
| 192 |
+ if err == nil {
|
|
| 193 |
+ switch len(projects) {
|
|
| 194 |
+ case 0: |
|
| 195 |
+ msg += "\nYou are not a member of any projects. You can request a project to be created with the 'new-project' command." |
|
| 196 |
+ case 1: |
|
| 197 |
+ msg += fmt.Sprintf("\nYou have one project on this server: %s", api.DisplayNameAndNameForProject(&projects[0]))
|
|
| 198 |
+ default: |
|
| 199 |
+ msg += "\nYour projects are:" |
|
| 200 |
+ for _, project := range projects {
|
|
| 201 |
+ msg += fmt.Sprintf("\n* %s", api.DisplayNameAndNameForProject(&project))
|
|
| 202 |
+ } |
|
| 201 | 203 |
} |
| 202 | 204 |
} |
| 203 |
- } |
|
| 204 | 205 |
|
| 205 |
- if hasMultipleServers(config) {
|
|
| 206 |
- msg += "\nTo see projects on another server, pass '--server=<server>'." |
|
| 206 |
+ if hasMultipleServers(config) {
|
|
| 207 |
+ msg += "\nTo see projects on another server, pass '--server=<server>'." |
|
| 208 |
+ } |
|
| 209 |
+ return errors.New(msg) |
|
| 207 | 210 |
} |
| 208 |
- return errors.New(msg) |
|
| 211 |
+ return err |
|
| 209 | 212 |
} |
| 210 |
- return err |
|
| 211 | 213 |
} |
| 214 |
+ projectName := argument |
|
| 212 | 215 |
|
| 213 |
- kubeconfig, err := cliconfig.CreateConfig(project.Name, o.ClientConfig) |
|
| 216 |
+ kubeconfig, err := cliconfig.CreateConfig(projectName, o.ClientConfig) |
|
| 214 | 217 |
if err != nil {
|
| 215 | 218 |
return err |
| 216 | 219 |
} |
| ... | ... |
@@ -221,7 +227,7 @@ func (o ProjectOptions) RunProject() error {
|
| 221 | 221 |
} |
| 222 | 222 |
config = *merged |
| 223 | 223 |
|
| 224 |
- namespaceInUse = project.Name |
|
| 224 |
+ namespaceInUse = projectName |
|
| 225 | 225 |
contextInUse = merged.CurrentContext |
| 226 | 226 |
contextNameIsGenerated = true |
| 227 | 227 |
} |
| ... | ... |
@@ -114,6 +114,7 @@ func (o *NewProjectOptions) Run() error {
|
| 114 | 114 |
if o.ProjectOptions != nil {
|
| 115 | 115 |
o.ProjectOptions.ProjectName = project.Name |
| 116 | 116 |
o.ProjectOptions.ProjectOnly = true |
| 117 |
+ o.ProjectOptions.SkipAccessValidation = true |
|
| 117 | 118 |
|
| 118 | 119 |
if err := o.ProjectOptions.RunProject(); err != nil {
|
| 119 | 120 |
return err |