This is an automated email from the ASF dual-hosted git repository. tokers pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/apisix-ingress-controller.git
The following commit(s) were added to refs/heads/master by this push: new 2cc9c76 fix: add name field when create route and upstream (#333) 2cc9c76 is described below commit 2cc9c7618cac6094c00bf152649f2c5f98bfa9e7 Author: okaybase <75366457+okayb...@users.noreply.github.com> AuthorDate: Fri Apr 2 15:28:56 2021 +0800 fix: add name field when create route and upstream (#333) Co-authored-by: lixingwang <lixingw...@yiche.com> Co-authored-by: Alex Zhang <zchao1...@gmail.com> --- pkg/apisix/resource.go | 2 ++ pkg/apisix/route.go | 6 ++++++ pkg/apisix/upstream.go | 3 +++ test/e2e/ingress/resourcepushing.go | 42 +++++++++++++++++++++++++++++++++++++ test/e2e/scaffold/k8s.go | 5 +++++ 5 files changed, 58 insertions(+) diff --git a/pkg/apisix/resource.go b/pkg/apisix/resource.go index 7dadb3e..8808788 100644 --- a/pkg/apisix/resource.go +++ b/pkg/apisix/resource.go @@ -76,6 +76,7 @@ type routeItem struct { UpstreamId string `json:"upstream_id"` ServiceId string `json:"service_id"` Host string `json:"host"` + Hosts []string `json:"hosts"` URI string `json:"uri"` Vars [][]v1.StringOrSlice `json:"vars"` Uris []string `json:"uris"` @@ -115,6 +116,7 @@ func (i *item) route(clusterName string) (*v1.Route, error) { UpstreamId: route.UpstreamId, ServiceId: route.ServiceId, Plugins: route.Plugins, + Hosts: route.Hosts, Priority: route.Priority, }, nil } diff --git a/pkg/apisix/route.go b/pkg/apisix/route.go index 5d3ab20..551e1b7 100644 --- a/pkg/apisix/route.go +++ b/pkg/apisix/route.go @@ -30,11 +30,13 @@ import ( type routeReqBody struct { Desc string `json:"desc,omitempty"` + Name string `json:"name,omitempty"` URI string `json:"uri,omitempty"` Priority int `json:"priority,omitempty"` Uris []string `json:"uris,omitempty"` Vars [][]v1.StringOrSlice `json:"vars,omitempty"` Host string `json:"host,omitempty"` + Hosts []string `json:"hosts,omitempty"` ServiceId string `json:"service_id,omitempty"` UpstreamId string `json:"upstream_id,omitempty"` Plugins v1.Plugins `json:"plugins,omitempty"` @@ -162,8 +164,10 @@ func (r *routeClient) Create(ctx context.Context, obj *v1.Route) (*v1.Route, err data, err := json.Marshal(routeReqBody{ Priority: obj.Priority, Desc: obj.Name, + Name: obj.Name, URI: obj.Path, Host: obj.Host, + Hosts: obj.Hosts, ServiceId: obj.ServiceId, UpstreamId: obj.UpstreamId, Uris: obj.Uris, @@ -231,7 +235,9 @@ func (r *routeClient) Update(ctx context.Context, obj *v1.Route) (*v1.Route, err body, err := json.Marshal(routeReqBody{ Priority: obj.Priority, Desc: obj.Name, + Name: obj.Name, Host: obj.Host, + Hosts: obj.Hosts, URI: obj.Path, ServiceId: obj.ServiceId, Plugins: obj.Plugins, diff --git a/pkg/apisix/upstream.go b/pkg/apisix/upstream.go index bb1077a..826f725 100644 --- a/pkg/apisix/upstream.go +++ b/pkg/apisix/upstream.go @@ -67,6 +67,7 @@ type upstreamReqBody struct { Key string `json:"key,omitempty"` Nodes upstreamNodes `json:"nodes"` Desc string `json:"desc"` + Name string `json:"name"` Scheme string `json:"scheme,omitempty"` Retries int `json:"retries,omitempty"` Timeout *v1.UpstreamTimeout `json:"timeout,omitempty"` @@ -199,6 +200,7 @@ func (u *upstreamClient) Create(ctx context.Context, obj *v1.Upstream) (*v1.Upst Key: obj.Key, Nodes: nodes, Desc: obj.Name, + Name: obj.Name, Scheme: obj.Scheme, Checks: obj.Checks, Retries: obj.Retries, @@ -278,6 +280,7 @@ func (u *upstreamClient) Update(ctx context.Context, obj *v1.Upstream) (*v1.Upst Key: obj.Key, Nodes: nodes, Desc: obj.Name, + Name: obj.Name, }) if err != nil { return nil, err diff --git a/test/e2e/ingress/resourcepushing.go b/test/e2e/ingress/resourcepushing.go index 6e3bbe6..54f64de 100644 --- a/test/e2e/ingress/resourcepushing.go +++ b/test/e2e/ingress/resourcepushing.go @@ -333,4 +333,46 @@ spec: resp.Body().Contains("origin") resp.Header("X-Request-Id").NotEmpty() }) + + ginkgo.It("verify route items", func() { + backendSvc, backendSvcPort := s.DefaultHTTPBackend() + apisixRoute := fmt.Sprintf(` +apiVersion: apisix.apache.org/v2alpha1 +kind: ApisixRoute +metadata: + name: httpbin-route +spec: + http: + - name: rule1 + priority: 1 + match: + hosts: + - httpbin.com + paths: + - /ip + backend: + serviceName: %s + servicePort: %d +`, backendSvc, backendSvcPort[0]) + + assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute), "creating ApisixRoute") + assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1)) + assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1)) + + routes, err := s.ListApisixRoutes() + assert.Nil(ginkgo.GinkgoT(), err, "listing routes") + assert.Len(ginkgo.GinkgoT(), routes, 1) + name := s.Namespace() + "_" + "httpbin-route" + "_" + "rule1" + assert.Equal(ginkgo.GinkgoT(), routes[0].Name, name) + assert.Equal(ginkgo.GinkgoT(), routes[0].Uris, []string{"/ip"}) + assert.Equal(ginkgo.GinkgoT(), routes[0].Hosts, []string{"httpbin.com"}) + + resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect() + resp.Status(http.StatusOK) + resp.Body().Contains("origin") + + resp = s.NewAPISIXClient().GET("/ip").Expect() + resp.Status(http.StatusNotFound) + resp.Body().Contains("404 Route Not Found") + }) }) diff --git a/test/e2e/scaffold/k8s.go b/test/e2e/scaffold/k8s.go index a87a55f..37f8868 100644 --- a/test/e2e/scaffold/k8s.go +++ b/test/e2e/scaffold/k8s.go @@ -276,3 +276,8 @@ func (s *Scaffold) newAPISIXTunnels() error { s.addFinalizers(s.apisixHttpsTunnel.Close) return nil } + +// Namespace returns the current working namespace. +func (s *Scaffold) Namespace() string { + return s.kubectlOptions.Namespace +}