Skip to content

Commit

Permalink
Adds ReferenceGrant Tests for TCPRoute (#10419)
Browse files Browse the repository at this point in the history
Signed-off-by: Daneyon Hansen <[email protected]>
Co-authored-by: Sam Heilbron <[email protected]>
  • Loading branch information
danehans and sam-heilbron authored Dec 5, 2024
1 parent 10e7739 commit d0fe477
Show file tree
Hide file tree
Showing 44 changed files with 1,778 additions and 4,581 deletions.
11 changes: 11 additions & 0 deletions changelog/v1.19.0-beta1/issue_7309_issue_10434.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
changelog:
- type: FIX
issueLink: https://github.com/solo-io/solo-projects/issues/7309
resolvesIssue: true
description: >-
Adds tests for TCPRoute ReferenceGrant support to ensure cross namespace references.
- type: FIX
issueLink: https://github.com/solo-io/gloo/issues/10434
resolvesIssue: true
description: >-
Increases the assertion timeout for TCPRoute e2e test cases.
2 changes: 1 addition & 1 deletion pkg/schemes/extended_scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
gwv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
)

// AddGatewayV1A2Scheme adds the gwv1a2 scheme to the provided scheme if the TCPRoute CRD exists.
// AddGatewayV1A2Scheme adds the Gateway v1alpha2 scheme to the provided scheme if the TCPRoute CRD exists.
func AddGatewayV1A2Scheme(restConfig *rest.Config, scheme *runtime.Scheme) error {
exists, err := CRDExists(restConfig, gwv1a2.GroupVersion.Group, gwv1a2.GroupVersion.Version, wellknown.TCPRouteKind)
if err != nil {
Expand Down
10 changes: 7 additions & 3 deletions pkg/schemes/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,15 @@ func DefaultScheme() *runtime.Scheme {
return s
}

// TestingScheme unconditionally includes the default scheme and the gwv1a2 scheme (which includes TCPRoute).
func TestingScheme() *runtime.Scheme {
// GatewayScheme unconditionally includes the default and required Gateway API schemes.
// Use the Default scheme with AddGatewayV1A2Scheme to conditionally add the v1alpha2 scheme.
func GatewayScheme() *runtime.Scheme {
s := DefaultScheme()
if err := gwv1a2.Install(s); err != nil {
panic(fmt.Sprintf("Failed to install gwv1a2 scheme: %v", err))
panic(fmt.Sprintf("Failed to install gateway v1alpha2 scheme: %v", err))
}
if err := gwv1b1.Install(s); err != nil {
panic(fmt.Sprintf("Failed to install gateway v1beta1 scheme: %v", err))
}
return s
}
4 changes: 2 additions & 2 deletions projects/gateway2/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (c *controllerBuilder) addIndexes(ctx context.Context) error {
}

// Conditionally index for TCPRoute
if c.cfg.CRDs.Has(wellknown.TCPRouteCRD) {
if c.cfg.CRDs.Has(wellknown.TCPRouteCRDName) {
if err := c.cfg.Mgr.GetFieldIndexer().IndexField(ctx, &apiv1a2.TCPRoute{}, query.TcpRouteTargetField, query.IndexerByObjType); err != nil {
errs = append(errs, err)
}
Expand Down Expand Up @@ -317,7 +317,7 @@ func (c *controllerBuilder) watchHttpRoute(_ context.Context) error {
}

func (c *controllerBuilder) watchTcpRoute(ctx context.Context) error {
if !c.cfg.CRDs.Has(wellknown.TCPRouteCRD) {
if !c.cfg.CRDs.Has(wellknown.TCPRouteCRDName) {
log.FromContext(ctx).Info("TCPRoute type not registered in scheme; skipping TCPRoute controller setup")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion projects/gateway2/controller/controller_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ var _ = BeforeSuite(func() {
cfg, err = testEnv.Start()
Expect(err).NotTo(HaveOccurred())
Expect(cfg).NotTo(BeNil())
scheme := schemes.DefaultScheme()
scheme := schemes.GatewayScheme()
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme})
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())
Expand Down
2 changes: 1 addition & 1 deletion projects/gateway2/controller/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func getGatewayCRDs(restConfig *rest.Config) (sets.Set[string], error) {
}

if tcpRouteExists {
crds.Insert(wellknown.TCPRouteCRD)
crds.Insert(wellknown.TCPRouteCRDName)
}

return crds, nil
Expand Down
Loading

0 comments on commit d0fe477

Please sign in to comment.