containerized-data-importer/pkg/operator/resources/cluster/controller.go
Michael Henriksen 0e24579513 move to v1 rbac
2019-01-11 10:22:49 -05:00

153 lines
2.6 KiB
Go

/*
Copyright 2018 The CDI 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 cluster
import (
rbacv1 "k8s.io/api/rbac/v1"
)
const (
controllerServiceAccountName = "cdi-sa"
controlerClusterRoleName = "cdi"
)
func createControllerResources(args *FactoryArgs) []Resource {
return []Resource{
createControllerClusterRoleBinding(args.Namespace),
createControllerClusterRole(),
}
}
func createControllerClusterRoleBinding(namespace string) *rbacv1.ClusterRoleBinding {
return createClusterRoleBinding(controllerServiceAccountName, controlerClusterRoleName, controllerServiceAccountName, namespace)
}
func createControllerClusterRole() *rbacv1.ClusterRole {
clusterRole := createClusterRole(controlerClusterRoleName)
clusterRole.Rules = []rbacv1.PolicyRule{
{
APIGroups: []string{
"",
},
Resources: []string{
"events",
},
Verbs: []string{
"create",
"update",
"patch",
},
},
{
APIGroups: []string{
"",
},
Resources: []string{
"persistentvolumeclaims",
},
Verbs: []string{
"get",
"list",
"watch",
"create",
"update",
"patch",
},
},
{
APIGroups: []string{
"",
},
Resources: []string{
"persistentvolumeclaims/finalizers",
"pods/finalizers",
},
Verbs: []string{
"update",
},
},
{
APIGroups: []string{
"",
},
Resources: []string{
"pods",
"services",
},
Verbs: []string{
"get",
"list",
"watch",
"create",
"delete",
},
},
{
APIGroups: []string{
"",
},
Resources: []string{
"secrets",
},
Verbs: []string{
"get",
"list",
"watch",
"create",
},
},
{
APIGroups: []string{
"",
},
Resources: []string{
"configmaps",
},
Verbs: []string{
"get",
"list",
"watch",
"create",
"update",
},
},
{
APIGroups: []string{
"storage.k8s.io",
},
Resources: []string{
"storageclasses",
},
Verbs: []string{
"get",
},
},
{
APIGroups: []string{
"cdi.kubevirt.io",
},
Resources: []string{
"*",
},
Verbs: []string{
"*",
},
},
}
return clusterRole
}