Skip to content

Move project creation to use RBAC objects - #15973

Merged
openshift-merge-robot merged 1 commit into
openshift:masterfrom
simo5:newprjrbac
Sep 6, 2017
Merged

openshift-merge-robot merged 1 commit into
openshift:masterfrom
simo5:newprjrbac

Conversation

@simo5

@simo5 simo5 commented Aug 24, 2017

Copy link
Copy Markdown

Also move Service Account Project Role Bindings to RBAC objects

Fixes #15818
Fixes #15856

@openshift-merge-robot openshift-merge-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 24, 2017
@enj

enj commented Aug 25, 2017

Copy link
Copy Markdown
Contributor

You ran a generate script that added junk to your commit.

@simo5

simo5 commented Aug 25, 2017

Copy link
Copy Markdown
Author

/test cmd

@simo5
simo5 force-pushed the newprjrbac branch 2 times, most recently from 2980e12 to 6ebdbe4 Compare August 25, 2017 12:23
@simo5 simo5 changed the title Move project creation touse RBAC objects Move project creation to use RBAC objects Aug 25, 2017
@enj enj assigned liggitt and deads2k and unassigned mfojtik and dcbw Aug 25, 2017
@simo5
simo5 force-pushed the newprjrbac branch 2 times, most recently from c435189 to 222ab5d Compare August 26, 2017 01:15
@simo5

simo5 commented Aug 26, 2017

Copy link
Copy Markdown
Author

@enj PTAL

for _, rbacBinding := range bootstrappolicy.GetBootstrapServiceAccountProjectRoleBindings(namespace.Name) {
binding, err := authzregutil.RoleBindingFromRBAC(&rbacBinding)
if err != nil {
glog.Errorf("Could not convert Role Bindning %v n the %q namespace: %v\n", rbacBinding.Name, namespace.Name, err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Role Binding %v in

continue
}

// Check for new RBAS RoleBinding first

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

RBAC

@liggitt

liggitt commented Aug 27, 2017

Copy link
Copy Markdown
Contributor

nits, lgtm

@deads2k

deads2k commented Aug 28, 2017

Copy link
Copy Markdown
Contributor

/approve
/assign enj

@openshift-merge-robot openshift-merge-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 28, 2017
@simo5

simo5 commented Aug 28, 2017

Copy link
Copy Markdown
Author

@liggitt fixed nits

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 29, 2017
enj
enj previously requested changes Aug 29, 2017

@enj enj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nits.

// wait for a rolebinding if we created one
if lastRoleBinding != nil {
r.waitForRoleBinding(createdProject.Name, lastRoleBinding.Name)
if lastRoleBindingName != "" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

len(lastRoleBindingName) != 0 is the convention

if lastRoleBinding != nil {
r.waitForRoleBinding(createdProject.Name, lastRoleBinding.Name)
if lastRoleBindingName != "" {
r.waitForRoleBinding(createdProject.Name, lastRoleBindingName)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Update waitForRoleBinding to use Get instead of List.

}

// Check for new RBAC RoleBinding first
if roleBinding, ok := list.Objects[i].(*rbac.RoleBinding); ok {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Change this block to use a type switch since that what we are doing here with mutually exclusive if statements.

"github.com/openshift/origin/pkg/api/v1"
"github.com/openshift/origin/pkg/authorization/authorizer"
authorizationinformer "github.com/openshift/origin/pkg/authorization/generated/informers/internalversion"
authzregutil "github.com/openshift/origin/pkg/authorization/registry/util"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

authorizationregistryutil

for _, rbacBinding := range bootstrappolicy.GetBootstrapServiceAccountProjectRoleBindings(namespace.Name) {
binding, err := authzregutil.RoleBindingFromRBAC(&rbacBinding)
if err != nil {
glog.Errorf("Could not convert Role Binding %v n the %q namespace: %v\n", rbacBinding.Name, namespace.Name, err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

glog.Errorf("Could not convert Role Binding %s in the %q namespace: %v", rbacBinding.Name, namespace.Name, err)

for _, rbacBinding := range bootstrappolicy.GetBootstrapServiceAccountProjectRoleBindings(o.ProjectName) {
binding, err := authzregutil.RoleBindingFromRBAC(&rbacBinding)
if err != nil {
errs = append(errs, err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fmt.Printf("Could not convert Role Binding %s in the %q namespace: %v\n", rbacBinding.Name, o.ProjectName, err)

Comment thread pkg/oc/admin/project/new_project.go Outdated
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"

oapi "github.com/openshift/origin/pkg/api"
authzregutil "github.com/openshift/origin/pkg/authorization/registry/util"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

authorizationregistryutil

@simo5
simo5 dismissed enj’s stale review August 29, 2017 19:36

nits addressed

@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 29, 2017
enj
enj previously requested changes Aug 29, 2017

return false, nil
_, err := r.roleBindings.RoleBindings(namespace).Get(name)
return (err == nil), nil

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why the redundant parentheses?

@liggitt there wasn't some archaic reason this was using list before right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe the lister we implemented for the virtual resources didn't implement Get?

var lastRoleBinding *authorizationapi.RoleBinding
lastRoleBindingName := ""
objectsToCreate := &kapi.List{}
for i := range list.Objects {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

for _, lobj := range list.Objects {
	switch t := lobj.(type) {
	case *projectapi.Project:
		projectFromTemplate = t
		// don't add this to the list to create.  We'll create the project separately.
		continue
	case *rbac.RoleBinding:
		lastRoleBindingName = t.Name
	case *authorizationapi.RoleBinding:
		lastRoleBindingName = t.Name
	default:
		// no-op we only skip creation of project
	}

	objectsToCreate.Items = append(objectsToCreate.Items, lobj)
}

@liggitt any reason we were doing list.Objects[i] before? Also, do we want to error if we see more than one project in the template?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@liggitt any reason we were doing list.Objects[i] before?

so we didn't have to reason about range variable reuse outside the loop

Also, do we want to error if we see more than one project in the template?

probably

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so we didn't have to reason about range variable reuse outside the loop

At worst it would only shadow a var outside the loop (I picked a unique name to avoid that as well)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

at worst, you'd reuse a memory address and actually append the same item to the list of items to create N times

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

at worst, you'd reuse a memory address and actually append the same item to the list of items to create N times

Ah you are correct, I always forget the "don't use range vars + append together".

for i := range list.Objects {
	switch t := list.Objects[i].(type) {
	case *projectapi.Project:
		projectFromTemplate = t
		// don't add this to the list to create.  We'll create the project separately.
		continue
	case *rbac.RoleBinding:
		lastRoleBindingName = t.Name
	case *authorizationapi.RoleBinding:
		lastRoleBindingName = t.Name
	default:
		// no-op we only skip creation of project
	}
	// use list.Objects[i] in append to avoid range memory address reuse
	objectsToCreate.Items = append(objectsToCreate.Items, list.Objects[i])
}

for _, rbacBinding := range bootstrappolicy.GetBootstrapServiceAccountProjectRoleBindings(namespace.Name) {
binding, err := authorizationregistryutil.RoleBindingFromRBAC(&rbacBinding)
if err != nil {
glog.Errorf("Could not convert Role Binding %v n the %q namespace: %v\n", rbacBinding.Name, namespace.Name, err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is still wrong.

@simo5
simo5 dismissed enj’s stale review August 30, 2017 13:26

Should have addressed the additional nits

@dobbymoodge

Copy link
Copy Markdown
Contributor

/retest

@simo5

simo5 commented Aug 31, 2017

Copy link
Copy Markdown
Author

Still seeing this flake even if it has been closed #14575

@simo5

simo5 commented Aug 31, 2017

Copy link
Copy Markdown
Author

/retest

@enj

enj commented Aug 31, 2017

Copy link
Copy Markdown
Contributor

@simo5 clean up the type switch and have it fail on multiple projects.

Also move Service Account Project Role Bindings to RBAC objects

Signed-off-by: Simo Sorce <[email protected]>
@simo5

simo5 commented Sep 6, 2017

Copy link
Copy Markdown
Author

@enj PTAL

@enj

enj commented Sep 6, 2017

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 6, 2017
@openshift-merge-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: deads2k, enj, simo5

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@openshift-merge-robot

Copy link
Copy Markdown
Contributor

Automatic merge from submit-queue (batch tested with PRs 15885, 15973, 16000)

@openshift-merge-robot
openshift-merge-robot merged commit 14ebc56 into openshift:master Sep 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants