Skip to content

Commit 42908eb

Browse files
swghoshbharath-b-rh
andcommitted
Update istio-csr controller with rebased bindata assets
* modify constants.go with new paths * fix rbacs.go to use generateName for clusterrole and clusterrolebinding Co-authored-by: Bharath B <bhb@redhat.com> Signed-off-by: Swarup Ghosh <swghosh@redhat.com>
1 parent 4cc5ff9 commit 42908eb

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

pkg/controller/istiocsr/constants.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,16 @@ var (
102102
// asset names are the files present in the root bindata/ dir. Which are then loaded
103103
// and made available by the pkg/operator/assets package.
104104
const (
105-
certificateAssetName = "istio-csr/certificate.yaml"
106-
clusterRoleAssetName = "istio-csr/clusterrole.yaml"
107-
clusterRoleBindingAssetName = "istio-csr/clusterrolebinding.yaml"
108-
deploymentAssetName = "istio-csr/deployment.yaml"
109-
roleAssetName = "istio-csr/role.yaml"
110-
roleLeasesAssetName = "istio-csr/role_leases.yaml"
111-
roleBindingAssetName = "istio-csr/rolebinding.yaml"
112-
roleBindingLeasesAssetName = "istio-csr/rolebinding_leases.yaml"
113-
serviceAssetName = "istio-csr/service.yaml"
114-
serviceAccountAssetName = "istio-csr/serviceaccount.yaml"
105+
certificateAssetName = "istio-csr/istiod-certificate.yaml"
106+
clusterRoleAssetName = "istio-csr/cert-manager-istio-csr-clusterrole.yaml"
107+
clusterRoleBindingAssetName = "istio-csr/cert-manager-istio-csr-clusterrolebinding.yaml"
108+
deploymentAssetName = "istio-csr/cert-manager-istio-csr-deployment.yaml"
109+
roleAssetName = "istio-csr/cert-manager-istio-csr-role.yaml"
110+
roleLeasesAssetName = "istio-csr/cert-manager-istio-csr-leases-role.yaml"
111+
roleBindingAssetName = "istio-csr/cert-manager-istio-csr-rolebinding.yaml"
112+
roleBindingLeasesAssetName = "istio-csr/cert-manager-istio-csr-leases-rolebinding.yaml"
113+
serviceAssetName = "istio-csr/cert-manager-istio-csr-service.yaml"
114+
serviceAccountAssetName = "istio-csr/cert-manager-istio-csr-serviceaccount.yaml"
115115
)
116116

117117
const (

pkg/controller/istiocsr/rbacs.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,16 @@ func (r *Reconciler) createOrApplyClusterRoles(istiocsr *v1alpha1.IstioCSR, reso
124124

125125
func (r *Reconciler) getClusterRoleObject(istioCSRNamespace string, resourceLabels map[string]string) *rbacv1.ClusterRole {
126126
clusterRole := decodeClusterRoleObjBytes(assets.MustAsset(clusterRoleAssetName))
127+
updateToUseGenerateName(clusterRole)
127128
updateResourceLabelsWithIstioMapperLabels(clusterRole, istioCSRNamespace, resourceLabels)
128129
return clusterRole
129130
}
130131

132+
func updateToUseGenerateName(obj client.Object) {
133+
obj.SetName("")
134+
obj.SetGenerateName("cert-manager-istio-csr-")
135+
}
136+
131137
func (r *Reconciler) updateClusterRoleNameInStatus(istiocsr *v1alpha1.IstioCSR, new, existing *rbacv1.ClusterRole) (string, error) {
132138
name := new.GetName()
133139
if name == "" {
@@ -212,6 +218,7 @@ func (r *Reconciler) createOrApplyClusterRoleBindings(istiocsr *v1alpha1.IstioCS
212218
func (r *Reconciler) getClusterRoleBindingObject(clusterRoleName, serviceAccount, istiocsrNamespace string, resourceLabels map[string]string) *rbacv1.ClusterRoleBinding {
213219
clusterRoleBinding := decodeClusterRoleBindingObjBytes(assets.MustAsset(clusterRoleBindingAssetName))
214220
clusterRoleBinding.RoleRef.Name = clusterRoleName
221+
updateToUseGenerateName(clusterRoleBinding)
215222
updateResourceLabelsWithIstioMapperLabels(clusterRoleBinding, istiocsrNamespace, resourceLabels)
216223
updateServiceAccountNamespaceInRBACBindingObject[*rbacv1.ClusterRoleBinding](clusterRoleBinding, serviceAccount, istiocsrNamespace)
217224
return clusterRoleBinding

pkg/controller/istiocsr/test_utils.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,15 @@ func testClusterRole() *rbacv1.ClusterRole {
157157
func testClusterRoleBinding() *rbacv1.ClusterRoleBinding {
158158
roleBinding := decodeClusterRoleBindingObjBytes(assets.MustAsset(clusterRoleBindingAssetName))
159159
roleBinding.SetName("cert-manager-istio-csr-dfkhk")
160+
roleBinding.SetGenerateName("cert-manager-istio-csr-")
160161
roleBinding.SetLabels(controllerDefaultResourceLabels)
161162
return roleBinding
162163
}
163164

164165
func testClusterRoleBindingExtra() *rbacv1.ClusterRoleBinding {
165166
roleBinding := decodeClusterRoleBindingObjBytes(assets.MustAsset(clusterRoleBindingAssetName))
166167
roleBinding.SetName("cert-manager-istio-csr-dfmfj")
168+
roleBinding.SetGenerateName("cert-manager-istio-csr-")
167169
roleBinding.SetLabels(controllerDefaultResourceLabels)
168170
return roleBinding
169171
}

0 commit comments

Comments
 (0)