@@ -3,23 +3,28 @@ package integration
33import (
44 "time"
55
6- "github.com/aws/aws-application-networking-k8s/pkg/apis/applicationnetworking/v1alpha1"
7- "github.com/aws/aws-application-networking-k8s/test/pkg/test"
86 "github.com/aws/aws-sdk-go/aws"
97 "github.com/aws/aws-sdk-go/service/vpclattice"
108 . "github.com/onsi/ginkgo/v2"
119 . "github.com/onsi/gomega"
1210 appsv1 "k8s.io/api/apps/v1"
1311 corev1 "k8s.io/api/core/v1"
12+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13+ "sigs.k8s.io/controller-runtime/pkg/client"
1414 gwv1 "sigs.k8s.io/gateway-api/apis/v1"
15+ gwv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
16+ gwv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
17+
18+ anv1alpha1 "github.com/aws/aws-application-networking-k8s/pkg/apis/applicationnetworking/v1alpha1"
19+ "github.com/aws/aws-application-networking-k8s/test/pkg/test"
1520)
1621
1722var _ = Describe ("Target Group Policy Tests" , Ordered , func () {
1823 var (
1924 deployment * appsv1.Deployment
2025 service * corev1.Service
2126 httpRoute * gwv1.HTTPRoute
22- policy * v1alpha1 .TargetGroupPolicy
27+ policy * anv1alpha1 .TargetGroupPolicy
2328 )
2429
2530 BeforeAll (func () {
@@ -34,22 +39,23 @@ var _ = Describe("Target Group Policy Tests", Ordered, func() {
3439 })
3540
3641 It ("Update Protocol replaces the Target Group with new one" , func () {
37- policy = testFramework . CreateTargetGroupPolicy (service , & test. TargetGroupPolicyConfig {
42+ policy = createTargetGroupPolicy (service , & TargetGroupPolicyConfig {
3843 PolicyName : "test-policy" ,
3944 Protocol : aws .String (vpclattice .TargetGroupProtocolHttp ),
4045 })
4146
4247 testFramework .ExpectCreated (ctx , policy )
4348
4449 tg := testFramework .GetTargetGroup (ctx , service )
45-
4650 Expect (* tg .Protocol ).To (Equal (vpclattice .TargetGroupProtocolHttp ))
4751
48- testFramework .UpdateTargetGroupPolicy (policy , & test.TargetGroupPolicyConfig {
49- Protocol : aws .String (vpclattice .TargetGroupProtocolHttps ),
50- })
52+ err := testFramework .Client .Get (ctx , client .ObjectKeyFromObject (policy ), policy )
53+ Expect (err ).Should (BeNil ())
54+
55+ policy .Spec .Protocol = aws .String (vpclattice .TargetGroupProtocolHttps )
56+ err = testFramework .Client .Update (ctx , policy )
57+ Expect (err ).Should (BeNil ())
5158
52- testFramework .ExpectUpdated (ctx , policy )
5359 testFramework .VerifyTargetGroupNotFound (tg )
5460
5561 httpsTG := testFramework .GetTargetGroupWithProtocol (ctx , service , "https" , "http1" )
@@ -58,11 +64,11 @@ var _ = Describe("Target Group Policy Tests", Ordered, func() {
5864 })
5965
6066 It ("Delete Target Group Policy reset health check config for HTTP and HTTP1 Target Group" , func () {
61- policy = testFramework . CreateTargetGroupPolicy (service , & test. TargetGroupPolicyConfig {
67+ policy = createTargetGroupPolicy (service , & TargetGroupPolicyConfig {
6268 PolicyName : "test-policy" ,
6369 Protocol : aws .String (vpclattice .TargetGroupProtocolHttp ),
6470 ProtocolVersion : aws .String (vpclattice .TargetGroupProtocolVersionHttp1 ),
65- HealthCheck : & v1alpha1 .HealthCheckConfig {
71+ HealthCheck : & anv1alpha1 .HealthCheckConfig {
6672 IntervalSeconds : aws .Int64 (7 ),
6773 StatusMatch : aws .String ("200,204" ),
6874 },
@@ -72,9 +78,7 @@ var _ = Describe("Target Group Policy Tests", Ordered, func() {
7278
7379 Eventually (func (g Gomega ) {
7480 tgSummary := testFramework .GetTargetGroup (ctx , service )
75-
7681 tg := testFramework .GetFullTargetGroupFromSummary (ctx , tgSummary )
77-
7882 g .Expect (* tg .Config .HealthCheck .ProtocolVersion ).To (Equal (vpclattice .TargetGroupProtocolVersionHttp1 ))
7983 g .Expect (* tg .Config .HealthCheck .Protocol ).To (Equal (vpclattice .TargetGroupProtocolHttp ))
8084 g .Expect (* tg .Config .HealthCheck .HealthCheckIntervalSeconds ).To (BeEquivalentTo (7 ))
@@ -106,7 +110,7 @@ var _ = Describe("Target Group Policy Tests", Ordered, func() {
106110 })
107111
108112 It ("Delete Target Group Policy create HTTP and HTTP1 Target Group" , func () {
109- policy = testFramework . CreateTargetGroupPolicy (service , & test. TargetGroupPolicyConfig {
113+ policy = createTargetGroupPolicy (service , & TargetGroupPolicyConfig {
110114 PolicyName : "test-policy" ,
111115 Protocol : aws .String (vpclattice .TargetGroupProtocolHttps ),
112116 ProtocolVersion : aws .String (vpclattice .TargetGroupProtocolVersionHttp2 ),
@@ -128,7 +132,12 @@ var _ = Describe("Target Group Policy Tests", Ordered, func() {
128132 AfterEach (func () {
129133 testFramework .ExpectDeleted (
130134 ctx ,
131- policy ,
135+ & anv1alpha1.TargetGroupPolicy {
136+ ObjectMeta : metav1.ObjectMeta {
137+ Name : policy .Name ,
138+ Namespace : policy .Namespace ,
139+ },
140+ },
132141 )
133142 })
134143
@@ -141,3 +150,34 @@ var _ = Describe("Target Group Policy Tests", Ordered, func() {
141150 )
142151 })
143152})
153+
154+ type TargetGroupPolicyConfig struct {
155+ PolicyName string
156+ Protocol * string
157+ ProtocolVersion * string
158+ HealthCheck * anv1alpha1.HealthCheckConfig
159+ }
160+
161+ func createTargetGroupPolicy (
162+ service * corev1.Service ,
163+ config * TargetGroupPolicyConfig ,
164+ ) * anv1alpha1.TargetGroupPolicy {
165+ return & anv1alpha1.TargetGroupPolicy {
166+ TypeMeta : metav1.TypeMeta {
167+ Kind : "TargetGroupPolicy" ,
168+ },
169+ ObjectMeta : metav1.ObjectMeta {
170+ Namespace : service .Namespace ,
171+ Name : config .PolicyName ,
172+ },
173+ Spec : anv1alpha1.TargetGroupPolicySpec {
174+ TargetRef : & gwv1alpha2.PolicyTargetReference {
175+ Kind : gwv1beta1 .Kind ("Service" ),
176+ Name : gwv1beta1 .ObjectName (service .Name ),
177+ },
178+ Protocol : config .Protocol ,
179+ ProtocolVersion : config .ProtocolVersion ,
180+ HealthCheck : config .HealthCheck ,
181+ },
182+ }
183+ }
0 commit comments