-
Notifications
You must be signed in to change notification settings - Fork 365
fix: support tlsSecret from http.backends in ApisixRoute #2518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Revolyssup
merged 8 commits into
apache:master
from
Revolyssup:revolyssup/revolyssup-2496
Aug 21, 2025
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5a00522
fix: support tlsSecret and externalNodes from http.backends in Apisix…
Revolyssup 9ab6b64
fix log
Revolyssup 293356a
remove redundant logs
Revolyssup 8fb5828
fix lint
Revolyssup 8f5f2bf
fix lint
Revolyssup c44c420
apply suggestions
Revolyssup 4a3f04c
fix test
Revolyssup f593713
apply suggestions
Revolyssup File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ import ( | |
| "net" | ||
| "net/http" | ||
| "net/url" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/gorilla/websocket" | ||
|
|
@@ -1368,4 +1369,184 @@ spec: | |
| }) | ||
| }) | ||
| }) | ||
| Context("Test tls secret processed from ApisixUpstream with matching backend", func() { | ||
| var Cert = strings.TrimSpace(framework.TestServerCert) | ||
| var Key = strings.TrimSpace(framework.TestServerKey) | ||
| createSecret := func(s *scaffold.Scaffold, secretName string) { | ||
| err := s.NewKubeTlsSecret(secretName, Cert, Key) | ||
| assert.Nil(GinkgoT(), err, "create secret error") | ||
| } | ||
| const apisixRouteSpec = ` | ||
| apiVersion: apisix.apache.org/v2 | ||
| kind: ApisixRoute | ||
| metadata: | ||
| name: default | ||
| namespace: %s | ||
| spec: | ||
| ingressClassName: %s | ||
| http: | ||
| - name: rule0 | ||
| match: | ||
| hosts: | ||
| - httpbin | ||
| paths: | ||
| - /* | ||
| backends: | ||
| - serviceName: httpbin-service-e2e-test | ||
| servicePort: 80 | ||
|
|
||
| ` | ||
| const apisixUpstreamSpec = ` | ||
| apiVersion: apisix.apache.org/v2 | ||
| kind: ApisixUpstream | ||
| metadata: | ||
| name: httpbin-service-e2e-test | ||
| namespace: %s | ||
| spec: | ||
| tlsSecret: | ||
| name: %s | ||
| namespace: %s | ||
| ` | ||
|
|
||
| It("create ApisixRoute and upstream with tlsSecret", func() { | ||
| secretName := fmt.Sprintf("test-tls-secret-%s", s.Namespace()) | ||
| createSecret(s, secretName) | ||
| By("apply apisixupstream") | ||
| applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin-service-e2e-test"}, | ||
| new(apiv2.ApisixUpstream), fmt.Sprintf(apisixUpstreamSpec, s.Namespace(), secretName, s.Namespace())) | ||
| By("apply apisixroute") | ||
| applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, | ||
| new(apiv2.ApisixRoute), fmt.Sprintf(apisixRouteSpec, s.Namespace(), s.Namespace())) | ||
| time.Sleep(6 * time.Second) | ||
| services, err := s.DefaultDataplaneResource().Service().List(context.Background()) | ||
| Expect(err).ShouldNot(HaveOccurred(), "list services") | ||
| service := services[0] | ||
| Expect(service.Upstream.TLS).ShouldNot(BeNil(), "check tls in service") | ||
| }) | ||
| }) | ||
|
|
||
| Context("Test tls secret processed from ApisixUpstream with matching upstream", func() { | ||
| var Cert = strings.TrimSpace(framework.TestServerCert) | ||
| var Key = strings.TrimSpace(framework.TestServerKey) | ||
| createSecret := func(s *scaffold.Scaffold, secretName string) { | ||
| err := s.NewKubeTlsSecret(secretName, Cert, Key) | ||
| assert.Nil(GinkgoT(), err, "create secret error") | ||
| } | ||
| const apisixRouteSpec = ` | ||
| apiVersion: apisix.apache.org/v2 | ||
| kind: ApisixRoute | ||
| metadata: | ||
| name: default | ||
| namespace: %s | ||
| spec: | ||
| ingressClassName: %s | ||
| http: | ||
| - name: rule0 | ||
| match: | ||
| hosts: | ||
| - httpbin | ||
| paths: | ||
| - /* | ||
| upstreams: | ||
| - name: httpbin-service-e2e-test | ||
| ` | ||
| const apisixUpstreamSpec = ` | ||
| apiVersion: apisix.apache.org/v2 | ||
| kind: ApisixUpstream | ||
| metadata: | ||
| name: httpbin-service-e2e-test | ||
| namespace: %s | ||
| spec: | ||
| tlsSecret: | ||
| name: %s | ||
| namespace: %s | ||
| ` | ||
|
|
||
| It("create ApisixRoute and upstream with tlsSecret", func() { | ||
| secretName := fmt.Sprintf("test-tls-secret-%s", s.Namespace()) | ||
| createSecret(s, secretName) | ||
| By("apply apisixupstream") | ||
| applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin-service-e2e-test"}, | ||
| new(apiv2.ApisixUpstream), fmt.Sprintf(apisixUpstreamSpec, s.Namespace(), secretName, s.Namespace())) | ||
| By("apply apisixroute") | ||
| applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, | ||
| new(apiv2.ApisixRoute), fmt.Sprintf(apisixRouteSpec, s.Namespace(), s.Namespace())) | ||
| time.Sleep(6 * time.Second) | ||
| services, err := s.DefaultDataplaneResource().Service().List(context.Background()) | ||
| Expect(err).ShouldNot(HaveOccurred(), "list services") | ||
| service := services[0] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Directly accessing |
||
| Expect(service.Upstream.TLS).ShouldNot(BeNil(), "check tls in service") | ||
| }) | ||
| }) | ||
|
|
||
| Context("Test external nodes processed from ApisixUpstream with matching backend", func() { | ||
| It("Test reference ApisixUpstream", func() { | ||
| const apisixRouteSpec = ` | ||
| apiVersion: apisix.apache.org/v2 | ||
| kind: ApisixRoute | ||
| metadata: | ||
| name: default | ||
| namespace: %s | ||
| spec: | ||
| ingressClassName: %s | ||
| http: | ||
| - name: rule0 | ||
| match: | ||
| paths: | ||
| - /* | ||
| backends: | ||
| - serviceName: httpbin-service-e2e-test | ||
| servicePort: 80 | ||
| ` | ||
| const apisixUpstreamSpec0 = ` | ||
| apiVersion: apisix.apache.org/v2 | ||
| kind: ApisixUpstream | ||
| metadata: | ||
| name: default-upstream | ||
| namespace: %s | ||
| spec: | ||
| ingressClassName: %s | ||
| externalNodes: | ||
| - type: Service | ||
| name: httpbin-service-e2e-test | ||
| ` | ||
| const apisixUpstreamSpec1 = ` | ||
| apiVersion: apisix.apache.org/v2 | ||
| kind: ApisixUpstream | ||
| metadata: | ||
| name: default-upstream | ||
| namespace: %s | ||
| spec: | ||
| ingressClassName: %s | ||
| externalNodes: | ||
| - type: Service | ||
| name: alias-httpbin-service-e2e-test | ||
| ` | ||
| const serviceSpec = ` | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: alias-httpbin-service-e2e-test | ||
| spec: | ||
| type: ExternalName | ||
| externalName: httpbin-service-e2e-test | ||
| ` | ||
| By("create Service, ApisixUpstream and ApisixRoute") | ||
| err := s.CreateResourceFromStringWithNamespace(serviceSpec, s.Namespace()) | ||
| Expect(err).ShouldNot(HaveOccurred(), "apply service") | ||
| applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default-upstream"}, | ||
| new(apiv2.ApisixUpstream), fmt.Sprintf(apisixUpstreamSpec0, s.Namespace(), s.Namespace())) | ||
|
|
||
| applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, | ||
| new(apiv2.ApisixRoute), fmt.Sprintf(apisixRouteSpec, s.Namespace(), s.Namespace())) | ||
|
|
||
| request := func(path string) int { | ||
| return s.NewAPISIXClient().GET(path).WithHost("httpbin").Expect().Raw().StatusCode | ||
| } | ||
| By("verify that ApisixUpstream reference a Service which is ExternalName should request OK") | ||
| applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default-upstream"}, | ||
| new(apiv2.ApisixUpstream), fmt.Sprintf(apisixUpstreamSpec1, s.Namespace(), s.Namespace())) | ||
| Eventually(request).WithArguments("/get").WithTimeout(30 * time.Second).ProbeEvery(1 * time.Second).Should(Equal(http.StatusOK)) | ||
| }) | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The backend uses Kubernetes services for service discovery, which should not allow custom endpoints. I don't think this needs to be handled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed