Skip to content

Commit

Permalink
Merge pull request kubernetes#20177 from deads2k/rbac-02-v1revert
Browse files Browse the repository at this point in the history
Collapse back to upstream reconcile command

Origin-commit: dab335cdf67c7cc29be8d7206583952dc447e033
  • Loading branch information
k8s-publishing-bot authored and OpenShift Publisher committed Jul 11, 2018
2 parents 35ba2a0 + 584a5ae commit cdab945
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
3 changes: 3 additions & 0 deletions hack/make-rules/test-cmd-util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5549,6 +5549,9 @@ runTests() {
kube::test::get_object_assert 'clusterrolebindings -l test-cmd=auth' "{{range.items}}{{$id_field}}:{{end}}" 'testing-CRB:'
kube::test::get_object_assert 'clusterroles -l test-cmd=auth' "{{range.items}}{{$id_field}}:{{end}}" 'testing-CR:'

failure_message=$(! kubectl auth reconcile "${kube_flags[@]}" -f test/fixtures/pkg/kubectl/cmd/auth/rbac-v1beta1.yaml 2>&1 )
kube::test::if_has_string "${failure_message}" 'only rbac.authorization.k8s.io/v1 is supported'

kubectl delete "${kube_flags[@]}" rolebindings,role,clusterroles,clusterrolebindings -n some-other-random -l test-cmd=auth
fi

Expand Down
25 changes: 15 additions & 10 deletions pkg/kubectl/cmd/auth/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ import (
"github.com/spf13/cobra"

rbacv1 "k8s.io/api/rbac/v1"
rbacv1beta1 "k8s.io/api/rbac/v1beta1"
rbacv1alpha1 "k8s.io/api/rbac/v1alpha1"
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
rbacv1client "k8s.io/client-go/kubernetes/typed/rbac/v1"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/printers"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/resource"
"k8s.io/kubernetes/pkg/kubectl/scheme"
"k8s.io/kubernetes/pkg/registry/rbac/reconciliation"
"fmt"
)

// ReconcileOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of
Expand Down Expand Up @@ -106,7 +108,7 @@ func (o *ReconcileOptions) Complete(cmd *cobra.Command, f cmdutil.Factory, args
}

r := f.NewBuilder().
WithScheme(legacyscheme.Scheme).
WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).
ContinueOnError().
NamespaceParam(namespace).DefaultNamespace().
FilenameParam(enforceNamespace, o.FilenameOptions).
Expand Down Expand Up @@ -171,14 +173,7 @@ func (o *ReconcileOptions) RunReconcile() error {
return err
}

obj, err := legacyscheme.Scheme.ConvertToVersion(info.Object, rbacv1.SchemeGroupVersion)
if err != nil {
glog.V(1).Infof("skipping %#v", info.Object.GetObjectKind())
// skip ignored resources
return nil
}

switch t := obj.(type) {
switch t := info.Object.(type) {
case *rbacv1.Role:
reconcileOptions := reconciliation.ReconcileRoleOptions{
Confirm: !o.DryRun,
Expand Down Expand Up @@ -241,6 +236,16 @@ func (o *ReconcileOptions) RunReconcile() error {
}
o.PrintObject(result.RoleBinding.GetObject(), o.Out)

case *rbacv1beta1.Role,
*rbacv1beta1.RoleBinding,
*rbacv1beta1.ClusterRole,
*rbacv1beta1.ClusterRoleBinding,
*rbacv1alpha1.Role,
*rbacv1alpha1.RoleBinding,
*rbacv1alpha1.ClusterRole,
*rbacv1alpha1.ClusterRoleBinding:
return fmt.Errorf("only rbac.authorization.k8s.io/v1 is supported: not %T", t)

default:
glog.V(1).Infof("skipping %#v", info.Object.GetObjectKind())
// skip ignored resources
Expand Down
25 changes: 25 additions & 0 deletions test/fixtures/pkg/kubectl/cmd/auth/rbac-v1beta1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: v1
items:
- apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
labels:
test-cmd: auth
name: testing-CR
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- create
- delete
- deletecollection
- get
- list
- patch
- update
- watch

kind: List
metadata: {}

0 comments on commit cdab945

Please sign in to comment.