Skip to content

Commit

Permalink
Adds GCP ClusterRole and ClusterRoleBinding
Browse files Browse the repository at this point in the history
This change adds back the ClusterRole and ClusterRoleBinding removed in
[OCPBUGS-5825](openshift/cluster-kube-controller-manager-operator#778).

This is because it is still required at present.
  • Loading branch information
theobarberbany committed Dec 18, 2023
1 parent 8a71f3e commit 8d5306a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 7 deletions.
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)
})
}
}

0 comments on commit 8d5306a

Please sign in to comment.