Skip to content

Commit 74a6a14

Browse files
Merge pull request #19619 from deads2k/cli-33-prune
add oc adm prune role command to replace the existing reaper
2 parents d388176 + 73e6152 commit 74a6a14

File tree

21 files changed

+677
-293
lines changed

21 files changed

+677
-293
lines changed

contrib/completions/bash/oc

+55
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/completions/zsh/oc

+55
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/.files_generated_oc

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-adm-prune-auth.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hack/import-restrictions.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@
429429
"vendor/k8s.io/kubernetes/pkg/printers",
430430
"vendor/k8s.io/kubernetes/pkg/util",
431431
"vendor/k8s.io/utils",
432+
"vendor/github.com/davecgh/go-spew/spew",
432433

433434
"github.com/openshift/origin/pkg/apps/generated",
434435
"github.com/openshift/origin/pkg/authorization/generated",
@@ -457,7 +458,7 @@
457458
"github.com/openshift/origin/pkg/apps/client/v1",
458459
"github.com/openshift/origin/pkg/apps/util",
459460
"github.com/openshift/origin/pkg/authorization/apis/authorization",
460-
"github.com/openshift/origin/pkg/authorization/reaper",
461+
"github.com/openshift/origin/pkg/authorization/apis/authorization/install",
461462
"github.com/openshift/origin/pkg/authorization/registry/util",
462463
"github.com/openshift/origin/pkg/authorization/util",
463464
"github.com/openshift/origin/pkg/build/apis/build",
@@ -525,7 +526,6 @@
525526
"github.com/openshift/origin/pkg/unidling/util",
526527
"github.com/openshift/origin/pkg/user/apis/user",
527528
"github.com/openshift/origin/pkg/user/apis/user/install",
528-
"github.com/openshift/origin/pkg/user/reaper",
529529
"github.com/openshift/origin/pkg/util",
530530
"github.com/openshift/origin/pkg/util/docker/dockerfile",
531531
"github.com/openshift/origin/pkg/util/dot",

pkg/authorization/reaper/cluster_role.go

-61
This file was deleted.

pkg/authorization/reaper/role.go

-47
This file was deleted.

pkg/user/reaper/bindings.go pkg/oc/admin/prune/authprune/bindings.go

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
package reaper
1+
package authprune
22

33
import (
4-
"github.com/golang/glog"
4+
"fmt"
5+
"io"
6+
57
kerrors "k8s.io/apimachinery/pkg/api/errors"
68
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
79
kapi "k8s.io/kubernetes/pkg/apis/core"
@@ -10,10 +12,12 @@ import (
1012
)
1113

1214
// reapClusterBindings removes the subject from cluster-level role bindings
13-
func reapClusterBindings(removedSubject kapi.ObjectReference, c authclient.Interface) error {
15+
func reapClusterBindings(removedSubject kapi.ObjectReference, c authclient.Interface, out io.Writer) []error {
16+
errors := []error{}
17+
1418
clusterBindings, err := c.Authorization().ClusterRoleBindings().List(metav1.ListOptions{})
1519
if err != nil {
16-
return err
20+
return []error{err}
1721
}
1822
for _, binding := range clusterBindings.Items {
1923
retainedSubjects := []kapi.ObjectReference{}
@@ -26,18 +30,22 @@ func reapClusterBindings(removedSubject kapi.ObjectReference, c authclient.Inter
2630
updatedBinding := binding
2731
updatedBinding.Subjects = retainedSubjects
2832
if _, err := c.Authorization().ClusterRoleBindings().Update(&updatedBinding); err != nil && !kerrors.IsNotFound(err) {
29-
glog.Infof("Cannot update clusterrolebinding/%s: %v", binding.Name, err)
33+
errors = append(errors, err)
34+
} else {
35+
fmt.Fprintf(out, "clusterrolebinding.rbac.authorization.k8s.io/"+updatedBinding.Name+" updated\n")
3036
}
3137
}
3238
}
33-
return nil
39+
return errors
3440
}
3541

3642
// reapNamespacedBindings removes the subject from namespaced role bindings
37-
func reapNamespacedBindings(removedSubject kapi.ObjectReference, c authclient.Interface) error {
43+
func reapNamespacedBindings(removedSubject kapi.ObjectReference, c authclient.Interface, out io.Writer) []error {
44+
errors := []error{}
45+
3846
namespacedBindings, err := c.Authorization().RoleBindings(metav1.NamespaceAll).List(metav1.ListOptions{})
3947
if err != nil {
40-
return err
48+
return []error{err}
4149
}
4250
for _, binding := range namespacedBindings.Items {
4351
retainedSubjects := []kapi.ObjectReference{}
@@ -50,9 +58,11 @@ func reapNamespacedBindings(removedSubject kapi.ObjectReference, c authclient.In
5058
updatedBinding := binding
5159
updatedBinding.Subjects = retainedSubjects
5260
if _, err := c.Authorization().RoleBindings(binding.Namespace).Update(&updatedBinding); err != nil && !kerrors.IsNotFound(err) {
53-
glog.Infof("Cannot update rolebinding/%s in %s: %v", binding.Name, binding.Namespace, err)
61+
errors = append(errors, err)
62+
} else {
63+
fmt.Fprintf(out, "rolebinding.rbac.authorization.k8s.io/"+updatedBinding.Name+" updated\n")
5464
}
5565
}
5666
}
57-
return nil
67+
return errors
5868
}

0 commit comments

Comments
 (0)