Skip to content

Commit

Permalink
fixup! Rename ClusterRoles created by OperatorGroups
Browse files Browse the repository at this point in the history
Signed-off-by: Todd Short <[email protected]>
  • Loading branch information
tmshort committed Sep 19, 2023
1 parent a4a9685 commit 88725b8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 52 deletions.
72 changes: 24 additions & 48 deletions pkg/controller/operators/olm/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4560,8 +4560,7 @@ func TestSyncOperatorGroups(t *testing.T) {
"": {
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns",
Expand All @@ -4571,8 +4570,7 @@ func TestSyncOperatorGroups(t *testing.T) {
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns",
Expand All @@ -4582,8 +4580,7 @@ func TestSyncOperatorGroups(t *testing.T) {
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns",
Expand Down Expand Up @@ -4624,8 +4621,7 @@ func TestSyncOperatorGroups(t *testing.T) {
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "operator-group-1-admin",
Name: "operator-group-1-admin",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns",
Expand All @@ -4635,8 +4631,7 @@ func TestSyncOperatorGroups(t *testing.T) {
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "operator-group-1-view",
Name: "operator-group-1-view",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns",
Expand All @@ -4646,8 +4641,7 @@ func TestSyncOperatorGroups(t *testing.T) {
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "operator-group-1-edit",
Name: "operator-group-1-edit",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns",
Expand All @@ -4665,8 +4659,7 @@ func TestSyncOperatorGroups(t *testing.T) {
"": {
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns",
Expand All @@ -4676,8 +4669,7 @@ func TestSyncOperatorGroups(t *testing.T) {
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns",
Expand All @@ -4687,8 +4679,7 @@ func TestSyncOperatorGroups(t *testing.T) {
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns",
Expand All @@ -4698,8 +4689,7 @@ func TestSyncOperatorGroups(t *testing.T) {
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "operator-group-1-admin",
Name: "operator-group-1-admin",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns",
Expand All @@ -4709,8 +4699,7 @@ func TestSyncOperatorGroups(t *testing.T) {
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "operator-group-1-view",
Name: "operator-group-1-view",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns",
Expand All @@ -4720,8 +4709,7 @@ func TestSyncOperatorGroups(t *testing.T) {
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "operator-group-1-edit",
Name: "operator-group-1-edit",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns",
Expand Down Expand Up @@ -4762,8 +4750,7 @@ func TestSyncOperatorGroups(t *testing.T) {
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns-bob",
Expand All @@ -4774,8 +4761,7 @@ func TestSyncOperatorGroups(t *testing.T) {
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
Labels: map[string]string{
"olm.owner": "operator-group-5",
"olm.owner.namespace": "operator-ns",
Expand All @@ -4787,8 +4773,7 @@ func TestSyncOperatorGroups(t *testing.T) {
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns",
Expand All @@ -4806,8 +4791,7 @@ func TestSyncOperatorGroups(t *testing.T) {
"": {
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns",
Expand All @@ -4818,8 +4802,7 @@ func TestSyncOperatorGroups(t *testing.T) {
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns",
Expand All @@ -4829,8 +4812,7 @@ func TestSyncOperatorGroups(t *testing.T) {
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns",
Expand Down Expand Up @@ -4873,8 +4855,7 @@ func TestSyncOperatorGroups(t *testing.T) {
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns",
Expand All @@ -4884,8 +4865,7 @@ func TestSyncOperatorGroups(t *testing.T) {
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns",
Expand All @@ -4895,8 +4875,7 @@ func TestSyncOperatorGroups(t *testing.T) {
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns",
Expand All @@ -4913,8 +4892,7 @@ func TestSyncOperatorGroups(t *testing.T) {
"": {
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
Name: "olm.og.operator-group-1.admin-8rdAjL0E35JMMAkOqYmoorzjpIIihfnj3DcgDU",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns",
Expand All @@ -4924,8 +4902,7 @@ func TestSyncOperatorGroups(t *testing.T) {
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
Name: "olm.og.operator-group-1.edit-9lBEUxqAYE7CX7wZfFEPYutTfQTo43WarB08od",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns",
Expand All @@ -4935,8 +4912,7 @@ func TestSyncOperatorGroups(t *testing.T) {
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "",
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
Name: "olm.og.operator-group-1.view-1l6ymczPK5SceF4d0DCtAnWZuvmKn6s8oBUxHr",
Labels: map[string]string{
"olm.owner": "operator-group-1",
"olm.owner.namespace": "operator-ns",
Expand Down
2 changes: 1 addition & 1 deletion pkg/lib/ownerutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func CSVOwnerSelector(owner *operatorsv1alpha1.ClusterServiceVersion) labels.Sel

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

// AddOwner adds an owner to the ownerref list.
Expand Down
18 changes: 15 additions & 3 deletions test/e2e/operator_groups_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"time"

"github.com/blang/semver/v4"
"github.com/google/go-cmp/cmp"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
authorizationv1 "k8s.io/api/authorization/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -351,18 +353,28 @@ var _ = Describe("Operator Group", func() {
adminPolicyRules := []rbacv1.PolicyRule{
{Verbs: []string{"*"}, APIGroups: []string{mainCRD.Spec.Group}, Resources: []string{mainCRDPlural}},
}
require.Equal(GinkgoT(), adminPolicyRules, role.Rules)
if assert.Equal(GinkgoT(), adminPolicyRules, role.Rules) == false {
fmt.Println(cmp.Diff(adminPolicyRules, role.Rules))
GinkgoT().Fail()
}

} else if strings.HasSuffix(role.Name, "edit") {
editPolicyRules := []rbacv1.PolicyRule{
{Verbs: []string{"create", "update", "patch", "delete"}, APIGroups: []string{mainCRD.Spec.Group}, Resources: []string{mainCRDPlural}},
}
require.Equal(GinkgoT(), editPolicyRules, role.Rules)
if assert.Equal(GinkgoT(), editPolicyRules, role.Rules) == false {
fmt.Println(cmp.Diff(editPolicyRules, role.Rules))
GinkgoT().Fail()
}
} else if strings.HasSuffix(role.Name, "view") {
viewPolicyRules := []rbacv1.PolicyRule{
{Verbs: []string{"get"}, APIGroups: []string{"apiextensions.k8s.io"}, Resources: []string{"customresourcedefinitions"}, ResourceNames: []string{mainCRD.Name}},
{Verbs: []string{"get", "list", "watch"}, APIGroups: []string{mainCRD.Spec.Group}, Resources: []string{mainCRDPlural}},
}
require.Equal(GinkgoT(), viewPolicyRules, role.Rules)
if assert.Equal(GinkgoT(), viewPolicyRules, role.Rules) == false {
fmt.Println(cmp.Diff(viewPolicyRules, role.Rules))
GinkgoT().Fail()
}
}
}

Expand Down

0 comments on commit 88725b8

Please sign in to comment.