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

Update "no projects" warning in oc status #12328

Merged

Conversation

juanvallejo
Copy link
Contributor

Related bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1405636#c3
Related PR: #12304

This patch only re-uses the oc login "no projects" warning in
oc status when a user cannot access the current default namespace
and has not yet created any projects and has not passed a namespace
value with the --namespace flag.

Before

$ oc login -u newuser -p any
$ oc status
You don't have any projects. You can try to create a new project, by
running

    oc new-project <projectname>

$ oc status -n default
You don't have any projects. You can try to create a new project, by
running

    oc new-project <projectname>

After

$ oc login -u newuser -p any
$ oc status
You don't have any projects. You can try to create a new project, by
running

    oc new-project <projectname>

$ oc status -n default
Error from server: User "newuser" cannot get projects in project "default"

$ oc new-project proj1
$ oc new-project proj2

$ oc status
In project proj2 on server https://10.13.137.149:8443

You have no services, deployment configs, or build configs.
Run 'oc new-app' to create an application.

$ oc delete project proj2
$ oc status
Error from server: User "newuser" cannot get projects in project "proj2"

$ oc logout
$ oc login -u newuser -p any
$ oc status
In project proj1 on server https://10.13.137.149:8443

You have no services, deployment configs, or build configs.
Run 'oc new-app' to create an application.

cc @openshift/cli-review

@juanvallejo
Copy link
Contributor Author

[test]

@juanvallejo juanvallejo force-pushed the jvallejo/update-oc-status-warning branch from 2505358 to 94cb181 Compare December 22, 2016 19:19
@smarterclayton
Copy link
Contributor

$ oc status -n default
Error from server: User "newuser" cannot get projects in project "default"

Does not make sense. Projects aren't nested in projects.

@juanvallejo
Copy link
Contributor Author

@smarterclayton I believe this is an error defined server-side in the authorizer package.

Would it make more sense to change User ... cannot {{verb}} {{resourceName}} in project ... to User ... cannot {{verb}} {{resourceName}} in namespace ... for each of the calls to messageResolver.addNamespacedForbiddenMessageMaker?

@juanvallejo
Copy link
Contributor Author

@smarterclayton

Would it make more sense to change User ... cannot {{verb}} {{resourceName}} in project ... to User ... cannot {{verb}} {{resourceName}} in namespace ... for each of the calls to messageResolver.addNamespacedForbiddenMessageMaker?

Alternatively we could just handle the forbidden error client side and return a more user-friendly message here

@smarterclayton
Copy link
Contributor

The error you are seeing cannot be correct - projects are not nested in projects, so whatever is putting that message together is doing so incorrectly. If that's the server, the server should be fixed.

@juanvallejo juanvallejo force-pushed the jvallejo/update-oc-status-warning branch 2 times, most recently from e2af29a to f3283ca Compare January 11, 2017 16:36
@juanvallejo
Copy link
Contributor Author

juanvallejo commented Jan 11, 2017

@smarterclayton

The error you are seeing cannot be correct - projects are not nested in projects, so whatever is putting that message together is doing so incorrectly. If that's the server, the server should be fixed.

Updated a conditional to authorizer messages to fix this: https://github.com/openshift/origin/pull/12328/files#diff-14287a8c63a62966ec50b251f590618d

EDIT: updated output

$ oc status -n default
Error from server: User "newuser" cannot get project "default"

@juanvallejo juanvallejo force-pushed the jvallejo/update-oc-status-warning branch from f3283ca to 31eae66 Compare January 11, 2017 18:17
@@ -30,17 +30,17 @@ func NewForbiddenMessageResolver(projectRequestForbiddenTemplate string) *Forbid
}

// general messages
messageResolver.addNamespacedForbiddenMessageMaker("create", authorizationapi.ResourceAll, newTemplateForbiddenMessageMaker(`User "{{.User.GetName}}" cannot create `+apiGroupIfNotEmpty+`{{.Attributes.GetResource}} in project "{{.Namespace}}"`))
messageResolver.addNamespacedForbiddenMessageMaker("create", authorizationapi.ResourceAll, newTemplateForbiddenMessageMaker(`User "{{.User.GetName}}" cannot create `+apiGroupIfNotEmpty+`{{if not .Attributes.IsProjectResource}}{{.Attributes.GetResource}} in {{end}}project "{{.Namespace}}"`))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't even make sense - projects aren't namspaced, why is GetResource a project resource?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.IsProjectResource needs better phrasing (I will update this), but I did not mean for it to imply that GetResource was a project resource, rather IsProjectResource returns true if the string value of Attributes.GetResource == "projects"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this is messageResolver.addNamespacedForbiddenMessageMaker - why is create projects getting passed to this? Since projects is never invoked in a namespaced context, I wouldn't expect this message to get used at all (it should be a different message without referencing projects or namespaces at all).

@juanvallejo
Copy link
Contributor Author

@smarterclayton
Updated the conditional statement in authorizer messages to make more sense: https://github.com/openshift/origin/pull/12328/files#diff-14287a8c63a62966ec50b251f590618d

@juanvallejo juanvallejo force-pushed the jvallejo/update-oc-status-warning branch 2 times, most recently from a300229 to e571ad8 Compare January 12, 2017 17:11
@juanvallejo
Copy link
Contributor Author

@smarterclayton

But this is messageResolver.addNamespacedForbiddenMessageMaker - why is create projects getting passed to this? Since projects is never invoked in a namespaced context, I wouldn't expect this message to get used at all (it should be a different message without referencing projects or namespaces at all).

Updated authorizer messages so that only "get" requests for the "projects" resource have this custom message. "Projects" are both namespaced and non-namespaced in the authorizer depending on where they are on the stack to allow for better handling of "get" requests. cc @deads2k

@juanvallejo juanvallejo force-pushed the jvallejo/update-oc-status-warning branch 2 times, most recently from 7a43510 to bb1a3b8 Compare January 12, 2017 21:19
@@ -146,6 +149,11 @@ func (d *ProjectStatusDescriber) MakeGraph(namespace string) (osgraph.Graph, set
// Describe returns the description of a project
func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error) {
var f formatter = namespacedFormatter{}
var currentProject string

if currentContext, exists := d.Config.Contexts[d.Config.CurrentContext]; exists {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just looking at all this code, it is increasingly complex and not really the right point to be doing the check. Describe() knowing about ClientConfig in this way is leaking the abstraction. You already get "default namespace or not" from the bool returned the .Namespace() call. Line 114 above.

@juanvallejo
Copy link
Contributor Author

@smarterclayton Thanks for the feedback, review comments addressed

@juanvallejo juanvallejo force-pushed the jvallejo/update-oc-status-warning branch 2 times, most recently from 9ba087b to 7811df8 Compare January 16, 2017 15:23
@juanvallejo
Copy link
Contributor Author

@smarterclayton or @fabianofranz are there any more comments on this patch? Thanks!

@juanvallejo
Copy link
Contributor Author

conformance flaked on #12362 re[test]

@juanvallejo juanvallejo force-pushed the jvallejo/update-oc-status-warning branch 5 times, most recently from c129637 to 03de650 Compare January 18, 2017 20:21
@juanvallejo
Copy link
Contributor Author

integration e2e check flaked on #12540 re[test]

@juanvallejo
Copy link
Contributor Author

@fabianofranz or @smarterclayton are there any more comments for this PR? Thanks

@fabianofranz
Copy link
Member

LGTM, squash?

@juanvallejo juanvallejo force-pushed the jvallejo/update-oc-status-warning branch from 03de650 to 62299d5 Compare January 20, 2017 15:43
@juanvallejo
Copy link
Contributor Author

@fabianofranz Done!

@fabianofranz
Copy link
Member

[merge]

@juanvallejo juanvallejo force-pushed the jvallejo/update-oc-status-warning branch from 62299d5 to 870d269 Compare January 23, 2017 19:00
@juanvallejo
Copy link
Contributor Author

integration check flaked on #12558 re[test]

@fabianofranz
Copy link
Member

flaked on #12558 re[test]

@fabianofranz
Copy link
Member

[merge]

@fabianofranz
Copy link
Member

@juanvallejo Test failure seems legit, ptal. You may need to delete the project by name, instead of --all.

@juanvallejo juanvallejo force-pushed the jvallejo/update-oc-status-warning branch from 870d269 to b1b51fa Compare January 24, 2017 16:15
This patch only re-uses the `oc login` "no projects" warning in
`oc status` when a user cannot access the current default namespace
and has not yet created any projects and has not passed a namespace
value with the `--namespace` flag.

**Before**
```
$ oc login -u newuser -p any
$ oc status
You don't have any projects. You can try to create a new project, by
running

    oc new-project <projectname>

$ oc status -n default
You don't have any projects. You can try to create a new project, by
running

    oc new-project <projectname>
```

**After**
```
$ oc login -u newuser -p any
$ oc status
You don't have any projects. You can try to create a new project, by
running

    oc new-project <projectname>

$ oc status -n default
Error from server: User "newuser" cannot get projects in project "default"

$ oc new-project proj1
$ oc new-project proj2

$ oc status
In project proj2 on server https://10.13.137.149:8443

You have no services, deployment configs, or build configs.
Run 'oc new-app' to create an application.

$ oc delete project proj2
$ oc status
Error from server: User "newuser" cannot get projects in project "proj2"

$ oc logout
$ oc login -u newuser -p any
$ oc status
In project proj1 on server https://10.13.137.149:8443

You have no services, deployment configs, or build configs.
Run 'oc new-app' to create an application.
```
@juanvallejo juanvallejo force-pushed the jvallejo/update-oc-status-warning branch from b1b51fa to 9cfc359 Compare January 24, 2017 16:18
@juanvallejo
Copy link
Contributor Author

@fabianofranz thanks, turns out I was not waiting for projects to be deleted, so when I tried deleting a new project right after deleting a previous one, I would get a forbidden error.

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to 9cfc359

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/13249/) (Base Commit: c5868ac)

@fabianofranz
Copy link
Member

[merge]

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to 9cfc359

@openshift-bot
Copy link
Contributor

openshift-bot commented Jan 25, 2017

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/13249/) (Base Commit: dced7f7) (Image: devenv-rhel7_5774)

@openshift-bot openshift-bot merged commit 7708f39 into openshift:master Jan 25, 2017
@juanvallejo juanvallejo deleted the jvallejo/update-oc-status-warning branch January 25, 2017 15:07
@smarterclayton
Copy link
Contributor

Looks like it is, I'm reverting.

juanvallejo added a commit to juanvallejo/origin that referenced this pull request Jan 26, 2017
juanvallejo added a commit to juanvallejo/origin that referenced this pull request Jan 26, 2017
juanvallejo added a commit to juanvallejo/origin that referenced this pull request Jan 26, 2017
juanvallejo added a commit to juanvallejo/origin that referenced this pull request Jan 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants