Skip to content

Commit ca112b7

Browse files
shaneuttopenshift-merge-bot[bot]
authored andcommitted
feat: add manifest loaders for the gwapi cluster roles
Signed-off-by: Shane Utt <[email protected]>
1 parent 0072a35 commit ca112b7

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

pkg/manifests/manifests.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ const (
4242
CanaryServiceAsset = "assets/canary/service.yaml"
4343
CanaryRouteAsset = "assets/canary/route.yaml"
4444

45-
GatewayClassCRDAsset = "assets/gateway-api/gateway.networking.k8s.io_gatewayclasses.yaml"
46-
GatewayCRDAsset = "assets/gateway-api/gateway.networking.k8s.io_gateways.yaml"
47-
GRPCRouteCRDAsset = "assets/gateway-api/gateway.networking.k8s.io_grpcroutes.yaml"
48-
HTTPRouteCRDAsset = "assets/gateway-api/gateway.networking.k8s.io_httproutes.yaml"
49-
ReferenceGrantCRDAsset = "assets/gateway-api/gateway.networking.k8s.io_referencegrants.yaml"
45+
GatewayClassCRDAsset = "assets/gateway-api/gateway.networking.k8s.io_gatewayclasses.yaml"
46+
GatewayCRDAsset = "assets/gateway-api/gateway.networking.k8s.io_gateways.yaml"
47+
GRPCRouteCRDAsset = "assets/gateway-api/gateway.networking.k8s.io_grpcroutes.yaml"
48+
HTTPRouteCRDAsset = "assets/gateway-api/gateway.networking.k8s.io_httproutes.yaml"
49+
ReferenceGrantCRDAsset = "assets/gateway-api/gateway.networking.k8s.io_referencegrants.yaml"
50+
GatewayAPIAdminClusterRoleAsset = "assets/gateway-api/aggregated-cluster-roles/admin-cluster-role.yaml"
51+
GatewayAPIViewClusterRoleAsset = "assets/gateway-api/aggregated-cluster-roles/view-cluster-role.yaml"
5052

5153
// Annotation used to inform the certificate generation service to
5254
// generate a cluster-signed certificate and populate the secret.
@@ -296,6 +298,22 @@ func ReferenceGrantCRD() *apiextensionsv1.CustomResourceDefinition {
296298
return crd
297299
}
298300

301+
func GatewayAPIAdminClusterRole() *rbacv1.ClusterRole {
302+
clusterRole, err := NewClusterRole(MustAssetReader(GatewayAPIAdminClusterRoleAsset))
303+
if err != nil {
304+
panic(err)
305+
}
306+
return clusterRole
307+
}
308+
309+
func GatewayAPIViewClusterRole() *rbacv1.ClusterRole {
310+
clusterRole, err := NewClusterRole(MustAssetReader(GatewayAPIViewClusterRoleAsset))
311+
if err != nil {
312+
panic(err)
313+
}
314+
return clusterRole
315+
}
316+
299317
func NewServiceAccount(manifest io.Reader) (*corev1.ServiceAccount, error) {
300318
sa := corev1.ServiceAccount{}
301319
if err := yaml.NewYAMLOrJSONDecoder(manifest, 100).Decode(&sa); err != nil {

pkg/manifests/manifests_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package manifests
22

33
import (
4+
"slices"
5+
"strings"
46
"testing"
57

68
operatorv1 "github.com/openshift/api/operator/v1"
@@ -50,6 +52,19 @@ func TestManifests(t *testing.T) {
5052
HTTPRouteCRD()
5153
ReferenceGrantCRD()
5254

55+
adminOnlyVerbs := []string{"create", "update", "patch", "delete", "deletecollection"}
56+
GatewayAPIAdminClusterRole()
57+
viewClusterRole := GatewayAPIViewClusterRole()
58+
for _, policyRule := range viewClusterRole.Rules {
59+
for _, adminOnlyVerb := range adminOnlyVerbs {
60+
if slices.ContainsFunc(policyRule.Verbs, func(verb string) bool {
61+
return strings.EqualFold(verb, adminOnlyVerb)
62+
}) {
63+
t.Errorf("view role %s should only contain read verbs, found: %s", viewClusterRole.Name, adminOnlyVerb)
64+
}
65+
}
66+
}
67+
5368
MustAsset(CustomResourceDefinitionManifest)
5469
MustAsset(NamespaceManifest)
5570
}

0 commit comments

Comments
 (0)