Skip to content

Commit 42cbb61

Browse files
author
Doyoon Kim
authored
Fix e2e tests and examples to be compatible w/ latest CRDs (#515)
* Fix e2e tests and examples to be compatible w/ latest CRDs * Fix empty rule matching behavior
1 parent 24a25cf commit 42cbb61

14 files changed

+77
-27
lines changed

examples/my-hotel-gateway-tls.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ spec:
1111
- name: https
1212
protocol: HTTPS
1313
port: 443
14-
- name: tls-with-customer-cert
15-
protocol: HTTPS
16-
port: 443
1714
tls:
1815
mode: Terminate
16+
certificateRefs:
17+
- name: unused
1918
options:
20-
application-networking.k8s.aws/certificate-arn: arn:aws:acm:us-west-2:<account>:certificate/4555204d-07e1-43f0-a533-d02750f41545
19+
application-networking.k8s.aws/certificate-arn: "" # arn:aws:acm:us-west-2:<account>:certificate/<certificate-id>

examples/parking-route-path.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ spec:
1010
- backendRefs:
1111
- name: parking-ver1
1212
kind: Service
13+
port: 80
1314
matches:
1415
- path:
1516
type: PathPrefix

examples/second-account-gw1-full-setup.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ spec:
6262
- backendRefs:
6363
- name: second-account-gw1-svc
6464
kind: Service
65+
port: 80
6566
matches:
6667
- path:
6768
type: PathPrefix

examples/tls-route-with-own-cert.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ spec:
77
- tls-parking.my-test.com
88
parentRefs:
99
- name: my-hotel
10-
sectionName: tls-with-customer-cert
10+
sectionName: https
1111
rules:
1212
- backendRefs:
1313
- name: parking-ver3

pkg/aws/services/tagging.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const (
1717
resourceTypePrefix = "vpc-lattice:"
1818

1919
ResourceTypeTargetGroup ResourceType = resourceTypePrefix + "targetgroup"
20+
ResourceTypeService ResourceType = resourceTypePrefix + "service"
2021

2122
// https://docs.aws.amazon.com/resourcegroupstagging/latest/APIReference/API_GetResources.html#API_GetResources_RequestSyntax
2223
maxArnsPerGetResourcesApi = 100

pkg/gateway/model_build_rule.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ func (t *latticeServiceModelBuildTask) buildRules(ctx context.Context, stackList
6161
if err := t.updateRuleSpecWithHeaderMatches(match, &ruleSpec); err != nil {
6262
return err
6363
}
64+
} else {
65+
// Match every traffic on no matches
66+
ruleSpec.PathMatchValue = "/"
67+
ruleSpec.PathMatchPrefix = true
68+
if _, ok := rule.(*core.GRPCRouteRule); ok {
69+
ruleSpec.Method = string(gwv1.HTTPMethodPost)
70+
}
6471
}
6572

6673
ruleTgList, err := t.getTargetGroupsForRuleAction(ctx, rule)

pkg/gateway/model_build_rule_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ func Test_RuleModelBuild(t *testing.T) {
153153
expectedSpec: []model.RuleSpec{ // note priority is only calculated at synthesis b/c it requires access to existing rules
154154
{
155155
StackListenerId: "listener-id",
156+
PathMatchPrefix: true,
157+
PathMatchValue: "/",
156158
Action: model.RuleAction{
157159
TargetGroups: []*model.RuleTargetGroup{
158160
{
@@ -195,6 +197,8 @@ func Test_RuleModelBuild(t *testing.T) {
195197
expectedSpec: []model.RuleSpec{
196198
{
197199
StackListenerId: "listener-id",
200+
PathMatchPrefix: true,
201+
PathMatchValue: "/",
198202
Action: model.RuleAction{
199203
TargetGroups: []*model.RuleTargetGroup{
200204
{
@@ -243,6 +247,8 @@ func Test_RuleModelBuild(t *testing.T) {
243247
expectedSpec: []model.RuleSpec{
244248
{
245249
StackListenerId: "listener-id",
250+
PathMatchPrefix: true,
251+
PathMatchValue: "/",
246252
Action: model.RuleAction{
247253
TargetGroups: []*model.RuleTargetGroup{
248254
{
@@ -564,6 +570,9 @@ func Test_RuleModelBuild(t *testing.T) {
564570
expectedSpec: []model.RuleSpec{
565571
{
566572
StackListenerId: "listener-id",
573+
Method: string(httpPost),
574+
PathMatchPrefix: true,
575+
PathMatchValue: "/",
567576
Action: model.RuleAction{
568577
TargetGroups: []*model.RuleTargetGroup{
569578
{
@@ -1407,6 +1416,8 @@ func Test_RuleModelBuild(t *testing.T) {
14071416
expectedSpec: []model.RuleSpec{
14081417
{
14091418
StackListenerId: "listener-id",
1419+
PathMatchPrefix: true,
1420+
PathMatchValue: "/",
14101421
Action: model.RuleAction{
14111422
TargetGroups: []*model.RuleTargetGroup{
14121423
{
@@ -1453,6 +1464,8 @@ func Test_RuleModelBuild(t *testing.T) {
14531464
expectedSpec: []model.RuleSpec{
14541465
{
14551466
StackListenerId: "listener-id",
1467+
PathMatchPrefix: true,
1468+
PathMatchValue: "/",
14561469
Action: model.RuleAction{
14571470
TargetGroups: []*model.RuleTargetGroup{
14581471
{

test/pkg/test/framework.go

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ type Framework struct {
107107
controllerRuntimeConfig *rest.Config
108108
Log gwlog.Logger
109109
LatticeClient services.Lattice
110+
TaggingClient services.Tagging
110111
Ec2Client *ec2.EC2
111112
GrpcurlRunner *corev1.Pod
112113
DefaultTags services.Tags
@@ -123,10 +124,12 @@ func NewFramework(ctx context.Context, log gwlog.Logger, testNamespace string) *
123124
Region: config.Region,
124125
ClusterName: config.ClusterName,
125126
}
127+
sess := session.Must(session.NewSession())
126128
framework := &Framework{
127129
Client: lo.Must(client.New(controllerRuntimeConfig, client.Options{Scheme: testScheme})),
128-
LatticeClient: services.NewDefaultLattice(session.Must(session.NewSession()), config.Region), // region is currently hardcoded
129-
Ec2Client: ec2.New(session.Must(session.NewSession(&aws.Config{Region: aws.String(config.Region)}))),
130+
LatticeClient: services.NewDefaultLattice(sess, config.Region),
131+
TaggingClient: services.NewDefaultTagging(sess, config.Region),
132+
Ec2Client: ec2.New(sess, &aws.Config{Region: aws.String(config.Region)}),
130133
GrpcurlRunner: &corev1.Pod{},
131134
ctx: ctx,
132135
Log: log,
@@ -150,25 +153,17 @@ func (env *Framework) ExpectToBeClean(ctx context.Context) {
150153
})
151154

152155
Eventually(func(g Gomega) {
153-
retrievedServices, _ := env.LatticeClient.ListServicesAsList(ctx, &vpclattice.ListServicesInput{})
154-
for _, service := range retrievedServices {
155-
env.Log.Infof("Found service, checking if created by current EKS Cluster: %v", service)
156-
managed, err := env.Cloud.IsArnManaged(ctx, *service.Arn)
157-
if err == nil { // ignore error as they can be a shared resource.
158-
g.Expect(managed).To(BeFalse())
159-
}
160-
}
156+
arns, err := env.TaggingClient.FindResourcesByTags(ctx, services.ResourceTypeService, env.DefaultTags)
157+
env.Log.Infow("Expecting no services created by the controller", "found", arns)
158+
g.Expect(err).To(BeNil())
159+
g.Expect(arns).To(BeEmpty())
160+
}).Should(Succeed())
161161

162-
retrievedTargetGroups, _ := env.LatticeClient.ListTargetGroupsAsList(ctx, &vpclattice.ListTargetGroupsInput{
163-
VpcIdentifier: &config.VpcID,
164-
})
165-
for _, tg := range retrievedTargetGroups {
166-
env.Log.Infof("Found TargetGroup: %s, checking if created by current EKS Cluster", *tg.Id)
167-
managed, err := env.Cloud.IsArnManaged(ctx, *tg.Arn)
168-
if err == nil { // ignore error as they can be a shared resource.
169-
g.Expect(managed).To(BeFalse())
170-
}
171-
}
162+
Eventually(func(g Gomega) {
163+
arns, err := env.TaggingClient.FindResourcesByTags(ctx, services.ResourceTypeTargetGroup, env.DefaultTags)
164+
env.Log.Infow("Expecting no target groups created by the controller", "found", arns)
165+
g.Expect(err).To(BeNil())
166+
g.Expect(arns).To(BeEmpty())
172167
}).Should(Succeed())
173168
}
174169

test/pkg/test/gateway.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package test
22

33
import (
4+
"github.com/samber/lo"
45
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
56
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
67
)
@@ -27,6 +28,14 @@ func (env *Framework) NewGateway(name string, namespace string) *gwv1.Gateway {
2728
Name: "https",
2829
Protocol: gwv1.HTTPSProtocolType,
2930
Port: 443,
31+
TLS: &gwv1.GatewayTLSConfig{
32+
Mode: lo.ToPtr(gwv1.TLSModeTerminate),
33+
CertificateRefs: []gwv1.SecretObjectReference{
34+
{
35+
Name: "dummy",
36+
},
37+
},
38+
},
3039
},
3140
},
3241
},

test/pkg/test/header_match_httproute.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func (env *Framework) NewHeaderMatchHttpRoute(parentRefsGateway *gwv1.Gateway, s
1616
BackendObjectReference: gwv1.BackendObjectReference{
1717
Name: gwv1.ObjectName(service.Name),
1818
Kind: lo.ToPtr(gwv1.Kind("Service")),
19+
Port: (*gwv1.PortNumber)(&service.Spec.Ports[0].Port),
1920
},
2021
},
2122
}},

0 commit comments

Comments
 (0)