Path: blob/main/install/installer/pkg/components/ws-manager-mk2/role.go
2501 views
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License-AGPL.txt in the project root for license information.34package wsmanagermk256import (7"github.com/gitpod-io/gitpod/installer/pkg/common"89rbacv1 "k8s.io/api/rbac/v1"10metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"11"k8s.io/apimachinery/pkg/runtime"12)1314var controllerRules = []rbacv1.PolicyRule{15{16APIGroups: []string{""},17Resources: []string{"pods"},18Verbs: []string{19"create",20"delete",21"get",22"list",23"patch",24"update",25"watch",26},27},28{29Verbs: []string{"get"},30APIGroups: []string{""},31Resources: []string{"pod/status"},32},33{34APIGroups: []string{"workspace.gitpod.io"},35Resources: []string{"workspaces"},36Verbs: []string{37"create",38"delete",39"get",40"list",41"patch",42"update",43"watch",44},45},46{47Verbs: []string{"update"},48APIGroups: []string{"workspace.gitpod.io"},49Resources: []string{"workspaces/finalizers"},50},51{52APIGroups: []string{"workspace.gitpod.io"},53Resources: []string{"workspaces/status"},54Verbs: []string{55"get",56"patch",57"update",58},59},60{61APIGroups: []string{"workspace.gitpod.io"},62Resources: []string{"snapshots"},63Verbs: []string{64"create",65"delete",66"get",67"list",68"watch",69},70},71{72APIGroups: []string{"workspace.gitpod.io"},73Resources: []string{"snapshots/status"},74Verbs: []string{75"get",76},77},78{79APIGroups: []string{""},80Resources: []string{"secrets"},81Verbs: []string{82"create",83"delete",84"get",85"list",86"watch",87},88},89{90APIGroups: []string{""},91Resources: []string{"configmaps"},92Verbs: []string{93"create",94"delete",95"get",96"list",97"patch",98"update",99"watch",100},101},102}103104var controllerClusterRules = []rbacv1.PolicyRule{105{106APIGroups: []string{""},107Resources: []string{"nodes"},108Verbs: []string{109"get",110"list",111"watch",112},113},114}115116// ConfigMap, Leases, and Events access is required for leader-election.117var leaderElectionRules = []rbacv1.PolicyRule{118{119APIGroups: []string{"coordination.k8s.io"},120Resources: []string{"leases"},121Verbs: []string{122"create",123"delete",124"get",125"list",126"patch",127"update",128"watch",129},130},131{132APIGroups: []string{""},133Resources: []string{"events"},134Verbs: []string{135"create",136"patch",137},138},139}140141func role(ctx *common.RenderContext) ([]runtime.Object, error) {142labels := common.DefaultLabels(Component)143144return []runtime.Object{145&rbacv1.Role{146TypeMeta: common.TypeMetaRole,147ObjectMeta: metav1.ObjectMeta{148Name: Component,149Namespace: ctx.Namespace,150Labels: labels,151},152Rules: append(controllerRules, leaderElectionRules...),153},154155&rbacv1.Role{156TypeMeta: common.TypeMetaRole,157ObjectMeta: metav1.ObjectMeta{158Name: Component,159Namespace: common.WorkspaceSecretsNamespace,160Labels: labels,161},162Rules: controllerRules,163},164165&rbacv1.ClusterRole{166TypeMeta: common.TypeMetaClusterRole,167ObjectMeta: metav1.ObjectMeta{168Name: Component,169Labels: labels,170},171Rules: controllerClusterRules,172},173}, nil174}175176177