Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCPBUGS-5825: Adds GCP ClusterRole and ClusterRoleBinding #310

Merged
merged 1 commit into from Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -133,6 +133,21 @@ rules:
verbs:
- patch

# gcp requires additional permissions on the kube-system/cloud-provider service account.
# The operator must have these permissions to then grant them to the gcp node manager.
- apiGroups:
- ""
resources:
- events
verbs:
- update
- apiGroups:
- ""
resources:
- services/status
verbs:
- update

---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
Expand Down
18 changes: 12 additions & 6 deletions pkg/cloud/cloud_test.go
Expand Up @@ -157,17 +157,23 @@ func TestGetResources(t *testing.T) {
}, {
name: "GCP resources returned as expected",
testPlatform: platformsMap[string(configv1.GCPPlatformType)],
expectedResourceCount: 2,
expectedResourceCount: 4,
expectedResourcesKindName: []string{
"Deployment/gcp-cloud-controller-manager",
"PodDisruptionBudget/gcp-cloud-controller-manager",
"ClusterRole/gcp-cloud-controller-manager",
"ClusterRoleBinding/gcp-cloud-controller-manager:cloud-provider",
},
}, {
name: "GCP resources returned as expected with single node cluster",
testPlatform: platformsMap[string(configv1.GCPPlatformType)],
expectedResourceCount: 1,
singleReplica: true,
expectedResourcesKindName: []string{"Deployment/gcp-cloud-controller-manager"},
name: "GCP resources returned as expected with single node cluster",
testPlatform: platformsMap[string(configv1.GCPPlatformType)],
expectedResourceCount: 3,
singleReplica: true,
expectedResourcesKindName: []string{
"Deployment/gcp-cloud-controller-manager",
"ClusterRole/gcp-cloud-controller-manager",
"ClusterRoleBinding/gcp-cloud-controller-manager:cloud-provider",
},
}, {
name: "Azure resources returned as expected",
testPlatform: platformsMap[string(configv1.AzurePlatformType)],
Expand Down
20 changes: 20 additions & 0 deletions pkg/cloud/gcp/assets/gcp-cloud-controller-manager-clusterrole.yaml
@@ -0,0 +1,20 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: gcp-cloud-controller-manager
rules:
- apiGroups:
- ""
resources:
- events
verbs:
- create
- patch
- update
- apiGroups:
- ""
resources:
- services/status
verbs:
- patch
- update
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: gcp-cloud-controller-manager:cloud-provider
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: gcp-cloud-controller-manager
subjects:
- kind: ServiceAccount
name: cloud-provider
namespace: kube-system
3 changes: 3 additions & 0 deletions pkg/cloud/gcp/gcp.go
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/asaskevich/govalidator"
appsv1 "k8s.io/api/apps/v1"
rbacv1 "k8s.io/api/rbac/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/cloud/common"
Expand All @@ -19,6 +20,8 @@ var (
assetsFs embed.FS
templates = []common.TemplateSource{
{ReferenceObject: &appsv1.Deployment{}, EmbedFsPath: "assets/cloud-controller-manager.yaml"},
{ReferenceObject: &rbacv1.ClusterRole{}, EmbedFsPath: "assets/gcp-cloud-controller-manager-clusterrole.yaml"},
{ReferenceObject: &rbacv1.ClusterRoleBinding{}, EmbedFsPath: "assets/gcp-cloud-controller-manager-clusterrolebinding.yaml"},
}
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/gcp/gcp_test.go
Expand Up @@ -55,7 +55,7 @@ func TestResourcesRenderingSmoke(t *testing.T) {
}

resources := assets.GetRenderedResources()
assert.Len(t, resources, 1)
assert.Len(t, resources, 3)
})
}
}