@@ -24,6 +24,7 @@ import (
2424
2525 . "github.com/onsi/ginkgo/v2"
2626 . "github.com/onsi/gomega"
27+ corev1 "k8s.io/api/core/v1"
2728 "k8s.io/apimachinery/pkg/types"
2829 "sigs.k8s.io/yaml"
2930
@@ -41,7 +42,7 @@ var _ = Describe("Test CRD Status", Label("apisix.apache.org", "v2", "apisixrout
4142 Context ("Test ApisixRoute Sync Status" , func () {
4243 BeforeEach (func () {
4344 By ("create GatewayProxy" )
44- gatewayProxy := s .GetGatewayProxyYaml ()
45+ gatewayProxy := s .GetGatewayProxyWithServiceYaml ()
4546 err := s .CreateResourceFromString (gatewayProxy )
4647 Expect (err ).NotTo (HaveOccurred (), "creating GatewayProxy" )
4748 time .Sleep (5 * time .Second )
@@ -144,7 +145,8 @@ spec:
144145
145146 It ("dataplane unavailable" , func () {
146147 By ("apply ApisixRoute" )
147- applier .MustApplyAPIv2 (types.NamespacedName {Namespace : s .Namespace (), Name : "default" }, & apiv2.ApisixRoute {}, fmt .Sprintf (ar , s .Namespace (), s .Namespace ()))
148+ arYaml := fmt .Sprintf (ar , s .Namespace (), s .Namespace ())
149+ applier .MustApplyAPIv2 (types.NamespacedName {Namespace : s .Namespace (), Name : "default" }, & apiv2.ApisixRoute {}, arYaml )
148150
149151 By ("check route in APISIX" )
150152 s .RequestAssert (& scaffold.RequestAssert {
@@ -154,27 +156,51 @@ spec:
154156 Check : scaffold .WithExpectedStatus (200 ),
155157 })
156158
157- s .Deployer .ScaleDataplane (0 )
159+ By ("get yaml from service" )
160+ serviceYaml , err := s .GetOutputFromString ("svc" , framework .ProviderType , "-o" , "yaml" )
161+ Expect (err ).NotTo (HaveOccurred (), "getting service yaml" )
162+ By ("update service to type ExternalName with invalid host" )
163+ var k8sservice corev1.Service
164+ err = yaml .Unmarshal ([]byte (serviceYaml ), & k8sservice )
165+ Expect (err ).NotTo (HaveOccurred (), "unmarshalling service" )
166+ oldSpec := k8sservice .Spec
167+ k8sservice .Spec = corev1.ServiceSpec {
168+ Type : corev1 .ServiceTypeExternalName ,
169+ ExternalName : "invalid.host" ,
170+ }
171+ newServiceYaml , err := yaml .Marshal (k8sservice )
172+ Expect (err ).NotTo (HaveOccurred (), "marshalling service" )
173+ err = s .CreateResourceFromString (string (newServiceYaml ))
174+ Expect (err ).NotTo (HaveOccurred (), "creating service" )
158175
159176 By ("check ApisixRoute status" )
160177 s .RetryAssertion (func () string {
161- output , _ := s .GetOutputFromString ("ar" , "default" , "-o" , "yaml" , "-n" , s . Namespace () )
178+ output , _ := s .GetOutputFromString ("ar" , "default" , "-o" , "yaml" )
162179 return output
163- }).WithTimeout (80 * time .Second ).
180+ }).WithTimeout (60 * time .Second ).
164181 Should (
165182 And (
166183 ContainSubstring (`status: "False"` ),
167184 ContainSubstring (`reason: SyncFailed` ),
168185 ),
169186 )
170187
171- s .Deployer .ScaleDataplane (1 )
188+ By ("update service to original spec" )
189+ serviceYaml , err = s .GetOutputFromString ("svc" , framework .ProviderType , "-o" , "yaml" )
190+ Expect (err ).NotTo (HaveOccurred (), "getting service yaml" )
191+ err = yaml .Unmarshal ([]byte (serviceYaml ), & k8sservice )
192+ Expect (err ).NotTo (HaveOccurred (), "unmarshalling service" )
193+ k8sservice .Spec = oldSpec
194+ newServiceYaml , err = yaml .Marshal (k8sservice )
195+ Expect (err ).NotTo (HaveOccurred (), "marshalling service" )
196+ err = s .CreateResourceFromString (string (newServiceYaml ))
197+ Expect (err ).NotTo (HaveOccurred (), "creating service" )
172198
173199 By ("check ApisixRoute status after scaling up" )
174200 s .RetryAssertion (func () string {
175- output , _ := s .GetOutputFromString ("ar" , "default" , "-o" , "yaml" , "-n" , s . Namespace () )
201+ output , _ := s .GetOutputFromString ("ar" , "default" , "-o" , "yaml" )
176202 return output
177- }).WithTimeout (80 * time .Second ).
203+ }).WithTimeout (60 * time .Second ).
178204 Should (
179205 And (
180206 ContainSubstring (`status: "True"` ),
0 commit comments