Skip to content

Commit

Permalink
OpenStack: Cleanup ServiceAccount
Browse files Browse the repository at this point in the history
For an unknown reason OpenStack was different in CCCMO and had it's
OpenStack-specific `kube-system` ServiceAccount defined in `manifests/`.
This was because OCCM for some reason was making number of API calls
from the `kube-system/cloud-controller-manager` ServiceAccount, so a
bunch of permissions needed to be defined there. This commit attempts to
clean up this situation.

To make OCCM use the main SA of
`openshift-cloud-controller-manager/cloud-controller-manager`, I change
the `--use-service-account-credentials` to `false`. I believe that we
only had `true` because that's what upstream sets and upstream has it
because it wrongly copied `cloud-provider-aws` manifest without
including the patches.

Now OCCM still needs a bunch of special permissions - ability to patch
`services` and `services/status`. In order to do that I add 2 more
OpenStack-specific manifests in `pkg/cloud/openstack` with a ClusterRole
and the binding.
  • Loading branch information
dulek committed Apr 11, 2024
1 parent f8e0afd commit 27d8e9a
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 56 deletions.

This file was deleted.

4 changes: 2 additions & 2 deletions pkg/cloud/openstack/assets/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:
infrastructure.openshift.io/cloud-controller-manager: {{ .cloudproviderName }}
spec:
hostNetwork: true
serviceAccount: cloud-controller-manager
serviceAccountName: cloud-controller-manager
priorityClassName: system-cluster-critical
nodeSelector:
node-role.kubernetes.io/master: ""
Expand Down Expand Up @@ -67,7 +67,7 @@ spec:
--v=1 \
--cloud-config=$(CLOUD_CONFIG) \
--cloud-provider=openstack \
--use-service-account-credentials=true \
--use-service-account-credentials=false \
--configure-cloud-routes=false \
--bind-address=127.0.0.1 \
--leader-elect=true \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: openstack-cloud-controller-manager
annotations:
include.release.openshift.io/self-managed-high-availability: "true"
include.release.openshift.io/single-node-developer: "true"
rules:
- apiGroups:
- ""
resources:
- services
- services/status
verbs:
- patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: cloud-controller-manager:openstack-cloud-controller-manager
roleRef:
kind: ClusterRole
name: openstack-cloud-controller-manager
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
namespace: openshift-cloud-controller-manager
name: cloud-controller-manager
3 changes: 3 additions & 0 deletions pkg/cloud/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
configv1 "github.com/openshift/api/config/v1"
ini "gopkg.in/ini.v1"
appsv1 "k8s.io/api/apps/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand All @@ -24,6 +25,8 @@ var (

templates = []common.TemplateSource{
{ReferenceObject: &appsv1.Deployment{}, EmbedFsPath: "assets/deployment.yaml"},
{ReferenceObject: &rbacv1.ClusterRole{}, EmbedFsPath: "assets/openstack-cloud-controller-manager-clusterrole.yaml"},
{ReferenceObject: &rbacv1.ClusterRoleBinding{}, EmbedFsPath: "assets/openstack-cloud-controller-manager-clusterrolebinding.yaml"},
}
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/openstack/openstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestResourcesRenderingSmoke(t *testing.T) {
}

resources := assets.GetRenderedResources()
g.Expect(resources).Should(HaveLen(1))
g.Expect(resources).Should(HaveLen(3))
})
}
}
Expand Down

0 comments on commit 27d8e9a

Please sign in to comment.