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

add oc adm prune role command to replace the existing reaper #19619

Merged
merged 2 commits into from
May 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions contrib/completions/bash/oc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions contrib/completions/zsh/oc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/man/man1/.files_generated_oc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-prune-auth.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions hack/import-restrictions.json
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@
"vendor/k8s.io/kubernetes/pkg/printers",
"vendor/k8s.io/kubernetes/pkg/util",
"vendor/k8s.io/utils",
"vendor/github.com/davecgh/go-spew/spew",

"github.com/openshift/origin/pkg/apps/generated",
"github.com/openshift/origin/pkg/authorization/generated",
Expand Down Expand Up @@ -457,7 +458,7 @@
"github.com/openshift/origin/pkg/apps/client/v1",
"github.com/openshift/origin/pkg/apps/util",
"github.com/openshift/origin/pkg/authorization/apis/authorization",
"github.com/openshift/origin/pkg/authorization/reaper",
"github.com/openshift/origin/pkg/authorization/apis/authorization/install",
"github.com/openshift/origin/pkg/authorization/registry/util",
"github.com/openshift/origin/pkg/authorization/util",
"github.com/openshift/origin/pkg/build/apis/build",
Expand Down Expand Up @@ -525,7 +526,6 @@
"github.com/openshift/origin/pkg/unidling/util",
"github.com/openshift/origin/pkg/user/apis/user",
"github.com/openshift/origin/pkg/user/apis/user/install",
"github.com/openshift/origin/pkg/user/reaper",
"github.com/openshift/origin/pkg/util",
"github.com/openshift/origin/pkg/util/docker/dockerfile",
"github.com/openshift/origin/pkg/util/dot",
Expand Down
61 changes: 0 additions & 61 deletions pkg/authorization/reaper/cluster_role.go

This file was deleted.

47 changes: 0 additions & 47 deletions pkg/authorization/reaper/role.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package reaper
package authprune

import (
"github.com/golang/glog"
"fmt"
"io"

kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kapi "k8s.io/kubernetes/pkg/apis/core"
Expand All @@ -10,10 +12,12 @@ import (
)

// reapClusterBindings removes the subject from cluster-level role bindings
func reapClusterBindings(removedSubject kapi.ObjectReference, c authclient.Interface) error {
func reapClusterBindings(removedSubject kapi.ObjectReference, c authclient.Interface, out io.Writer) []error {
errors := []error{}

clusterBindings, err := c.Authorization().ClusterRoleBindings().List(metav1.ListOptions{})
if err != nil {
return err
return []error{err}
}
for _, binding := range clusterBindings.Items {
retainedSubjects := []kapi.ObjectReference{}
Expand All @@ -26,18 +30,22 @@ func reapClusterBindings(removedSubject kapi.ObjectReference, c authclient.Inter
updatedBinding := binding
updatedBinding.Subjects = retainedSubjects
if _, err := c.Authorization().ClusterRoleBindings().Update(&updatedBinding); err != nil && !kerrors.IsNotFound(err) {
glog.Infof("Cannot update clusterrolebinding/%s: %v", binding.Name, err)
errors = append(errors, err)
} else {
fmt.Fprintf(out, "clusterrolebinding.rbac.authorization.k8s.io/"+updatedBinding.Name+" updated\n")
}
}
}
return nil
return errors
}

// reapNamespacedBindings removes the subject from namespaced role bindings
func reapNamespacedBindings(removedSubject kapi.ObjectReference, c authclient.Interface) error {
func reapNamespacedBindings(removedSubject kapi.ObjectReference, c authclient.Interface, out io.Writer) []error {
errors := []error{}

namespacedBindings, err := c.Authorization().RoleBindings(metav1.NamespaceAll).List(metav1.ListOptions{})
if err != nil {
return err
return []error{err}
}
for _, binding := range namespacedBindings.Items {
retainedSubjects := []kapi.ObjectReference{}
Expand All @@ -50,9 +58,11 @@ func reapNamespacedBindings(removedSubject kapi.ObjectReference, c authclient.In
updatedBinding := binding
updatedBinding.Subjects = retainedSubjects
if _, err := c.Authorization().RoleBindings(binding.Namespace).Update(&updatedBinding); err != nil && !kerrors.IsNotFound(err) {
glog.Infof("Cannot update rolebinding/%s in %s: %v", binding.Name, binding.Namespace, err)
errors = append(errors, err)
} else {
fmt.Fprintf(out, "rolebinding.rbac.authorization.k8s.io/"+updatedBinding.Name+" updated\n")
}
}
}
return nil
return errors
}
Loading