提交 aa2e388c 编写于 作者: Z ZeHuaiWang 提交者: Kubernetes Prow Robot

add list/detail for roleBinding and clusterRoleBinding resource (#4496)

* add list/detail for rolebinding resource

* update

* update

* update

* update

* update

* update

* update

* add detail/list for clusterRoleBinding

* add detail/list for clusterRoleBinding
上级 c2c47f26
......@@ -137,7 +137,9 @@ const (
ResourceKindStatefulSet = "statefulset"
ResourceKindStorageClass = "storageclass"
ResourceKindClusterRole = "clusterrole"
ResourceKindClusterRoleBinding = "clusterrolebinding"
ResourceKindRole = "role"
ResourceKindRoleBinding = "rolebinding"
ResourceKindPlugin = "plugin"
ResourceKindEndpoint = "endpoint"
)
......
......@@ -32,6 +32,7 @@ import (
"github.com/kubernetes/dashboard/src/app/backend/errors"
"github.com/kubernetes/dashboard/src/app/backend/integration"
"github.com/kubernetes/dashboard/src/app/backend/resource/clusterrole"
"github.com/kubernetes/dashboard/src/app/backend/resource/clusterrolebinding"
"github.com/kubernetes/dashboard/src/app/backend/resource/common"
"github.com/kubernetes/dashboard/src/app/backend/resource/configmap"
"github.com/kubernetes/dashboard/src/app/backend/resource/container"
......@@ -54,6 +55,7 @@ import (
"github.com/kubernetes/dashboard/src/app/backend/resource/replicaset"
"github.com/kubernetes/dashboard/src/app/backend/resource/replicationcontroller"
"github.com/kubernetes/dashboard/src/app/backend/resource/role"
"github.com/kubernetes/dashboard/src/app/backend/resource/rolebinding"
"github.com/kubernetes/dashboard/src/app/backend/resource/secret"
resourceService "github.com/kubernetes/dashboard/src/app/backend/resource/service"
"github.com/kubernetes/dashboard/src/app/backend/resource/statefulset"
......@@ -517,6 +519,15 @@ func CreateHTTPAPIHandler(iManager integration.IntegrationManager, cManager clie
To(apiHandler.handleGetClusterRoleDetail).
Writes(clusterrole.ClusterRoleDetail{}))
apiV1Ws.Route(
apiV1Ws.GET("/clusterrolebinding").
To(apiHandler.handleGetClusterRoleBindingList).
Writes(clusterrolebinding.ClusterRoleBindingList{}))
apiV1Ws.Route(
apiV1Ws.GET("/clusterrolebinding/{name}").
To(apiHandler.handleGetClusterRoleBindingDetail).
Writes(clusterrolebinding.ClusterRoleBindingDetail{}))
apiV1Ws.Route(
apiV1Ws.GET("/role/{namespace}").
To(apiHandler.handleGetRoleList).
......@@ -526,6 +537,15 @@ func CreateHTTPAPIHandler(iManager integration.IntegrationManager, cManager clie
To(apiHandler.handleGetRoleDetail).
Writes(role.RoleDetail{}))
apiV1Ws.Route(
apiV1Ws.GET("/rolebinding/{namespace}").
To(apiHandler.handleGetRoleBindingList).
Writes(rolebinding.RoleBindingList{}))
apiV1Ws.Route(
apiV1Ws.GET("/rolebinding/{namespace}/{name}").
To(apiHandler.handleGetRoleBindingDetail).
Writes(rolebinding.RoleBindingDetail{}))
apiV1Ws.Route(
apiV1Ws.GET("/persistentvolume").
To(apiHandler.handleGetPersistentVolumeList).
......@@ -644,6 +664,38 @@ func (apiHandler *APIHandler) handleGetClusterRoleDetail(request *restful.Reques
response.WriteHeaderAndEntity(http.StatusOK, result)
}
func (apiHandler *APIHandler) handleGetClusterRoleBindingList(request *restful.Request, response *restful.Response) {
k8sClient, err := apiHandler.cManager.Client(request)
if err != nil {
errors.HandleInternalError(response, err)
return
}
dataSelect := parser.ParseDataSelectPathParameter(request)
result, err := clusterrolebinding.GetClusterRoleBindingList(k8sClient, dataSelect)
if err != nil {
errors.HandleInternalError(response, err)
return
}
response.WriteHeaderAndEntity(http.StatusOK, result)
}
func (apiHandler *APIHandler) handleGetClusterRoleBindingDetail(request *restful.Request, response *restful.Response) {
k8sClient, err := apiHandler.cManager.Client(request)
if err != nil {
errors.HandleInternalError(response, err)
return
}
name := request.PathParameter("name")
result, err := clusterrolebinding.GetClusterRoleBindingDetail(k8sClient, name)
if err != nil {
errors.HandleInternalError(response, err)
return
}
response.WriteHeaderAndEntity(http.StatusOK, result)
}
func (apiHandler *APIHandler) handleGetRoleList(request *restful.Request, response *restful.Response) {
k8sClient, err := apiHandler.cManager.Client(request)
if err != nil {
......@@ -678,6 +730,40 @@ func (apiHandler *APIHandler) handleGetRoleDetail(request *restful.Request, resp
response.WriteHeaderAndEntity(http.StatusOK, result)
}
func (apiHandler *APIHandler) handleGetRoleBindingList(request *restful.Request, response *restful.Response) {
k8sClient, err := apiHandler.cManager.Client(request)
if err != nil {
errors.HandleInternalError(response, err)
return
}
namespace := parseNamespacePathParameter(request)
dataSelect := parser.ParseDataSelectPathParameter(request)
result, err := rolebinding.GetRoleBindingList(k8sClient, namespace, dataSelect)
if err != nil {
errors.HandleInternalError(response, err)
return
}
response.WriteHeaderAndEntity(http.StatusOK, result)
}
func (apiHandler *APIHandler) handleGetRoleBindingDetail(request *restful.Request, response *restful.Response) {
k8sClient, err := apiHandler.cManager.Client(request)
if err != nil {
errors.HandleInternalError(response, err)
return
}
namespace := request.PathParameter("namespace")
name := request.PathParameter("name")
result, err := rolebinding.GetRoleBindingDetail(k8sClient, namespace, name)
if err != nil {
errors.HandleInternalError(response, err)
return
}
response.WriteHeaderAndEntity(http.StatusOK, result)
}
func (apiHandler *APIHandler) handleGetCsrfToken(request *restful.Request, response *restful.Response) {
action := request.PathParameter("action")
token := xsrftoken.Generate(apiHandler.cManager.CSRFKey(), "none", action)
......
// Copyright 2017 The Kubernetes Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package clusterrolebinding
import (
"github.com/kubernetes/dashboard/src/app/backend/resource/dataselect"
)
// The code below allows to perform complex data section on []ClusterRoleBinding
type ClusterRoleBindingCell ClusterRoleBinding
func (self ClusterRoleBindingCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue {
switch name {
case dataselect.NameProperty:
return dataselect.StdComparableString(self.ObjectMeta.Name)
case dataselect.CreationTimestampProperty:
return dataselect.StdComparableTime(self.ObjectMeta.CreationTimestamp.Time)
case dataselect.NamespaceProperty:
return dataselect.StdComparableString(self.ObjectMeta.Namespace)
default:
// if name is not supported then just return a constant dummy value, sort will have no effect.
return nil
}
}
func toCells(std []ClusterRoleBinding) []dataselect.DataCell {
cells := make([]dataselect.DataCell, len(std))
for i := range std {
cells[i] = ClusterRoleBindingCell(std[i])
}
return cells
}
func fromCells(cells []dataselect.DataCell) []ClusterRoleBinding {
std := make([]ClusterRoleBinding, len(cells))
for i := range std {
std[i] = ClusterRoleBinding(cells[i].(ClusterRoleBindingCell))
}
return std
}
// Copyright 2017 The Kubernetes Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package clusterrolebinding
import (
rbac "k8s.io/api/rbac/v1"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8sClient "k8s.io/client-go/kubernetes"
)
// ClusterRoleBindingDetail contains ClusterRoleBinding details.
type ClusterRoleBindingDetail struct {
// Extends list item structure.
ClusterRoleBinding `json:",inline"`
Subjects []rbac.Subject `json:"subjects,omitempty" protobuf:"bytes,2,rep,name=subjects"`
RoleRef rbac.RoleRef `json:"roleRef" protobuf:"bytes,3,opt,name=roleRef"`
// List of non-critical errors, that occurred during resource retrieval.
Errors []error `json:"errors"`
}
// GetClusterRoleBindingDetail gets ClusterRoleBinding details.
func GetClusterRoleBindingDetail(client k8sClient.Interface, name string) (*ClusterRoleBindingDetail, error) {
rawObject, err := client.RbacV1().ClusterRoleBindings().Get(name, metaV1.GetOptions{})
if err != nil {
return nil, err
}
cr := toClusterRoleBindingDetail(*rawObject)
return &cr, nil
}
func toClusterRoleBindingDetail(cr rbac.ClusterRoleBinding) ClusterRoleBindingDetail {
return ClusterRoleBindingDetail{
ClusterRoleBinding: toClusterRoleBinding(cr),
Subjects: cr.Subjects,
RoleRef: cr.RoleRef,
Errors: []error{},
}
}
// Copyright 2017 The Kubernetes Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package clusterrolebinding
import (
"log"
"github.com/kubernetes/dashboard/src/app/backend/api"
"github.com/kubernetes/dashboard/src/app/backend/errors"
"github.com/kubernetes/dashboard/src/app/backend/resource/common"
"github.com/kubernetes/dashboard/src/app/backend/resource/dataselect"
rbac "k8s.io/api/rbac/v1"
"k8s.io/client-go/kubernetes"
)
// ClusterRoleBindingList contains a list of clusterRoleBindings in the cluster.
type ClusterRoleBindingList struct {
ListMeta api.ListMeta `json:"listMeta"`
Items []ClusterRoleBinding `json:"items"`
// List of non-critical errors, that occurred during resource retrieval.
Errors []error `json:"errors"`
}
// ClusterRoleBindingList is a presentation layer view of Kubernetes clusterRoleBindingList. This means it is clusterRoleBindingList plus additional
// augmented data we can get from other sources.
type ClusterRoleBinding struct {
ObjectMeta api.ObjectMeta `json:"objectMeta"`
TypeMeta api.TypeMeta `json:"typeMeta"`
}
// GetClusterRoleBindingList returns a list of all ClusterRoleBindings in the cluster.
func GetClusterRoleBindingList(client kubernetes.Interface, dsQuery *dataselect.DataSelectQuery) (*ClusterRoleBindingList, error) {
log.Print("Getting list of all clusterRoleBindings in the cluster")
channels := &common.ResourceChannels{
ClusterRoleBindingList: common.GetClusterRoleBindingListChannel(client, 1),
}
return GetClusterRoleBindingListFromChannels(channels, dsQuery)
}
// GetClusterRoleBindingListFromChannels returns a list of all ClusterRoleBindings in the cluster
// reading required resource list once from the channels.
func GetClusterRoleBindingListFromChannels(channels *common.ResourceChannels, dsQuery *dataselect.DataSelectQuery) (*ClusterRoleBindingList, error) {
clusterRoleBindings := <-channels.ClusterRoleBindingList.List
err := <-channels.ClusterRoleBindingList.Error
nonCriticalErrors, criticalError := errors.HandleError(err)
if criticalError != nil {
return nil, criticalError
}
clusterRoleBindingList := toClusterRoleBindingList(clusterRoleBindings.Items, nonCriticalErrors, dsQuery)
return clusterRoleBindingList, nil
}
func toClusterRoleBinding(clusterRoleBinding rbac.ClusterRoleBinding) ClusterRoleBinding {
return ClusterRoleBinding{
ObjectMeta: api.NewObjectMeta(clusterRoleBinding.ObjectMeta),
TypeMeta: api.NewTypeMeta(api.ResourceKindClusterRoleBinding),
}
}
func toClusterRoleBindingList(clusterRoleBindings []rbac.ClusterRoleBinding, nonCriticalErrors []error, dsQuery *dataselect.DataSelectQuery) *ClusterRoleBindingList {
result := &ClusterRoleBindingList{
ListMeta: api.ListMeta{TotalItems: len(clusterRoleBindings)},
Errors: nonCriticalErrors,
}
items := make([]ClusterRoleBinding, 0)
for _, item := range clusterRoleBindings {
items = append(items, toClusterRoleBinding(item))
}
clusterRoleBindingCells, filteredTotal := dataselect.GenericDataSelectWithFilter(toCells(items), dsQuery)
result.ListMeta = api.ListMeta{TotalItems: filteredTotal}
result.Items = fromCells(clusterRoleBindingCells)
return result
}
// Copyright 2017 The Kubernetes Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package clusterrolebinding
import (
"reflect"
"testing"
"github.com/kubernetes/dashboard/src/app/backend/api"
"github.com/kubernetes/dashboard/src/app/backend/resource/dataselect"
rbac "k8s.io/api/rbac/v1"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestToRbacClusterRoleBindingLists(t *testing.T) {
cases := []struct {
ClusterRoleBindings []rbac.ClusterRoleBinding
expected *ClusterRoleBindingList
}{
{nil, &ClusterRoleBindingList{Items: []ClusterRoleBinding{}}},
{
[]rbac.ClusterRoleBinding{
{
ObjectMeta: metaV1.ObjectMeta{Name: "clusterRoleBinding"},
Subjects: []rbac.Subject{{
Kind: "User",
Name: "dashboard",
APIGroup: "rbac.authorization.k8s.io",
}},
RoleRef: rbac.RoleRef{
APIGroup: "Role",
Kind: "pod-reader",
Name: "rbac.authorization.k8s.io",
},
},
},
&ClusterRoleBindingList{
ListMeta: api.ListMeta{TotalItems: 1},
Items: []ClusterRoleBinding{{
ObjectMeta: api.ObjectMeta{Name: "clusterRoleBinding", Namespace: ""},
TypeMeta: api.TypeMeta{Kind: api.ResourceKindClusterRoleBinding},
}},
},
},
}
for _, c := range cases {
actual := toClusterRoleBindingList(c.ClusterRoleBindings, nil, dataselect.NoDataSelect)
if !reflect.DeepEqual(actual, c.expected) {
t.Errorf("toRbacRoleLists(%#v) == \n%#v\nexpected \n%#v\n",
c.ClusterRoleBindings, actual, c.expected)
}
}
}
......@@ -740,14 +740,14 @@ type RoleBindingListChannel struct {
// GetRoleBindingListChannel returns a pair of channels to a RoleBinding list for a namespace and errors that
// both must be read numReads times.
func GetRoleBindingListChannel(client client.Interface, numReads int) RoleBindingListChannel {
func GetRoleBindingListChannel(client client.Interface, nsQuery *NamespaceQuery, numReads int) RoleBindingListChannel {
channel := RoleBindingListChannel{
List: make(chan *rbac.RoleBindingList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.RbacV1().RoleBindings("").List(api.ListEverything)
list, err := client.RbacV1().RoleBindings(nsQuery.ToRequestParam()).List(api.ListEverything)
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
......
......@@ -20,7 +20,7 @@ import (
k8sClient "k8s.io/client-go/kubernetes"
)
// RoleDetail contains Cron Job details.
// RoleDetail contains Role details.
type RoleDetail struct {
// Extends list item structure.
Role `json:",inline"`
......
......@@ -60,8 +60,8 @@ func GetRoleListFromChannels(channels *common.ResourceChannels, dsQuery *datasel
if criticalError != nil {
return nil, criticalError
}
deploymentList := toRoleList(roles.Items, nonCriticalErrors, dsQuery)
return deploymentList, nil
roleList := toRoleList(roles.Items, nonCriticalErrors, dsQuery)
return roleList, nil
}
func toRole(role rbac.Role) Role {
......
// Copyright 2017 The Kubernetes Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package rolebinding
import (
"github.com/kubernetes/dashboard/src/app/backend/resource/dataselect"
)
// The code below allows to perform complex data section on []RoleBinding
type RoleBindingCell RoleBinding
func (self RoleBindingCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue {
switch name {
case dataselect.NameProperty:
return dataselect.StdComparableString(self.ObjectMeta.Name)
case dataselect.CreationTimestampProperty:
return dataselect.StdComparableTime(self.ObjectMeta.CreationTimestamp.Time)
case dataselect.NamespaceProperty:
return dataselect.StdComparableString(self.ObjectMeta.Namespace)
default:
// if name is not supported then just return a constant dummy value, sort will have no effect.
return nil
}
}
func toCells(std []RoleBinding) []dataselect.DataCell {
cells := make([]dataselect.DataCell, len(std))
for i := range std {
cells[i] = RoleBindingCell(std[i])
}
return cells
}
func fromCells(cells []dataselect.DataCell) []RoleBinding {
std := make([]RoleBinding, len(cells))
for i := range std {
std[i] = RoleBinding(cells[i].(RoleBindingCell))
}
return std
}
// Copyright 2017 The Kubernetes Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package rolebinding
import (
rbac "k8s.io/api/rbac/v1"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8sClient "k8s.io/client-go/kubernetes"
)
// RoleBindingDetail contains RoleBinding details.
type RoleBindingDetail struct {
// Extends list item structure.
RoleBinding `json:",inline"`
Subjects []rbac.Subject `json:"subjects,omitempty" protobuf:"bytes,2,rep,name=subjects"`
RoleRef rbac.RoleRef `json:"roleRef" protobuf:"bytes,3,opt,name=roleRef"`
// List of non-critical errors, that occurred during resource retrieval.
Errors []error `json:"errors"`
}
// GetRoleBindingDetail gets RoleBinding details.
func GetRoleBindingDetail(client k8sClient.Interface, namespace, name string) (*RoleBindingDetail, error) {
rawObject, err := client.RbacV1().RoleBindings(namespace).Get(name, metaV1.GetOptions{})
if err != nil {
return nil, err
}
cr := toRoleBindingDetail(*rawObject)
return &cr, nil
}
func toRoleBindingDetail(cr rbac.RoleBinding) RoleBindingDetail {
return RoleBindingDetail{
RoleBinding: toRoleBinding(cr),
Subjects: cr.Subjects,
RoleRef: cr.RoleRef,
Errors: []error{},
}
}
// Copyright 2017 The Kubernetes Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package rolebinding
import (
"log"
"github.com/kubernetes/dashboard/src/app/backend/api"
"github.com/kubernetes/dashboard/src/app/backend/errors"
"github.com/kubernetes/dashboard/src/app/backend/resource/common"
"github.com/kubernetes/dashboard/src/app/backend/resource/dataselect"
rbac "k8s.io/api/rbac/v1"
"k8s.io/client-go/kubernetes"
)
// RoleBindingList contains a list of roleBindings in the cluster.
type RoleBindingList struct {
ListMeta api.ListMeta `json:"listMeta"`
Items []RoleBinding `json:"items"`
// List of non-critical errors, that occurred during resource retrieval.
Errors []error `json:"errors"`
}
// RoleBinding is a presentation layer view of Kubernetes roleBinding. This means it is roleBinding plus additional
// augmented data we can get from other sources.
type RoleBinding struct {
ObjectMeta api.ObjectMeta `json:"objectMeta"`
TypeMeta api.TypeMeta `json:"typeMeta"`
}
// GetRoleBindingList returns a list of all RoleBindings in the cluster.
func GetRoleBindingList(client kubernetes.Interface, nsQuery *common.NamespaceQuery, dsQuery *dataselect.DataSelectQuery) (*RoleBindingList, error) {
log.Print("Getting list of all roleBindings in the cluster")
channels := &common.ResourceChannels{
RoleBindingList: common.GetRoleBindingListChannel(client, nsQuery, 1),
}
return GetRoleBindingListFromChannels(channels, dsQuery)
}
// GetRoleBindingListFromChannels returns a list of all RoleBindings in the cluster
// reading required resource list once from the channels.
func GetRoleBindingListFromChannels(channels *common.ResourceChannels, dsQuery *dataselect.DataSelectQuery) (*RoleBindingList, error) {
roleBindings := <-channels.RoleBindingList.List
err := <-channels.RoleBindingList.Error
nonCriticalErrors, criticalError := errors.HandleError(err)
if criticalError != nil {
return nil, criticalError
}
roleBindingList := toRoleBindingList(roleBindings.Items, nonCriticalErrors, dsQuery)
return roleBindingList, nil
}
func toRoleBinding(roleBinding rbac.RoleBinding) RoleBinding {
return RoleBinding{
ObjectMeta: api.NewObjectMeta(roleBinding.ObjectMeta),
TypeMeta: api.NewTypeMeta(api.ResourceKindRoleBinding),
}
}
func toRoleBindingList(roleBindings []rbac.RoleBinding, nonCriticalErrors []error, dsQuery *dataselect.DataSelectQuery) *RoleBindingList {
result := &RoleBindingList{
ListMeta: api.ListMeta{TotalItems: len(roleBindings)},
Errors: nonCriticalErrors,
}
items := make([]RoleBinding, 0)
for _, item := range roleBindings {
items = append(items, toRoleBinding(item))
}
roleBindingCells, filteredTotal := dataselect.GenericDataSelectWithFilter(toCells(items), dsQuery)
result.ListMeta = api.ListMeta{TotalItems: filteredTotal}
result.Items = fromCells(roleBindingCells)
return result
}
// Copyright 2017 The Kubernetes Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package rolebinding
import (
"reflect"
"testing"
"github.com/kubernetes/dashboard/src/app/backend/api"
"github.com/kubernetes/dashboard/src/app/backend/resource/dataselect"
rbac "k8s.io/api/rbac/v1"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestToRbacRoleBindingLists(t *testing.T) {
cases := []struct {
RoleBindings []rbac.RoleBinding
expected *RoleBindingList
}{
{nil, &RoleBindingList{Items: []RoleBinding{}}},
{
[]rbac.RoleBinding{
{
ObjectMeta: metaV1.ObjectMeta{Name: "rolebinding"},
Subjects: []rbac.Subject{{
Kind: "User",
Name: "dashboard",
APIGroup: "rbac.authorization.k8s.io",
}},
RoleRef: rbac.RoleRef{
APIGroup: "Role",
Kind: "pod-reader",
Name: "rbac.authorization.k8s.io",
},
},
},
&RoleBindingList{
ListMeta: api.ListMeta{TotalItems: 1},
Items: []RoleBinding{{
ObjectMeta: api.ObjectMeta{Name: "rolebinding", Namespace: ""},
TypeMeta: api.TypeMeta{Kind: api.ResourceKindRoleBinding},
}},
},
},
}
for _, c := range cases {
actual := toRoleBindingList(c.RoleBindings, nil, dataselect.NoDataSelect)
if !reflect.DeepEqual(actual, c.expected) {
t.Errorf("toRbacRoleLists(%#v) == \n%#v\nexpected \n%#v\n",
c.RoleBindings, actual, c.expected)
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册