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

Move project creation to use RBAC objects #15973

Merged
merged 1 commit into from
Sep 6, 2017

Conversation

simo5
Copy link
Contributor

@simo5 simo5 commented Aug 24, 2017

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
Copy link
Contributor

enj commented Aug 25, 2017

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

@simo5
Copy link
Contributor Author

simo5 commented Aug 25, 2017

/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
Copy link
Contributor Author

simo5 commented Aug 26, 2017

@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
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

@@ -142,9 +143,16 @@ func (r *REST) Create(ctx apirequest.Context, obj runtime.Object, includeUniniti
continue
}

// Check for new RBAS RoleBinding first
Copy link
Contributor

Choose a reason for hiding this comment

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

RBAC

@liggitt
Copy link
Contributor

liggitt commented Aug 27, 2017

nits, lgtm

@deads2k
Copy link
Contributor

deads2k commented Aug 28, 2017

/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
Copy link
Contributor Author

simo5 commented Aug 28, 2017

@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
Copy link
Contributor

@enj enj left a comment

Choose a reason for hiding this comment

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

Nits.

@@ -187,8 +195,8 @@ func (r *REST) Create(ctx apirequest.Context, obj runtime.Object, includeUniniti
}

// wait for a rolebinding if we created one
if lastRoleBinding != nil {
r.waitForRoleBinding(createdProject.Name, lastRoleBinding.Name)
if lastRoleBindingName != "" {
Copy link
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
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.

@@ -142,9 +143,16 @@ func (r *REST) Create(ctx apirequest.Context, obj runtime.Object, includeUniniti
continue
}

// Check for new RBAC RoleBinding first
if roleBinding, ok := list.Objects[i].(*rbac.RoleBinding); ok {
Copy link
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.

@@ -31,6 +31,7 @@ import (
"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
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
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
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)

@@ -14,6 +14,7 @@ import (
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
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
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
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?

@@ -133,18 +133,18 @@ func (r *REST) Create(ctx apirequest.Context, obj runtime.Object, includeUniniti

// one of the items in this list should be the project. We are going to locate it, remove it from the list, create it separately
var projectFromTemplate *projectapi.Project
var lastRoleBinding *authorizationapi.RoleBinding
lastRoleBindingName := ""
objectsToCreate := &kapi.List{}
for i := range list.Objects {
Copy link
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
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
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
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
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
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
Contributor

/retest

@simo5
Copy link
Contributor Author

simo5 commented Aug 31, 2017

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

@simo5
Copy link
Contributor Author

simo5 commented Aug 31, 2017

/retest

@enj
Copy link
Contributor

enj commented Aug 31, 2017

@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
Copy link
Contributor Author

simo5 commented Sep 6, 2017

@enj PTAL

@enj
Copy link
Contributor

enj commented Sep 6, 2017

/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
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.

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
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.

9 participants