Skip to content

Commit

Permalink
Merge pull request #19619 from deads2k/cli-33-prune
Browse files Browse the repository at this point in the history
add oc adm prune role command to replace the existing reaper
  • Loading branch information
openshift-merge-robot authored May 10, 2018
2 parents d388176 + 73e6152 commit 74a6a14
Show file tree
Hide file tree
Showing 21 changed files with 677 additions and 293 deletions.
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

0 comments on commit 74a6a14

Please sign in to comment.