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/08/16 03:41:24 UTC

[GitHub] [apisix-ingress-controller] tao12345666333 commented on a diff in pull request #1222: fix: nodes convert failed

tao12345666333 commented on code in PR #1222:
URL: https://github.com/apache/apisix-ingress-controller/pull/1222#discussion_r946308536


##########
pkg/types/apisix/v1/types.go:
##########
@@ -216,21 +217,55 @@ type UpstreamNodes []UpstreamNode
 // and by default empty array will be encoded as '{}'.
 // We have to maintain the compatibility.
 func (n *UpstreamNodes) UnmarshalJSON(p []byte) error {
+	var data []UpstreamNode
 	if p[0] == '{' {
-		if len(p) != 2 {
-			return errors.New("unexpected non-empty object")
+		value := map[string]float64{}
+		if err := json.Unmarshal(p, &value); err != nil {
+			return err
+		}
+		for k, v := range value {
+			node, err := mapKV2Node(k, v)
+			if err != nil {
+				return err
+			}
+			data = append(data, *node)
 		}
-		*n = UpstreamNodes{}
+		*n = data
 		return nil
 	}
-	var data []UpstreamNode
 	if err := json.Unmarshal(p, &data); err != nil {
 		return err
 	}
 	*n = data
 	return nil
 }
 
+func mapKV2Node(key string, val float64) (*UpstreamNode, error) {
+	hp := strings.Split(key, ":")
+	host := hp[0]
+	//  according to APISIX upstream nodes policy, port is optional
+	port := "0"

Review Comment:
   ref: https://github.com/apache/apisix/blob/c4d5f2fca5b9ef98b551c769e2b1565185ed9630/apisix/schema_def.lua#L316-L341
   
   port is not optional.
   
   When APISIX is processing, there is a method to determine the port according to the protocol https://github.com/apache/apisix/blob/c4d5f2fca5b9ef98b551c769e2b1565185ed9630/apisix/upstream.lua#L167-L175
   
   So here I suggest setting it to 80, WDYT @bzp2010 



-- 
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