Skip to content

Commit 20fbc30

Browse files
committed
fixup! Rename ClusterRoles created by OperatorGroups
Signed-off-by: Todd Short <[email protected]>
1 parent 306cd60 commit 20fbc30

File tree

3 files changed

+40
-52
lines changed

3 files changed

+40
-52
lines changed

pkg/controller/operators/olm/operator_test.go

+24-48
Original file line numberDiff line numberDiff line change
@@ -4560,8 +4560,7 @@ func TestSyncOperatorGroups(t *testing.T) {
45604560
"": {
45614561
&rbacv1.ClusterRole{
45624562
ObjectMeta: metav1.ObjectMeta{
4563-
ResourceVersion: "",
4564-
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
4563+
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
45654564
Labels: map[string]string{
45664565
"olm.owner": "operator-group-1",
45674566
"olm.owner.namespace": "operator-ns",
@@ -4571,8 +4570,7 @@ func TestSyncOperatorGroups(t *testing.T) {
45714570
},
45724571
&rbacv1.ClusterRole{
45734572
ObjectMeta: metav1.ObjectMeta{
4574-
ResourceVersion: "",
4575-
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
4573+
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
45764574
Labels: map[string]string{
45774575
"olm.owner": "operator-group-1",
45784576
"olm.owner.namespace": "operator-ns",
@@ -4582,8 +4580,7 @@ func TestSyncOperatorGroups(t *testing.T) {
45824580
},
45834581
&rbacv1.ClusterRole{
45844582
ObjectMeta: metav1.ObjectMeta{
4585-
ResourceVersion: "",
4586-
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
4583+
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
45874584
Labels: map[string]string{
45884585
"olm.owner": "operator-group-1",
45894586
"olm.owner.namespace": "operator-ns",
@@ -4624,8 +4621,7 @@ func TestSyncOperatorGroups(t *testing.T) {
46244621
},
46254622
&rbacv1.ClusterRole{
46264623
ObjectMeta: metav1.ObjectMeta{
4627-
ResourceVersion: "",
4628-
Name: "operator-group-1-admin",
4624+
Name: "operator-group-1-admin",
46294625
Labels: map[string]string{
46304626
"olm.owner": "operator-group-1",
46314627
"olm.owner.namespace": "operator-ns",
@@ -4635,8 +4631,7 @@ func TestSyncOperatorGroups(t *testing.T) {
46354631
},
46364632
&rbacv1.ClusterRole{
46374633
ObjectMeta: metav1.ObjectMeta{
4638-
ResourceVersion: "",
4639-
Name: "operator-group-1-view",
4634+
Name: "operator-group-1-view",
46404635
Labels: map[string]string{
46414636
"olm.owner": "operator-group-1",
46424637
"olm.owner.namespace": "operator-ns",
@@ -4646,8 +4641,7 @@ func TestSyncOperatorGroups(t *testing.T) {
46464641
},
46474642
&rbacv1.ClusterRole{
46484643
ObjectMeta: metav1.ObjectMeta{
4649-
ResourceVersion: "",
4650-
Name: "operator-group-1-edit",
4644+
Name: "operator-group-1-edit",
46514645
Labels: map[string]string{
46524646
"olm.owner": "operator-group-1",
46534647
"olm.owner.namespace": "operator-ns",
@@ -4665,8 +4659,7 @@ func TestSyncOperatorGroups(t *testing.T) {
46654659
"": {
46664660
&rbacv1.ClusterRole{
46674661
ObjectMeta: metav1.ObjectMeta{
4668-
ResourceVersion: "",
4669-
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
4662+
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
46704663
Labels: map[string]string{
46714664
"olm.owner": "operator-group-1",
46724665
"olm.owner.namespace": "operator-ns",
@@ -4676,8 +4669,7 @@ func TestSyncOperatorGroups(t *testing.T) {
46764669
},
46774670
&rbacv1.ClusterRole{
46784671
ObjectMeta: metav1.ObjectMeta{
4679-
ResourceVersion: "",
4680-
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
4672+
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
46814673
Labels: map[string]string{
46824674
"olm.owner": "operator-group-1",
46834675
"olm.owner.namespace": "operator-ns",
@@ -4687,8 +4679,7 @@ func TestSyncOperatorGroups(t *testing.T) {
46874679
},
46884680
&rbacv1.ClusterRole{
46894681
ObjectMeta: metav1.ObjectMeta{
4690-
ResourceVersion: "",
4691-
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
4682+
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
46924683
Labels: map[string]string{
46934684
"olm.owner": "operator-group-1",
46944685
"olm.owner.namespace": "operator-ns",
@@ -4698,8 +4689,7 @@ func TestSyncOperatorGroups(t *testing.T) {
46984689
},
46994690
&rbacv1.ClusterRole{
47004691
ObjectMeta: metav1.ObjectMeta{
4701-
ResourceVersion: "",
4702-
Name: "operator-group-1-admin",
4692+
Name: "operator-group-1-admin",
47034693
Labels: map[string]string{
47044694
"olm.owner": "operator-group-1",
47054695
"olm.owner.namespace": "operator-ns",
@@ -4709,8 +4699,7 @@ func TestSyncOperatorGroups(t *testing.T) {
47094699
},
47104700
&rbacv1.ClusterRole{
47114701
ObjectMeta: metav1.ObjectMeta{
4712-
ResourceVersion: "",
4713-
Name: "operator-group-1-view",
4702+
Name: "operator-group-1-view",
47144703
Labels: map[string]string{
47154704
"olm.owner": "operator-group-1",
47164705
"olm.owner.namespace": "operator-ns",
@@ -4720,8 +4709,7 @@ func TestSyncOperatorGroups(t *testing.T) {
47204709
},
47214710
&rbacv1.ClusterRole{
47224711
ObjectMeta: metav1.ObjectMeta{
4723-
ResourceVersion: "",
4724-
Name: "operator-group-1-edit",
4712+
Name: "operator-group-1-edit",
47254713
Labels: map[string]string{
47264714
"olm.owner": "operator-group-1",
47274715
"olm.owner.namespace": "operator-ns",
@@ -4762,8 +4750,7 @@ func TestSyncOperatorGroups(t *testing.T) {
47624750
},
47634751
&rbacv1.ClusterRole{
47644752
ObjectMeta: metav1.ObjectMeta{
4765-
ResourceVersion: "",
4766-
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
4753+
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
47674754
Labels: map[string]string{
47684755
"olm.owner": "operator-group-1",
47694756
"olm.owner.namespace": "operator-ns-bob",
@@ -4774,8 +4761,7 @@ func TestSyncOperatorGroups(t *testing.T) {
47744761
},
47754762
&rbacv1.ClusterRole{
47764763
ObjectMeta: metav1.ObjectMeta{
4777-
ResourceVersion: "",
4778-
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
4764+
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
47794765
Labels: map[string]string{
47804766
"olm.owner": "operator-group-5",
47814767
"olm.owner.namespace": "operator-ns",
@@ -4787,8 +4773,7 @@ func TestSyncOperatorGroups(t *testing.T) {
47874773
},
47884774
&rbacv1.ClusterRole{
47894775
ObjectMeta: metav1.ObjectMeta{
4790-
ResourceVersion: "",
4791-
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
4776+
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
47924777
Labels: map[string]string{
47934778
"olm.owner": "operator-group-1",
47944779
"olm.owner.namespace": "operator-ns",
@@ -4806,8 +4791,7 @@ func TestSyncOperatorGroups(t *testing.T) {
48064791
"": {
48074792
&rbacv1.ClusterRole{
48084793
ObjectMeta: metav1.ObjectMeta{
4809-
ResourceVersion: "",
4810-
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
4794+
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
48114795
Labels: map[string]string{
48124796
"olm.owner": "operator-group-1",
48134797
"olm.owner.namespace": "operator-ns",
@@ -4818,8 +4802,7 @@ func TestSyncOperatorGroups(t *testing.T) {
48184802
},
48194803
&rbacv1.ClusterRole{
48204804
ObjectMeta: metav1.ObjectMeta{
4821-
ResourceVersion: "",
4822-
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
4805+
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
48234806
Labels: map[string]string{
48244807
"olm.owner": "operator-group-1",
48254808
"olm.owner.namespace": "operator-ns",
@@ -4829,8 +4812,7 @@ func TestSyncOperatorGroups(t *testing.T) {
48294812
},
48304813
&rbacv1.ClusterRole{
48314814
ObjectMeta: metav1.ObjectMeta{
4832-
ResourceVersion: "",
4833-
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
4815+
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
48344816
Labels: map[string]string{
48354817
"olm.owner": "operator-group-1",
48364818
"olm.owner.namespace": "operator-ns",
@@ -4873,8 +4855,7 @@ func TestSyncOperatorGroups(t *testing.T) {
48734855
},
48744856
&rbacv1.ClusterRole{
48754857
ObjectMeta: metav1.ObjectMeta{
4876-
ResourceVersion: "",
4877-
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
4858+
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
48784859
Labels: map[string]string{
48794860
"olm.owner": "operator-group-1",
48804861
"olm.owner.namespace": "operator-ns",
@@ -4884,8 +4865,7 @@ func TestSyncOperatorGroups(t *testing.T) {
48844865
},
48854866
&rbacv1.ClusterRole{
48864867
ObjectMeta: metav1.ObjectMeta{
4887-
ResourceVersion: "",
4888-
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
4868+
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
48894869
Labels: map[string]string{
48904870
"olm.owner": "operator-group-1",
48914871
"olm.owner.namespace": "operator-ns",
@@ -4895,8 +4875,7 @@ func TestSyncOperatorGroups(t *testing.T) {
48954875
},
48964876
&rbacv1.ClusterRole{
48974877
ObjectMeta: metav1.ObjectMeta{
4898-
ResourceVersion: "",
4899-
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
4878+
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
49004879
Labels: map[string]string{
49014880
"olm.owner": "operator-group-1",
49024881
"olm.owner.namespace": "operator-ns",
@@ -4913,8 +4892,7 @@ func TestSyncOperatorGroups(t *testing.T) {
49134892
"": {
49144893
&rbacv1.ClusterRole{
49154894
ObjectMeta: metav1.ObjectMeta{
4916-
ResourceVersion: "",
4917-
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
4895+
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
49184896
Labels: map[string]string{
49194897
"olm.owner": "operator-group-1",
49204898
"olm.owner.namespace": "operator-ns",
@@ -4924,8 +4902,7 @@ func TestSyncOperatorGroups(t *testing.T) {
49244902
},
49254903
&rbacv1.ClusterRole{
49264904
ObjectMeta: metav1.ObjectMeta{
4927-
ResourceVersion: "",
4928-
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
4905+
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
49294906
Labels: map[string]string{
49304907
"olm.owner": "operator-group-1",
49314908
"olm.owner.namespace": "operator-ns",
@@ -4935,8 +4912,7 @@ func TestSyncOperatorGroups(t *testing.T) {
49354912
},
49364913
&rbacv1.ClusterRole{
49374914
ObjectMeta: metav1.ObjectMeta{
4938-
ResourceVersion: "",
4939-
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
4915+
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
49404916
Labels: map[string]string{
49414917
"olm.owner": "operator-group-1",
49424918
"olm.owner.namespace": "operator-ns",

pkg/lib/ownerutil/util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ func CSVOwnerSelector(owner *operatorsv1alpha1.ClusterServiceVersion) labels.Sel
273273

274274
// OperatorGroupOwnerSelector returns a label selector to find generated objects owned by owner
275275
func OperatorGroupOwnerSelector(owner *operatorsv1.OperatorGroup) labels.Selector {
276-
return labels.SelectorFromSet(OwnerLabel(owner, "OperatorGroup"))
276+
return labels.SelectorFromSet(OwnerLabel(owner, operatorsv1.OperatorGroupKind))
277277
}
278278

279279
// AddOwner adds an owner to the ownerref list.

test/e2e/operator_groups_e2e_test.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import (
77
"time"
88

99
"github.com/blang/semver/v4"
10+
"github.com/google/go-cmp/cmp"
1011
. "github.com/onsi/ginkgo/v2"
1112
. "github.com/onsi/gomega"
13+
"github.com/stretchr/testify/assert"
1214
"github.com/stretchr/testify/require"
1315
authorizationv1 "k8s.io/api/authorization/v1"
1416
corev1 "k8s.io/api/core/v1"
@@ -351,18 +353,28 @@ var _ = Describe("Operator Group", func() {
351353
adminPolicyRules := []rbacv1.PolicyRule{
352354
{Verbs: []string{"*"}, APIGroups: []string{mainCRD.Spec.Group}, Resources: []string{mainCRDPlural}},
353355
}
354-
require.Equal(GinkgoT(), adminPolicyRules, role.Rules)
356+
if assert.Equal(GinkgoT(), adminPolicyRules, role.Rules) == false {
357+
fmt.Println(cmp.Diff(adminPolicyRules, role.Rules))
358+
GinkgoT().Fail()
359+
}
360+
355361
} else if strings.HasSuffix(role.Name, "edit") {
356362
editPolicyRules := []rbacv1.PolicyRule{
357363
{Verbs: []string{"create", "update", "patch", "delete"}, APIGroups: []string{mainCRD.Spec.Group}, Resources: []string{mainCRDPlural}},
358364
}
359-
require.Equal(GinkgoT(), editPolicyRules, role.Rules)
365+
if assert.Equal(GinkgoT(), editPolicyRules, role.Rules) == false {
366+
fmt.Println(cmp.Diff(editPolicyRules, role.Rules))
367+
GinkgoT().Fail()
368+
}
360369
} else if strings.HasSuffix(role.Name, "view") {
361370
viewPolicyRules := []rbacv1.PolicyRule{
362371
{Verbs: []string{"get"}, APIGroups: []string{"apiextensions.k8s.io"}, Resources: []string{"customresourcedefinitions"}, ResourceNames: []string{mainCRD.Name}},
363372
{Verbs: []string{"get", "list", "watch"}, APIGroups: []string{mainCRD.Spec.Group}, Resources: []string{mainCRDPlural}},
364373
}
365-
require.Equal(GinkgoT(), viewPolicyRules, role.Rules)
374+
if assert.Equal(GinkgoT(), viewPolicyRules, role.Rules) == false {
375+
fmt.Println(cmp.Diff(viewPolicyRules, role.Rules))
376+
GinkgoT().Fail()
377+
}
366378
}
367379
}
368380

0 commit comments

Comments
 (0)