You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "AlinsRan (via GitHub)" <gi...@apache.org> on 2025/10/14 00:56:00 UTC

[PR] feat: support resolve svc.ports[].appProtocol [apisix-ingress-controller]

AlinsRan opened a new pull request, #2601:
URL: https://github.com/apache/apisix-ingress-controller/pull/2601

   <!-- Please answer these questions before submitting a pull request -->
   
   ### Type of change:
   
   <!-- Please delete options that are not relevant. -->
   
   <!-- Select all the options from below that matches the type your PR best -->
   
   - [ ] Bugfix
   - [ ] New feature provided
   - [ ] Improve performance
   - [ ] Backport patches
   - [ ] Documentation
   - [ ] Refactor
   - [ ] Chore
   - [ ] CI/CD or Tests
   
   ### What this PR does / why we need it:
   
   <!--- Why is this change required? What problem does it solve? -->
   <!--- If it fixes an open issue, please link to the issue here. -->
   
   ### Pre-submission checklist:
   
   <!--
   Please follow the requirements:
   1. Use Draft if the PR is not ready to be reviewed
   2. Test is required for the feat/fix PR, unless you have a good reason
   3. Doc is required for the feat PR
   4. Use a new commit to resolve review instead of `push -f`
   5. Use "request review" to notify the reviewer once you have resolved the review
   -->
   
   - [ ] Did you explain what problem does this PR solve? Or what new features have been added?
   - [ ] Have you added corresponding test cases?
   - [ ] Have you modified the corresponding document?
   - [ ] Is this PR backward compatible? **If it is not backward compatible, please discuss on the [mailing list](https://github.com/apache/apisix-ingress-controller#community) first**
   


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


Re: [PR] feat: support resolve svc.ports[].appProtocol [apisix-ingress-controller]

Posted by "bzp2010 (via GitHub)" <gi...@apache.org>.
bzp2010 commented on code in PR #2601:
URL: https://github.com/apache/apisix-ingress-controller/pull/2601#discussion_r2427839391


##########
test/e2e/framework/manifests/nginx.yaml:
##########
@@ -110,6 +110,7 @@ spec:
       port: 443
       protocol: TCP
       targetPort: 443
+      appProtocol: https

Review Comment:
   We'd better add a WSS test or modify it to WSS to verify whether the WebSocket "hint" is functioning properly.



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


Re: [PR] feat: support resolve svc.ports[].appProtocol [apisix-ingress-controller]

Posted by "ronething (via GitHub)" <gi...@apache.org>.
ronething commented on code in PR #2601:
URL: https://github.com/apache/apisix-ingress-controller/pull/2601#discussion_r2431692577


##########
internal/webhook/v1/gatewayproxy_webhook.go:
##########


Review Comment:
   Why are these changes occurring?



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


Re: [PR] feat: support resolve svc.ports[].appProtocol [apisix-ingress-controller]

Posted by "AlinsRan (via GitHub)" <gi...@apache.org>.
AlinsRan merged PR #2601:
URL: https://github.com/apache/apisix-ingress-controller/pull/2601


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


Re: [PR] feat: support resolve svc.ports[].appProtocol [apisix-ingress-controller]

Posted by "AlinsRan (via GitHub)" <gi...@apache.org>.
AlinsRan commented on code in PR #2601:
URL: https://github.com/apache/apisix-ingress-controller/pull/2601#discussion_r2431746691


##########
internal/webhook/v1/gatewayproxy_webhook.go:
##########


Review Comment:
   Perhaps there is a problem with the merger.
   



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


Re: [PR] feat: support resolve svc.ports[].appProtocol [apisix-ingress-controller]

Posted by "AlinsRan (via GitHub)" <gi...@apache.org>.
AlinsRan commented on code in PR #2601:
URL: https://github.com/apache/apisix-ingress-controller/pull/2601#discussion_r2431488116


##########
internal/adc/translator/apisixroute.go:
##########
@@ -352,50 +355,57 @@ func (t *Translator) translateApisixRouteHTTPBackend(tctx *provider.TranslateCon
 		upstream = u
 	}
 	var (
-		err   error
-		nodes adc.UpstreamNodes
+		err      error
+		nodes    adc.UpstreamNodes
+		protocol string
 	)
 	if backend.ResolveGranularity == apiv2.ResolveGranularityService {
-		nodes, err = t.translateApisixRouteBackendResolveGranularityService(tctx, auNN, backend)
+		nodes, protocol, err = t.translateApisixRouteBackendResolveGranularityService(tctx, auNN, backend)
 	} else {
-		nodes, err = t.translateApisixRouteBackendResolveGranularityEndpoint(tctx, auNN, backend)
+		nodes, protocol, err = t.translateApisixRouteBackendResolveGranularityEndpoint(tctx, auNN, backend)
 	}
 	if err != nil {
 		return nil, err
 	}
 	upstream.Nodes = nodes
+	if upstream.Scheme == "" {
+		upstream.Scheme = appProtocolToUpstreamScheme(protocol)
+	}
+	if protocol == internaltypes.AppProtocolWS || protocol == internaltypes.AppProtocolWSS {
+		*enableWebsocket = ptr.To(true)
+	}
 	if backend.Weight != nil {
 		upstream.Labels["meta_weight"] = strconv.FormatInt(int64(*backend.Weight), 10)
 	}
 	return upstream, nil
 }
 
-func (t *Translator) translateApisixRouteBackendResolveGranularityService(tctx *provider.TranslateContext, arNN types.NamespacedName, backend apiv2.ApisixRouteHTTPBackend) (adc.UpstreamNodes, error) {
+func (t *Translator) translateApisixRouteBackendResolveGranularityService(tctx *provider.TranslateContext, arNN types.NamespacedName, backend apiv2.ApisixRouteHTTPBackend) (adc.UpstreamNodes, string, error) {

Review Comment:
   fixed.



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


Re: [PR] feat: support resolve svc.ports[].appProtocol [apisix-ingress-controller]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2601:
URL: https://github.com/apache/apisix-ingress-controller/pull/2601#discussion_r2427652713


##########
internal/adc/translator/apisixroute.go:
##########
@@ -352,50 +355,55 @@ func (t *Translator) translateApisixRouteHTTPBackend(tctx *provider.TranslateCon
 		upstream = u
 	}
 	var (
-		err   error
-		nodes adc.UpstreamNodes
+		err      error
+		nodes    adc.UpstreamNodes
+		protocol string
 	)
 	if backend.ResolveGranularity == apiv2.ResolveGranularityService {
-		nodes, err = t.translateApisixRouteBackendResolveGranularityService(tctx, auNN, backend)
+		nodes, protocol, err = t.translateApisixRouteBackendResolveGranularityService(tctx, auNN, backend)
 	} else {
-		nodes, err = t.translateApisixRouteBackendResolveGranularityEndpoint(tctx, auNN, backend)
+		nodes, protocol, err = t.translateApisixRouteBackendResolveGranularityEndpoint(tctx, auNN, backend)
 	}
 	if err != nil {
 		return nil, err
 	}
 	upstream.Nodes = nodes
+	upstream.Scheme = appProtocolToUpstreamScheme(protocol)
+	if protocol == "kubernetes.io/ws" || protocol == "kubernetes.io/wss" {
+		*enableWebsocket = ptr.To(true)

Review Comment:
   Potential nil pointer dereference. `enableWebsocket` could be nil when dereferencing. Should check `enableWebsocket != nil` before assignment.
   ```suggestion
   		if enableWebsocket != nil {
   			*enableWebsocket = ptr.To(true)
   		}
   ```



##########
internal/adc/translator/httproute.go:
##########
@@ -825,3 +833,16 @@ func (t *Translator) translateHTTPRouteHeaderMatchToVars(header gatewayv1.HTTPHe
 	}
 	return HeaderMatchToVars(matchType, string(header.Name), header.Value)
 }
+
+func appProtocolToUpstreamScheme(appProtocol string) string {
+	switch appProtocol {
+	case "http":
+		return apiv2.SchemeHTTP
+	case "https":
+		return apiv2.SchemeHTTPS
+	case "kubernetes.io/wss":
+		return apiv2.SchemeHTTPS
+	default:
+		return ""
+	}
+}

Review Comment:
   The function only handles `kubernetes.io/wss` but not `kubernetes.io/ws`. Based on the websocket detection logic elsewhere, `kubernetes.io/ws` should likely return `apiv2.SchemeHTTP`.



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


Re: [PR] feat: support resolve svc.ports[].appProtocol [apisix-ingress-controller]

Posted by "AlinsRan (via GitHub)" <gi...@apache.org>.
AlinsRan commented on code in PR #2601:
URL: https://github.com/apache/apisix-ingress-controller/pull/2601#discussion_r2431746691


##########
internal/webhook/v1/gatewayproxy_webhook.go:
##########


Review Comment:
   Merge master introduced, maybe I did something wrong.



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


Re: [PR] feat: support resolve svc.ports[].appProtocol [apisix-ingress-controller]

Posted by "AlinsRan (via GitHub)" <gi...@apache.org>.
AlinsRan commented on code in PR #2601:
URL: https://github.com/apache/apisix-ingress-controller/pull/2601#discussion_r2434475130


##########
internal/adc/translator/ingress.go:
##########


Review Comment:
   I don't want to either.  😫
   The logical complexity is too high, Lint check failed.



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


Re: [PR] feat: support resolve svc.ports[].appProtocol [apisix-ingress-controller]

Posted by "ronething (via GitHub)" <gi...@apache.org>.
ronething commented on code in PR #2601:
URL: https://github.com/apache/apisix-ingress-controller/pull/2601#discussion_r2430903509


##########
internal/adc/translator/apisixroute.go:
##########
@@ -352,50 +355,57 @@ func (t *Translator) translateApisixRouteHTTPBackend(tctx *provider.TranslateCon
 		upstream = u
 	}
 	var (
-		err   error
-		nodes adc.UpstreamNodes
+		err      error
+		nodes    adc.UpstreamNodes
+		protocol string
 	)
 	if backend.ResolveGranularity == apiv2.ResolveGranularityService {
-		nodes, err = t.translateApisixRouteBackendResolveGranularityService(tctx, auNN, backend)
+		nodes, protocol, err = t.translateApisixRouteBackendResolveGranularityService(tctx, auNN, backend)
 	} else {
-		nodes, err = t.translateApisixRouteBackendResolveGranularityEndpoint(tctx, auNN, backend)
+		nodes, protocol, err = t.translateApisixRouteBackendResolveGranularityEndpoint(tctx, auNN, backend)
 	}
 	if err != nil {
 		return nil, err
 	}
 	upstream.Nodes = nodes
+	if upstream.Scheme == "" {
+		upstream.Scheme = appProtocolToUpstreamScheme(protocol)
+	}
+	if protocol == internaltypes.AppProtocolWS || protocol == internaltypes.AppProtocolWSS {
+		*enableWebsocket = ptr.To(true)
+	}
 	if backend.Weight != nil {
 		upstream.Labels["meta_weight"] = strconv.FormatInt(int64(*backend.Weight), 10)
 	}
 	return upstream, nil
 }
 
-func (t *Translator) translateApisixRouteBackendResolveGranularityService(tctx *provider.TranslateContext, arNN types.NamespacedName, backend apiv2.ApisixRouteHTTPBackend) (adc.UpstreamNodes, error) {
+func (t *Translator) translateApisixRouteBackendResolveGranularityService(tctx *provider.TranslateContext, arNN types.NamespacedName, backend apiv2.ApisixRouteHTTPBackend) (adc.UpstreamNodes, string, error) {

Review Comment:
   It seems that this function does not actually process the `protocol` and always returns an empty string?



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


Re: [PR] feat: support resolve svc.ports[].appProtocol [apisix-ingress-controller]

Posted by "bzp2010 (via GitHub)" <gi...@apache.org>.
bzp2010 commented on code in PR #2601:
URL: https://github.com/apache/apisix-ingress-controller/pull/2601#discussion_r2434448160


##########
internal/adc/translator/ingress.go:
##########


Review Comment:
   This seems to have refactored a lot. Is it necessary to include it in this PR?



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


Re: [PR] feat: support resolve svc.ports[].appProtocol [apisix-ingress-controller]

Posted by "AlinsRan (via GitHub)" <gi...@apache.org>.
AlinsRan commented on code in PR #2601:
URL: https://github.com/apache/apisix-ingress-controller/pull/2601#discussion_r2434475130


##########
internal/adc/translator/ingress.go:
##########


Review Comment:
   https://github.com/apache/apisix-ingress-controller/actions/runs/18489910583/job/52680915589#step:5:11
   
   The high complexity of the code logic caused Lint's check to fail. 😫



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


Re: [PR] feat: support resolve svc.ports[].appProtocol [apisix-ingress-controller]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2601:
URL: https://github.com/apache/apisix-ingress-controller/pull/2601#discussion_r2427646438


##########
internal/adc/translator/httproute.go:
##########
@@ -825,3 +833,16 @@ func (t *Translator) translateHTTPRouteHeaderMatchToVars(header gatewayv1.HTTPHe
 	}
 	return HeaderMatchToVars(matchType, string(header.Name), header.Value)
 }
+
+func appProtocolToUpstreamScheme(appProtocol string) string {
+	switch appProtocol {
+	case "http":
+		return apiv2.SchemeHTTP
+	case "https":
+		return apiv2.SchemeHTTPS
+	case "kubenetes.io/wss":

Review Comment:
   Corrected spelling of 'kubenetes.io/wss' to 'kubernetes.io/wss'.
   ```suggestion
   	case "kubernetes.io/wss":
   ```



##########
internal/adc/translator/apisixroute.go:
##########
@@ -179,13 +179,16 @@ func (t *Translator) addAuthenticationPlugins(rule apiv2.ApisixRouteHTTP, plugin
 	}
 }
 
-func (t *Translator) buildRoute(ar *apiv2.ApisixRoute, service *adc.Service, rule apiv2.ApisixRouteHTTP, plugins adc.Plugins, timeout *adc.Timeout, vars adc.Vars) {
+func (t *Translator) buildRoute(ar *apiv2.ApisixRoute, service *adc.Service, rule apiv2.ApisixRouteHTTP, plugins adc.Plugins, timeout *adc.Timeout, vars adc.Vars, enableWebsocket **bool) {
 	route := adc.NewDefaultRoute()
 	route.Name = adc.ComposeRouteName(ar.Namespace, ar.Name, rule.Name)
 	route.ID = id.GenID(route.Name)
 	route.Desc = "Created by apisix-ingress-controller, DO NOT modify it manually"
 	route.Labels = label.GenLabel(ar)
-	route.EnableWebsocket = ptr.To(rule.Websocket)
+	route.EnableWebsocket = rule.Websocket
+	if route.EnableWebsocket == nil && *enableWebsocket != nil {

Review Comment:
   Potential nil pointer dereference. The condition should check if `enableWebsocket != nil` before dereferencing it with `*enableWebsocket != nil`.
   ```suggestion
   	if route.EnableWebsocket == nil && enableWebsocket != nil && *enableWebsocket != nil {
   ```



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


Re: [PR] feat: support resolve svc.ports[].appProtocol [apisix-ingress-controller]

Posted by "AlinsRan (via GitHub)" <gi...@apache.org>.
AlinsRan commented on code in PR #2601:
URL: https://github.com/apache/apisix-ingress-controller/pull/2601#discussion_r2431746691


##########
internal/webhook/v1/gatewayproxy_webhook.go:
##########


Review Comment:
   It may be a rebase or merge error.



##########
internal/webhook/v1/gatewayproxy_webhook.go:
##########


Review Comment:
   fixed.



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


Re: [PR] feat: support resolve svc.ports[].appProtocol [apisix-ingress-controller]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2601:
URL: https://github.com/apache/apisix-ingress-controller/pull/2601#discussion_r2428595659


##########
test/e2e/gatewayapi/httproute.go:
##########
@@ -2439,4 +2442,104 @@ spec:
 		})
 
 	})
+
+	Context("Test Service With AppProtocol", func() {
+		var (
+			httproute = `
+apiVersion: gateway.networking.k8s.io/v1
+kind: HTTPRoute
+metadata:
+  name: nginx
+spec:
+  parentRefs:
+  - name: %s
+  hostnames:
+  - api6.com
+  rules:
+  - matches:
+    - path:
+        type: Exact
+        value: /get
+    backendRefs:
+    - name: nginx
+      port: 443
+ `
+			httprouteWithWSS = `
+apiVersion: gateway.networking.k8s.io/v1
+kind: HTTPRoute
+metadata:
+  name: nginx-wss
+spec:
+  parentRefs:
+  - name: %s
+  hostnames:
+  - api6.com
+  rules:
+  - matches:
+    - path:
+        type: Exact
+        value: /ws
+    backendRefs:
+    - name: nginx
+      port: 8443
+ `
+		)
+
+		BeforeEach(func() {
+			beforeEachHTTPS()
+			s.DeployNginx(framework.NginxOptions{
+				Namespace: s.Namespace(),
+				Replicas:  ptr.To(int32(1)),
+			})
+		})
+		It("HTTPS backend", func() {
+			s.ResourceApplied("HTTPRoute", "nginx", fmt.Sprintf(httproute, s.Namespace()), 1)
+			s.RequestAssert(&scaffold.RequestAssert{
+				Method: "GET",
+				Path:   "/get",
+				Host:   "api6.com",
+				Check:  scaffold.WithExpectedStatus(http.StatusOK),
+			})
+		})
+
+		It("WWS backend", func() {

Review Comment:
   Corrected spelling of 'WWS' to 'WSS' in test description.
   ```suggestion
   		It("WSS backend", func() {
   ```



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


Re: [PR] feat: support resolve svc.ports[].appProtocol [apisix-ingress-controller]

Posted by "AlinsRan (via GitHub)" <gi...@apache.org>.
AlinsRan commented on code in PR #2601:
URL: https://github.com/apache/apisix-ingress-controller/pull/2601#discussion_r2428202427


##########
test/e2e/framework/manifests/nginx.yaml:
##########
@@ -110,6 +110,7 @@ spec:
       port: 443
       protocol: TCP
       targetPort: 443
+      appProtocol: https

Review Comment:
   added.



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