Skip to content

Commit

Permalink
select an RBAC version for kubefed it knows how to speak
Browse files Browse the repository at this point in the history
  • Loading branch information
liggitt committed Aug 11, 2017
1 parent 92d9e44 commit 7f1a617
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
3 changes: 3 additions & 0 deletions federation/pkg/kubefed/util/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ go_library(
"//federation/client/clientset_generated/federation_clientset:go_default_library",
"//pkg/api:go_default_library",
"//pkg/apis/rbac:go_default_library",
"//pkg/apis/rbac/v1:go_default_library",
"//pkg/apis/rbac/v1alpha1:go_default_library",
"//pkg/apis/rbac/v1beta1:go_default_library",
"//pkg/client/clientset_generated/internalclientset:go_default_library",
"//pkg/kubectl/cmd:go_default_library",
"//pkg/kubectl/cmd/util:go_default_library",
Expand Down
27 changes: 25 additions & 2 deletions federation/pkg/kubefed/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import (
fedclient "k8s.io/kubernetes/federation/client/clientset_generated/federation_clientset"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/rbac"
rbacv1 "k8s.io/kubernetes/pkg/apis/rbac/v1"
rbacv1alpha1 "k8s.io/kubernetes/pkg/apis/rbac/v1alpha1"
rbacv1beta1 "k8s.io/kubernetes/pkg/apis/rbac/v1beta1"
client "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
kubectlcmd "k8s.io/kubernetes/pkg/kubectl/cmd"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
Expand Down Expand Up @@ -285,27 +288,47 @@ func getRBACVersion(discoveryclient discovery.CachedDiscoveryInterface) (*schema
return nil, fmt.Errorf("Couldn't get clientset to create RBAC roles in the host cluster: %v", err)
}

// These are the RBAC versions we can speak
knownVersions := map[schema.GroupVersion]bool{
rbacv1.SchemeGroupVersion: true,
rbacv1alpha1.SchemeGroupVersion: true,
rbacv1beta1.SchemeGroupVersion: true,
}

// This holds any RBAC versions listed in discovery we do not know how to speak
unknownVersions := []schema.GroupVersion{}

for _, g := range groupList.Groups {
if g.Name == rbac.GroupName {
if g.PreferredVersion.GroupVersion != "" {
gv, err := schema.ParseGroupVersion(g.PreferredVersion.GroupVersion)
if err != nil {
return nil, err
}
return &gv, nil
if knownVersions[gv] {
return &gv, nil
}
}
for _, version := range g.Versions {
if version.GroupVersion != "" {
gv, err := schema.ParseGroupVersion(version.GroupVersion)
if err != nil {
return nil, err
}
return &gv, nil
if knownVersions[gv] {
return &gv, nil
} else {
unknownVersions = append(unknownVersions, gv)
}
}
}
}
}

if len(unknownVersions) > 0 {
return nil, &NoRBACAPIError{fmt.Sprintf("%s\nUnknown RBAC API versions: %v", rbacAPINotAvailable, unknownVersions)}
}

return nil, &NoRBACAPIError{rbacAPINotAvailable}
}

Expand Down

0 comments on commit 7f1a617

Please sign in to comment.