Skip to content

Commit 439cfd5

Browse files
committed
fix:
1 parent c68dc05 commit 439cfd5

File tree

2 files changed

+25
-34
lines changed

2 files changed

+25
-34
lines changed

internal/controller/httproutepolicy.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ func (r *HTTPRouteReconciler) processHTTPRoutePolicies(tctx *provider.TranslateC
4545
return nil
4646
}
4747

48+
// set namespace in prentRef if it is not set
49+
var parentRefs = make([]gatewayv1.ParentReference, len(httpRoute.Spec.ParentRefs))
50+
for i := range httpRoute.Spec.ParentRefs {
51+
ref := httpRoute.Spec.ParentRefs[i]
52+
if ref.Namespace == nil || *ref.Namespace == "" {
53+
ref.Namespace = (*gatewayv1.Namespace)(&httpRoute.Namespace)
54+
}
55+
parentRefs[i] = ref
56+
}
57+
4858
var conflicts = make(map[types.NamespacedName]v1alpha1.HTTPRoutePolicy)
4959
for _, rule := range httpRoute.Spec.Rules {
5060
var policies = findPoliciesWhichTargetRefTheRule(rule.Name, "HTTPRoute", list)
@@ -70,7 +80,7 @@ func (r *HTTPRouteReconciler) processHTTPRoutePolicies(tctx *provider.TranslateC
7080
tctx.HTTPRoutePolicies = append(tctx.HTTPRoutePolicies, policy)
7181
}
7282

73-
if updated := setAncestorsForHTTPRoutePolicyStatus(httpRoute.Spec.ParentRefs, &policy, condition); updated {
83+
if updated := setAncestorsForHTTPRoutePolicyStatus(parentRefs, &policy, condition); updated {
7484
tctx.StatusUpdaters = append(tctx.StatusUpdaters, &policy)
7585
}
7686
}

test/e2e/gatewayapi/httproute.go

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -103,26 +103,6 @@ spec:
103103
kind: GatewayProxy
104104
name: apisix-proxy-config
105105
`
106-
107-
var ResourceApplied = func(resourType, resourceName, resourceRaw string, observedGeneration int) {
108-
Expect(s.CreateResourceFromString(resourceRaw)).
109-
NotTo(HaveOccurred(), fmt.Sprintf("creating %s", resourType))
110-
111-
Eventually(func() string {
112-
hryaml, err := s.GetResourceYaml(resourType, resourceName)
113-
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("getting %s yaml", resourType))
114-
return hryaml
115-
}, "8s", "2s").
116-
Should(
117-
SatisfyAll(
118-
ContainSubstring(`status: "True"`),
119-
ContainSubstring(fmt.Sprintf("observedGeneration: %d", observedGeneration)),
120-
),
121-
fmt.Sprintf("checking %s condition status", resourType),
122-
)
123-
time.Sleep(1 * time.Second)
124-
}
125-
126106
var beforeEachHTTP = func() {
127107
By("create GatewayProxy")
128108
gatewayProxy := fmt.Sprintf(gatewayProxyYaml, framework.DashboardTLSEndpoint, s.AdminKey())
@@ -929,20 +909,18 @@ spec:
929909
- http-route-policy-0
930910
`
931911
By("create HTTPRoute")
932-
ResourceApplied("HTTPRoute", "httpbin", varsRoute, 1)
912+
s.ApplyHTTPRoute(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin"}, varsRoute)
933913

934914
By("create HTTPRoutePolices")
935915
for name, spec := range map[string]string{
936916
"http-route-policy-0": httpRoutePolicy0,
937917
"http-route-policy-1": httpRoutePolicy1,
938918
"http-route-policy-2": httpRoutePolicy2,
939919
} {
940-
err := s.CreateResourceFromString(spec)
941-
Expect(err).NotTo(HaveOccurred(), "creating HTTPRoutePolicy")
942-
// wait for HTTPRoutePolicy is Accepted
943-
framework.HTTPRoutePolicyMustHaveCondition(s.GinkgoT, s.K8sClient, 10*time.Second,
920+
s.ApplyHTTPRoutePolicy(
944921
types.NamespacedName{Namespace: s.Namespace(), Name: "apisix"},
945922
types.NamespacedName{Namespace: s.Namespace(), Name: name},
923+
spec,
946924
metav1.Condition{
947925
Type: string(v1alpha2.PolicyConditionAccepted),
948926
},
@@ -1414,15 +1392,14 @@ spec:
14141392
- name: httpbin-service-e2e-test
14151393
port: 80
14161394
`
1417-
ResourceApplied("HTTPRoute", "httpbin", echoRoute, 1)
1395+
s.ApplyHTTPRoute(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin"}, echoRoute, func(_ context.Context) (done bool, err error) {
1396+
return s.NewAPISIXClient().GET("/headers").
1397+
WithHeader("Host", "httpbin.example").
1398+
Expect().Raw().StatusCode == http.StatusOK, nil
1399+
})
14181400

14191401
time.Sleep(time.Second * 6)
14201402

1421-
_ = s.NewAPISIXClient().GET("/headers").
1422-
WithHeader("Host", "httpbin.example").
1423-
Expect().
1424-
Status(http.StatusOK)
1425-
14261403
echoLogs := s.GetDeploymentLogs("echo")
14271404
Expect(echoLogs).To(ContainSubstring("GET /headers"))
14281405
})
@@ -1554,7 +1531,11 @@ spec:
15541531
})
15551532
})
15561533
It("HTTPRoute Canary", func() {
1557-
ResourceApplied("HTTPRoute", "httpbin", sameWeight, 1)
1534+
s.ApplyHTTPRoute(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin"}, sameWeight, func(_ context.Context) (done bool, err error) {
1535+
return s.NewAPISIXClient().GET("/get").
1536+
WithHeader("Host", "httpbin.example").
1537+
Expect().Raw().StatusCode == http.StatusOK, nil
1538+
})
15581539

15591540
var (
15601541
hitNginxCnt = 0
@@ -1575,7 +1556,7 @@ spec:
15751556
}
15761557
Expect(hitNginxCnt - hitHttpbinCnt).To(BeNumerically("~", 0, 2))
15771558

1578-
ResourceApplied("HTTPRoute", "httpbin", oneWeight, 2)
1559+
s.ApplyHTTPRoute(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin"}, oneWeight)
15791560

15801561
hitNginxCnt = 0
15811562
hitHttpbinCnt = 0

0 commit comments

Comments
 (0)