@@ -95,7 +95,7 @@ var _ = Describe("Resources", func() {
9595 Expect (feature .SetFeatureGates ()).ShouldNot (HaveOccurred ())
9696 ctx = context .TODO ()
9797 // use ClusterIP svc when run operator in k8s
98- adminServiceURL := fmt .Sprintf ("http://%s-broker.%s.svc.cluster.local:8080" , brokerName , namespaceName )
98+ adminServiceURL := utils . GetEnv ( "ADMIN_SERVICE_URL" , fmt .Sprintf ("http://%s-broker.%s.svc.cluster.local:8080" , brokerName , namespaceName ) )
9999 // use NodePort svc when cluster is kind cluster and run operator locally, the nodePort need to be setup in kind
100100 // adminServiceURL := fmt.Sprintf("http://127.0.0.1:%d", nodePort)
101101 pconn = utils .MakePulsarConnection (namespaceName , pconnName , adminServiceURL )
@@ -125,7 +125,7 @@ var _ = Describe("Resources", func() {
125125 })
126126
127127 Describe ("Basic resource operations" , Ordered , func () {
128- Context ("Check pulsar broker" , func () {
128+ Context ("Check pulsar broker" , Label ( "Permissions" ), func () {
129129 It ("should create the pulsar broker successfully" , func () {
130130 Eventually (func () bool {
131131 statefulset := & v1.StatefulSet {}
@@ -138,14 +138,14 @@ var _ = Describe("Resources", func() {
138138 })
139139 })
140140
141- Context ("PulsarConnection operation" , func () {
141+ Context ("PulsarConnection operation" , Label ( "Permissions" ), func () {
142142 It ("should create the pulsarconnection successfully" , func () {
143143 err := k8sClient .Create (ctx , pconn )
144144 Expect (err == nil || apierrors .IsAlreadyExists (err )).Should (BeTrue ())
145145 })
146146 })
147147
148- Context ("PulsarTenant operation" , func () {
148+ Context ("PulsarTenant operation" , Label ( "Permissions" ), func () {
149149 It ("should create the pulsartenant successfully" , func () {
150150 err := k8sClient .Create (ctx , ptenant )
151151 Expect (err == nil || apierrors .IsAlreadyExists (err )).Should (BeTrue ())
@@ -176,7 +176,7 @@ var _ = Describe("Resources", func() {
176176 })
177177 })
178178
179- Context ("PulsarNamespace operation" , func () {
179+ Context ("PulsarNamespace operation" , Label ( "Permissions" ), func () {
180180 It ("should create the pulsarnamespace successfully" , func () {
181181 err := k8sClient .Create (ctx , pnamespace )
182182 Expect (err == nil || apierrors .IsAlreadyExists (err )).Should (BeTrue ())
@@ -193,7 +193,7 @@ var _ = Describe("Resources", func() {
193193 })
194194
195195 Context ("PulsarTopic operation" , Ordered , func () {
196- It ("should create the pulsartopic successfully" , func () {
196+ It ("should create the pulsartopic successfully" , Label ( "Permissions" ), func () {
197197 err := k8sClient .Create (ctx , ptopic )
198198 Expect (err == nil || apierrors .IsAlreadyExists (err )).Should (BeTrue ())
199199 err = k8sClient .Create (ctx , ptopic2 )
@@ -202,7 +202,7 @@ var _ = Describe("Resources", func() {
202202 Expect (err == nil || apierrors .IsAlreadyExists (err )).Should (BeTrue ())
203203 })
204204
205- It ("should be ready" , func () {
205+ It ("should be ready" , Label ( "Permissions" ), func () {
206206 Eventually (func () bool {
207207 t := & v1alphav1.PulsarTopic {}
208208 tns := types.NamespacedName {Namespace : namespaceName , Name : ptopicName }
@@ -291,7 +291,7 @@ var _ = Describe("Resources", func() {
291291
292292 })
293293
294- Context ("PulsarPermission operation" , func () {
294+ Context ("PulsarPermission operation" , Label ( "Permissions" ), func () {
295295 It ("should grant the pulsarpermission successfully" , func () {
296296 err := k8sClient .Create (ctx , ppermission )
297297 Expect (err == nil || apierrors .IsAlreadyExists (err )).Should (BeTrue ())
@@ -305,6 +305,69 @@ var _ = Describe("Resources", func() {
305305 return v1alphav1 .IsPulsarResourceReady (t )
306306 }, "20s" , "100ms" ).Should (BeTrue ())
307307 })
308+
309+ It ("should add a new role" , func () {
310+ t := & v1alphav1.PulsarPermission {}
311+ tns := types.NamespacedName {Namespace : namespaceName , Name : ppermissionName }
312+ Expect (k8sClient .Get (ctx , tns , t )).Should (Succeed ())
313+ t .Spec .Roles = append (t .Spec .Roles , "spiderman" )
314+ err := k8sClient .Update (ctx , t )
315+ Expect (err ).Should (Succeed ())
316+ })
317+
318+ It ("should be ready" , func () {
319+ Eventually (func () bool {
320+ t := & v1alphav1.PulsarPermission {}
321+ tns := types.NamespacedName {Namespace : namespaceName , Name : ppermissionName }
322+ Expect (k8sClient .Get (ctx , tns , t )).Should (Succeed ())
323+ return v1alphav1 .IsPulsarResourceReady (t )
324+ }, "20s" , "100ms" ).Should (BeTrue ())
325+ })
326+
327+ It ("spiderman should exists along with ironman" , func () {
328+ Eventually (func (g Gomega ) {
329+ podName := fmt .Sprintf ("%s-broker-0" , brokerName )
330+ containerName := fmt .Sprintf ("%s-broker" , brokerName )
331+ stdout , _ , err := utils .ExecInPod (k8sConfig , namespaceName , podName , containerName ,
332+ "./bin/pulsar-admin topics permissions " + ppermission .Spec .ResourceName )
333+ g .Expect (err ).Should (Succeed ())
334+ g .Expect (stdout ).Should (Not (BeEmpty ()))
335+ g .Expect (stdout ).Should (ContainSubstring ("ironman" ))
336+ g .Expect (stdout ).Should (ContainSubstring ("spiderman" ))
337+ }, "20s" , "100ms" ).Should (Succeed ())
338+ })
339+
340+ It ("should delete a role" , func () {
341+ t := & v1alphav1.PulsarPermission {}
342+ tns := types.NamespacedName {Namespace : namespaceName , Name : ppermissionName }
343+ Expect (k8sClient .Get (ctx , tns , t )).Should (Succeed ())
344+ // remove spiderman and assign to roles
345+ t .Spec .Roles = []string {"ironman" }
346+ err := k8sClient .Update (ctx , t )
347+ Expect (err ).Should (Succeed ())
348+ })
349+
350+ It ("should be ready" , func () {
351+ Eventually (func () bool {
352+ t := & v1alphav1.PulsarPermission {}
353+ tns := types.NamespacedName {Namespace : namespaceName , Name : ppermissionName }
354+ Expect (k8sClient .Get (ctx , tns , t )).Should (Succeed ())
355+ return v1alphav1 .IsPulsarResourceReady (t )
356+ }, "20s" , "100ms" ).Should (BeTrue ())
357+ })
358+
359+ It ("spiderman shouldn't exists anymore but ironman" , func () {
360+ Eventually (func (g Gomega ) {
361+ podName := fmt .Sprintf ("%s-broker-0" , brokerName )
362+ containerName := fmt .Sprintf ("%s-broker" , brokerName )
363+ stdout , _ , err := utils .ExecInPod (k8sConfig , namespaceName , podName , containerName ,
364+ "./bin/pulsar-admin topics permissions " + ptopic .Spec .Name )
365+ g .Expect (err ).Should (Succeed ())
366+ g .Expect (stdout ).Should (Not (BeEmpty ()))
367+ g .Expect (stdout ).Should (ContainSubstring ("ironman" ))
368+ g .Expect (stdout ).Should (Not (ContainSubstring ("spiderman" )))
369+ }, "20s" , "100ms" ).Should (Succeed ())
370+ })
308371 })
309372
310373 Context ("PulsarFunction & PulsarPackage operation" , func () {
@@ -514,6 +577,20 @@ var _ = Describe("Resources", func() {
514577 g .Expect (k8sClient .Delete (ctx , t )).Should (Succeed ())
515578 }).Should (Succeed ())
516579
580+ Eventually (func (g Gomega ) {
581+ t := & v1alphav1.PulsarTopic {}
582+ tns := types.NamespacedName {Namespace : namespaceName , Name : ptopicName2 }
583+ g .Expect (k8sClient .Get (ctx , tns , t )).Should (Succeed ())
584+ g .Expect (k8sClient .Delete (ctx , t )).Should (Succeed ())
585+ }).Should (Succeed ())
586+
587+ Eventually (func (g Gomega ) {
588+ t := & v1alphav1.PulsarTopic {}
589+ tns := types.NamespacedName {Namespace : namespaceName , Name : partitionedTopic .Name }
590+ g .Expect (k8sClient .Get (ctx , tns , t )).Should (Succeed ())
591+ g .Expect (k8sClient .Delete (ctx , t )).Should (Succeed ())
592+ }).Should (Succeed ())
593+
517594 Eventually (func (g Gomega ) {
518595 ns := & v1alphav1.PulsarNamespace {}
519596 tns := types.NamespacedName {Namespace : namespaceName , Name : pnamespaceName }
0 commit comments