You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/04/12 01:32:17 UTC

[GitHub] [apisix-dashboard] starsz commented on a diff in pull request #2421: fix: create upstream error when pass host is node and nodes without port

starsz commented on code in PR #2421:
URL: https://github.com/apache/apisix-dashboard/pull/2421#discussion_r847862261


##########
api/test/e2enew/upstream/upstream_test.go:
##########
@@ -88,6 +88,24 @@ var _ = ginkgo.Describe("Upstream", func() {
 			ExpectStatus: http.StatusOK,
 		})
 	})
+	ginkgo.It("create upstream3 success when pass host is 'node' and nodes without port", func() {
+		createUpstreamBody := make(map[string]interface{})
+		createUpstreamBody["name"] = "upstream3"
+		createUpstreamBody["nodes"] = map[string]float64{base.UpstreamIp: 100}
+		createUpstreamBody["type"] = "roundrobin"
+		createUpstreamBody["pass_host"] = "node"
+
+		_createUpstreamBody, err := json.Marshal(createUpstreamBody)
+		gomega.Expect(err).To(gomega.BeNil())
+		base.RunTestCase(base.HttpTestCase{
+			Object:       base.ManagerApiExpect(),
+			Method:       http.MethodPut,
+			Path:         "/apisix/admin/upstreams/3",
+			Body:         string(_createUpstreamBody),
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusOK,
+		})
+	})

Review Comment:
   Can you add test to check the upstream is work ?



##########
api/internal/core/entity/format.go:
##########
@@ -17,17 +17,23 @@
 package entity
 
 import (
-	"net"
+	"errors"
 	"strconv"
+	"strings"
 
 	"github.com/apisix/manager-api/internal/log"
 )
 
 func mapKV2Node(key string, val float64) (*Node, error) {
-	host, port, err := net.SplitHostPort(key)
-	if err != nil {
-		log.Errorf("split host port fail: %s", err)
-		return nil, err
+	hp := strings.Split(key, ":")
+	host := hp[0]
+	//  according to APISIX upstream nodes policy, port is optional
+	port := "0"
+
+	if len(hp) > 2 {
+		return nil, errors.New("address typo error")

Review Comment:
   ```suggestion
   		return nil, errors.New("invalid upstream node")
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org