From 824382b78423cf25609fa7a70c6ee1981b5ac7a4 Mon Sep 17 00:00:00 2001 From: ashing Date: Fri, 6 Jun 2025 15:07:55 +0800 Subject: [PATCH 1/7] chore: remove apisixCli Signed-off-by: ashing --- test/e2e/scaffold/api7_deployer.go | 31 ------------------------------ test/e2e/scaffold/scaffold.go | 13 +------------ 2 files changed, 1 insertion(+), 43 deletions(-) diff --git a/test/e2e/scaffold/api7_deployer.go b/test/e2e/scaffold/api7_deployer.go index b50458192..69c52d6cd 100644 --- a/test/e2e/scaffold/api7_deployer.go +++ b/test/e2e/scaffold/api7_deployer.go @@ -13,7 +13,6 @@ package scaffold import ( - "context" "fmt" "os" "time" @@ -24,7 +23,6 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/apache/apisix-ingress-controller/pkg/dashboard" "github.com/apache/apisix-ingress-controller/pkg/utils" "github.com/apache/apisix-ingress-controller/test/e2e/framework" ) @@ -90,7 +88,6 @@ func (s *API7Deployer) BeforeEach() { e.Add(func() { s.DeployDataplane() s.DeployIngress() - s.initDataPlaneClient() }) e.Add(s.DeployTestService) e.Wait() @@ -181,34 +178,6 @@ func (s *API7Deployer) ScaleIngress(replicas int) { }) } -func (s *API7Deployer) initDataPlaneClient() { - var err error - s.apisixCli, err = dashboard.NewClient() - Expect(err).NotTo(HaveOccurred(), "creating apisix client") - - adminURL := fmt.Sprintf("http://%s/apisix/admin", s.GetDashboardEndpoint()) - - s.Logf("apisix admin: %s", adminURL) - - err = s.apisixCli.AddCluster(context.Background(), &dashboard.ClusterOptions{ - Name: "default", - ControllerName: s.opts.ControllerName, - Labels: map[string]string{"k8s/controller-name": s.opts.ControllerName}, - BaseURL: adminURL, - AdminKey: s.AdminKey(), - }) - Expect(err).NotTo(HaveOccurred(), "adding cluster") - - httpsURL := fmt.Sprintf("https://%s/apisix/admin", s.GetDashboardEndpointHTTPS()) - err = s.apisixCli.AddCluster(context.Background(), &dashboard.ClusterOptions{ - Name: "default-https", - BaseURL: httpsURL, - AdminKey: s.AdminKey(), - SkipTLSVerify: true, - }) - Expect(err).NotTo(HaveOccurred(), "adding cluster") -} - // CreateAdditionalGateway creates a new gateway group and deploys a dataplane for it. // It returns the gateway group ID and namespace name where the dataplane is deployed. func (s *API7Deployer) CreateAdditionalGateway(namePrefix string) (string, string, error) { diff --git a/test/e2e/scaffold/scaffold.go b/test/e2e/scaffold/scaffold.go index 3779b3ed2..d319bb04b 100644 --- a/test/e2e/scaffold/scaffold.go +++ b/test/e2e/scaffold/scaffold.go @@ -66,9 +66,6 @@ type Scaffold struct { additionalGateways map[string]*GatewayResources - // TODO: move to deployer - apisixCli dashboard.Dashboard - Deployer Deployer } @@ -192,15 +189,7 @@ func (s *Scaffold) NewAPISIXHttpsClient(host string) *httpexpect.Expect { } func (s *Scaffold) DefaultDataplaneResource() dashboard.Cluster { - return s.apisixCli.Cluster("default") -} - -func (s *Scaffold) DefaultDataplaneResourceHTTPS() dashboard.Cluster { - return s.apisixCli.Cluster("default-https") -} - -func (s *Scaffold) DataPlaneClient() dashboard.Dashboard { - return s.apisixCli + return nil } func (s *Scaffold) DeployTestService() { From 094a551db6971f2b85eb19e4cf36195ea39e094a Mon Sep 17 00:00:00 2001 From: ashing Date: Fri, 6 Jun 2025 17:23:49 +0800 Subject: [PATCH 2/7] chore: add adc dump Signed-off-by: ashing --- .../manifests/apisix-standalone.yaml | 21 +- test/e2e/gatewayapi/controller.go | 4 +- test/e2e/gatewayapi/gateway.go | 13 +- test/e2e/ingress/ingress.go | 3 +- test/e2e/scaffold/adc.go | 189 ++++++++++++++++++ test/e2e/scaffold/api7_deployer.go | 9 + test/e2e/scaffold/apisix_deployer.go | 22 +- test/e2e/scaffold/deployer.go | 5 +- test/e2e/scaffold/scaffold.go | 5 +- 9 files changed, 244 insertions(+), 27 deletions(-) create mode 100644 test/e2e/scaffold/adc.go diff --git a/test/e2e/framework/manifests/apisix-standalone.yaml b/test/e2e/framework/manifests/apisix-standalone.yaml index 299c619e0..912aa8325 100644 --- a/test/e2e/framework/manifests/apisix-standalone.yaml +++ b/test/e2e/framework/manifests/apisix-standalone.yaml @@ -4,21 +4,20 @@ metadata: name: apisix-conf data: config.yaml: | - apisix: - enable_admin: true - admin_key: - - name: admin - key: {{ .AdminKey }} - role: admin - ssl: - enabled: true - nginx_config: - worker_processes: 2 - error_log_level: info deployment: role: traditional role_traditional: config_provider: yaml + admin: + allow_admin: + - 0.0.0.0/0 + admin_key: + - key: {{ .AdminKey }} + name: admin + role: admin + nginx_config: + worker_processes: 2 + error_log_level: info --- apiVersion: apps/v1 kind: Deployment diff --git a/test/e2e/gatewayapi/controller.go b/test/e2e/gatewayapi/controller.go index 1412d5191..4831fddc3 100644 --- a/test/e2e/gatewayapi/controller.go +++ b/test/e2e/gatewayapi/controller.go @@ -14,6 +14,7 @@ package gatewayapi import ( "fmt" + "log" "time" . "github.com/onsi/ginkgo/v2" @@ -166,9 +167,10 @@ spec: BeforeEach(func() { beforeEach(s1, "gateway1") }) - It("Apply resource ", func() { + FIt("Apply resource ", func() { ResourceApplied(s1, "HTTPRoute", "httpbin", "gateway1", route1, 1) routes, err := s1.DefaultDataplaneResource().Route().List(s1.Context) + log.Println("routes", routes) Expect(err).NotTo(HaveOccurred()) Expect(routes).To(HaveLen(1)) assert.Equal(GinkgoT(), routes[0].Labels["k8s/controller-name"], "apisix.apache.org/apisix-ingress-controller-1") diff --git a/test/e2e/gatewayapi/gateway.go b/test/e2e/gatewayapi/gateway.go index dc3f7b46b..5f6ee0499 100644 --- a/test/e2e/gatewayapi/gateway.go +++ b/test/e2e/gatewayapi/gateway.go @@ -15,6 +15,7 @@ package gatewayapi import ( "context" "fmt" + "log" "strings" "time" @@ -204,7 +205,9 @@ spec: tls, err := s.DefaultDataplaneResource().SSL().List(context.Background()) assert.Nil(GinkgoT(), err, "list tls error") assert.Len(GinkgoT(), tls, 1, "tls number not expect") - assert.Equal(GinkgoT(), Cert, tls[0].Cert, "tls cert not expect") + log.Println("tls", tls) + assert.Len(GinkgoT(), tls[0].Certificates, 1, "length of certificates not expect") + assert.Equal(GinkgoT(), Cert, tls[0].Certificates[0].Certificate, "tls cert not expect") assert.ElementsMatch(GinkgoT(), []string{host, "*.api6.com"}, tls[0].Snis) }) @@ -277,7 +280,8 @@ spec: tls, err := s.DefaultDataplaneResource().SSL().List(context.Background()) assert.Nil(GinkgoT(), err, "list tls error") assert.Len(GinkgoT(), tls, 1, "tls number not expect") - assert.Equal(GinkgoT(), Cert, tls[0].Cert, "tls cert not expect") + assert.Len(GinkgoT(), tls[0].Certificates, 1, "length of certificates not expect") + assert.Equal(GinkgoT(), Cert, tls[0].Certificates[0].Certificate, "tls cert not expect") assert.Equal(GinkgoT(), tls[0].Labels["k8s/controller-name"], "apisix.apache.org/apisix-ingress-controller") By("update secret") @@ -289,7 +293,10 @@ spec: if len(tls) < 1 { return "" } - return tls[0].Cert + if len(tls[0].Certificates) < 1 { + return "" + } + return tls[0].Certificates[0].Certificate }).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(framework.TestCert)) }) }) diff --git a/test/e2e/ingress/ingress.go b/test/e2e/ingress/ingress.go index a53d3fa26..93b0f6237 100644 --- a/test/e2e/ingress/ingress.go +++ b/test/e2e/ingress/ingress.go @@ -131,7 +131,8 @@ spec: tls, err := s.DefaultDataplaneResource().SSL().List(context.Background()) assert.Nil(GinkgoT(), err, "list tls error") assert.Len(GinkgoT(), tls, 1, "tls number not expect") - assert.Equal(GinkgoT(), Cert, tls[0].Cert, "tls cert not expect") + assert.Len(GinkgoT(), tls[0].Certificates, 1, "length of certificates not expect") + assert.Equal(GinkgoT(), Cert, tls[0].Certificates[0].Certificate, "tls cert not expect") assert.ElementsMatch(GinkgoT(), []string{host}, tls[0].Snis) }) }) diff --git a/test/e2e/scaffold/adc.go b/test/e2e/scaffold/adc.go new file mode 100644 index 000000000..12a984143 --- /dev/null +++ b/test/e2e/scaffold/adc.go @@ -0,0 +1,189 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package scaffold + +import ( + "bytes" + "context" + "encoding/json" + "os" + "os/exec" + "time" + + adctypes "github.com/apache/apisix-ingress-controller/api/adc" + "github.com/apache/apisix-ingress-controller/internal/provider/adc/translator" +) + +// DataplaneResource defines the interface for accessing dataplane resources +type DataplaneResource interface { + Route() RouteResource + Service() ServiceResource + SSL() SSLResource + Consumer() ConsumerResource +} + +// RouteResource defines the interface for route resources +type RouteResource interface { + List(ctx context.Context) ([]*adctypes.Route, error) +} + +// ServiceResource defines the interface for service resources +type ServiceResource interface { + List(ctx context.Context) ([]*adctypes.Service, error) +} + +// SSLResource defines the interface for SSL resources +type SSLResource interface { + List(ctx context.Context) ([]*adctypes.SSL, error) +} + +// ConsumerResource defines the interface for consumer resources +type ConsumerResource interface { + List(ctx context.Context) ([]*adctypes.Consumer, error) +} + +// adcDataplaneResource implements DataplaneResource using ADC command +type adcDataplaneResource struct { + backend string + serverAddr string + token string + tlsVerify bool + syncTimeout time.Duration +} + +// newADCDataplaneResource creates a new ADC-based dataplane resource +func newADCDataplaneResource(backend, serverAddr, token string, tlsVerify bool) DataplaneResource { + return &adcDataplaneResource{ + backend: backend, + serverAddr: serverAddr, + token: token, + tlsVerify: tlsVerify, + syncTimeout: 30 * time.Second, + } +} + +func (a *adcDataplaneResource) Route() RouteResource { + return &adcRouteResource{a} +} + +func (a *adcDataplaneResource) Service() ServiceResource { + return &adcServiceResource{a} +} + +func (a *adcDataplaneResource) SSL() SSLResource { + return &adcSSLResource{a} +} + +func (a *adcDataplaneResource) Consumer() ConsumerResource { + return &adcConsumerResource{a} +} + +// dumpResources executes adc dump command and returns the resources +func (a *adcDataplaneResource) dumpResources(ctx context.Context) (*translator.TranslateResult, error) { + ctxWithTimeout, cancel := context.WithTimeout(ctx, a.syncTimeout) + defer cancel() + + args := []string{"dump", "-o", "/tmp/dump.yaml"} + if !a.tlsVerify { + args = append(args, "--tls-skip-verify") + } + + adcEnv := []string{ + "ADC_BACKEND=" + a.backend, + "ADC_SERVER=" + a.serverAddr, + "ADC_TOKEN=" + a.token, + } + + var stdout, stderr bytes.Buffer + cmd := exec.CommandContext(ctxWithTimeout, "adc", args...) + cmd.Stdout = &stdout + cmd.Stderr = &stderr + cmd.Env = append(cmd.Env, os.Environ()...) + cmd.Env = append(cmd.Env, adcEnv...) + + if err := cmd.Run(); err != nil { + return nil, err + } + + var resources adctypes.Resources + if err := json.Unmarshal(stdout.Bytes(), &resources); err != nil { + return nil, err + } + + // Extract routes from services + var routes []*adctypes.Route + for _, service := range resources.Services { + routes = append(routes, service.Routes...) + } + + return &translator.TranslateResult{ + Routes: routes, + Services: resources.Services, + SSL: resources.SSLs, + GlobalRules: resources.GlobalRules, + PluginMetadata: resources.PluginMetadata, + Consumers: resources.Consumers, + }, nil +} + +// adcRouteResource implements RouteResource +type adcRouteResource struct { + *adcDataplaneResource +} + +func (r *adcRouteResource) List(ctx context.Context) ([]*adctypes.Route, error) { + result, err := r.dumpResources(ctx) + if err != nil { + return nil, err + } + return result.Routes, nil +} + +// adcServiceResource implements ServiceResource +type adcServiceResource struct { + *adcDataplaneResource +} + +func (s *adcServiceResource) List(ctx context.Context) ([]*adctypes.Service, error) { + result, err := s.dumpResources(ctx) + if err != nil { + return nil, err + } + return result.Services, nil +} + +// adcSSLResource implements SSLResource +type adcSSLResource struct { + *adcDataplaneResource +} + +func (s *adcSSLResource) List(ctx context.Context) ([]*adctypes.SSL, error) { + result, err := s.dumpResources(ctx) + if err != nil { + return nil, err + } + return result.SSL, nil +} + +// adcConsumerResource implements ConsumerResource +type adcConsumerResource struct { + *adcDataplaneResource +} + +func (c *adcConsumerResource) List(ctx context.Context) ([]*adctypes.Consumer, error) { + result, err := c.dumpResources(ctx) + if err != nil { + return nil, err + } + return result.Consumers, nil +} diff --git a/test/e2e/scaffold/api7_deployer.go b/test/e2e/scaffold/api7_deployer.go index 69c52d6cd..a80ba7797 100644 --- a/test/e2e/scaffold/api7_deployer.go +++ b/test/e2e/scaffold/api7_deployer.go @@ -272,3 +272,12 @@ func (s *API7Deployer) GetAdminEndpoint(_ ...*corev1.Service) string { // always return the default dashboard endpoint return framework.DashboardTLSEndpoint } + +func (s *API7Deployer) DefaultDataplaneResource() DataplaneResource { + return newADCDataplaneResource( + "api7ee", + s.Framework.GetDashboardEndpoint(), + s.AdminKey(), + false, + ) +} diff --git a/test/e2e/scaffold/apisix_deployer.go b/test/e2e/scaffold/apisix_deployer.go index 6a8e3cd56..375e5576a 100644 --- a/test/e2e/scaffold/apisix_deployer.go +++ b/test/e2e/scaffold/apisix_deployer.go @@ -40,6 +40,7 @@ type APISIXDeployOptions struct { type APISIXDeployer struct { *Scaffold + adminTunnel *k8s.Tunnel } func NewAPISIXDeployer(s *Scaffold) *APISIXDeployer { @@ -91,6 +92,7 @@ func (s *APISIXDeployer) BeforeEach() { e.Add(func() { s.DeployDataplane() s.DeployIngress() + s.createAdminTunnel(s.dataplaneService) }) e.Add(s.DeployTestService) e.Wait() @@ -220,12 +222,7 @@ func getEnvOrDefault(key, defaultValue string) string { return defaultValue } -//nolint:unused -func (s *APISIXDeployer) createAdminTunnel( - svc *corev1.Service, - kubectlOpts *k8s.KubectlOptions, - serviceName string, -) (*k8s.Tunnel, error) { +func (s *APISIXDeployer) createAdminTunnel(svc *corev1.Service) (*k8s.Tunnel, error) { var ( adminNodePort int adminPort int @@ -239,7 +236,9 @@ func (s *APISIXDeployer) createAdminTunnel( } } - adminTunnel := k8s.NewTunnel(kubectlOpts, k8s.ResourceTypeService, serviceName, + kubectlOpts := k8s.NewKubectlOptions("", "", svc.Namespace) + + adminTunnel := k8s.NewTunnel(kubectlOpts, k8s.ResourceTypeService, svc.Name, adminNodePort, adminPort) if err := adminTunnel.ForwardPortE(s.t); err != nil { @@ -343,3 +342,12 @@ func (s *APISIXDeployer) GetAdminEndpoint(svc ...*corev1.Service) string { } return fmt.Sprintf("http://%s.%s:9180", svc[0].Name, svc[0].Namespace) } + +func (s *APISIXDeployer) DefaultDataplaneResource() DataplaneResource { + return newADCDataplaneResource( + "apisix-standalone", + s.adminTunnel.Endpoint(), + s.AdminKey(), + false, // tlsVerify + ) +} diff --git a/test/e2e/scaffold/deployer.go b/test/e2e/scaffold/deployer.go index 75614ed5d..f4216d896 100644 --- a/test/e2e/scaffold/deployer.go +++ b/test/e2e/scaffold/deployer.go @@ -12,7 +12,9 @@ package scaffold -import corev1 "k8s.io/api/core/v1" +import ( + corev1 "k8s.io/api/core/v1" +) // Deployer defines the interface for deploying data plane components type Deployer interface { @@ -25,6 +27,7 @@ type Deployer interface { CreateAdditionalGateway(namePrefix string) (string, string, error) CleanupAdditionalGateway(identifier string) error GetAdminEndpoint(...*corev1.Service) string + DefaultDataplaneResource() DataplaneResource } var NewDeployer func(*Scaffold) Deployer diff --git a/test/e2e/scaffold/scaffold.go b/test/e2e/scaffold/scaffold.go index d319bb04b..2121bd897 100644 --- a/test/e2e/scaffold/scaffold.go +++ b/test/e2e/scaffold/scaffold.go @@ -29,7 +29,6 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/apache/apisix-ingress-controller/pkg/dashboard" "github.com/apache/apisix-ingress-controller/test/e2e/framework" ) @@ -188,8 +187,8 @@ func (s *Scaffold) NewAPISIXHttpsClient(host string) *httpexpect.Expect { }) } -func (s *Scaffold) DefaultDataplaneResource() dashboard.Cluster { - return nil +func (s *Scaffold) DefaultDataplaneResource() DataplaneResource { + return s.Deployer.DefaultDataplaneResource() } func (s *Scaffold) DeployTestService() { From 0bb0e4b71375b37d0f266697c5e260e4c9b79004 Mon Sep 17 00:00:00 2001 From: ashing Date: Fri, 6 Jun 2025 18:24:09 +0800 Subject: [PATCH 3/7] fix: adc dump Signed-off-by: ashing --- test/e2e/gatewayapi/controller.go | 4 +-- test/e2e/scaffold/adc.go | 41 ++++++++++++++++++++++++++-- test/e2e/scaffold/api7_deployer.go | 2 +- test/e2e/scaffold/apisix_deployer.go | 2 +- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/test/e2e/gatewayapi/controller.go b/test/e2e/gatewayapi/controller.go index 4831fddc3..fa32ab799 100644 --- a/test/e2e/gatewayapi/controller.go +++ b/test/e2e/gatewayapi/controller.go @@ -167,11 +167,11 @@ spec: BeforeEach(func() { beforeEach(s1, "gateway1") }) - FIt("Apply resource ", func() { + It("Apply resource ", func() { ResourceApplied(s1, "HTTPRoute", "httpbin", "gateway1", route1, 1) routes, err := s1.DefaultDataplaneResource().Route().List(s1.Context) - log.Println("routes", routes) Expect(err).NotTo(HaveOccurred()) + log.Println("dump routes", routes) Expect(routes).To(HaveLen(1)) assert.Equal(GinkgoT(), routes[0].Labels["k8s/controller-name"], "apisix.apache.org/apisix-ingress-controller-1") }) diff --git a/test/e2e/scaffold/adc.go b/test/e2e/scaffold/adc.go index 12a984143..4a36956ae 100644 --- a/test/e2e/scaffold/adc.go +++ b/test/e2e/scaffold/adc.go @@ -15,13 +15,17 @@ package scaffold import ( "bytes" "context" - "encoding/json" + "errors" "os" "os/exec" "time" + "go.uber.org/zap" + "gopkg.in/yaml.v3" + adctypes "github.com/apache/apisix-ingress-controller/api/adc" "github.com/apache/apisix-ingress-controller/internal/provider/adc/translator" + "github.com/api7/gopkg/pkg/log" ) // DataplaneResource defines the interface for accessing dataplane resources @@ -88,6 +92,19 @@ func (a *adcDataplaneResource) Consumer() ConsumerResource { return &adcConsumerResource{a} } +func init() { + // dashboard sdk log + l, err := log.NewLogger( + log.WithOutputFile("stderr"), + log.WithLogLevel("debug"), + log.WithSkipFrames(3), + ) + if err != nil { + panic(err) + } + log.DefaultLogger = l +} + // dumpResources executes adc dump command and returns the resources func (a *adcDataplaneResource) dumpResources(ctx context.Context) (*translator.TranslateResult, error) { ctxWithTimeout, cancel := context.WithTimeout(ctx, a.syncTimeout) @@ -99,6 +116,7 @@ func (a *adcDataplaneResource) dumpResources(ctx context.Context) (*translator.T } adcEnv := []string{ + "ADC_RUNNING_MODE=", // need to set empty "ADC_BACKEND=" + a.backend, "ADC_SERVER=" + a.serverAddr, "ADC_TOKEN=" + a.token, @@ -111,12 +129,31 @@ func (a *adcDataplaneResource) dumpResources(ctx context.Context) (*translator.T cmd.Env = append(cmd.Env, os.Environ()...) cmd.Env = append(cmd.Env, adcEnv...) + log.Debug("running adc command", zap.String("command", cmd.String()), zap.Strings("env", adcEnv)) + if err := cmd.Run(); err != nil { + stderrStr := stderr.String() + stdoutStr := stdout.String() + errMsg := stderrStr + if errMsg == "" { + errMsg = stdoutStr + } + log.Errorw("failed to run adc", + zap.Error(err), + zap.String("output", stdoutStr), + zap.String("stderr", stderrStr), + ) + return nil, errors.New("failed to dump resources: " + errMsg + ", exit err: " + err.Error()) + } + + // Read the YAML file that was created by adc dump + yamlData, err := os.ReadFile("/tmp/dump.yaml") + if err != nil { return nil, err } var resources adctypes.Resources - if err := json.Unmarshal(stdout.Bytes(), &resources); err != nil { + if err := yaml.Unmarshal(yamlData, &resources); err != nil { return nil, err } diff --git a/test/e2e/scaffold/api7_deployer.go b/test/e2e/scaffold/api7_deployer.go index a80ba7797..2df21a0ea 100644 --- a/test/e2e/scaffold/api7_deployer.go +++ b/test/e2e/scaffold/api7_deployer.go @@ -276,7 +276,7 @@ func (s *API7Deployer) GetAdminEndpoint(_ ...*corev1.Service) string { func (s *API7Deployer) DefaultDataplaneResource() DataplaneResource { return newADCDataplaneResource( "api7ee", - s.Framework.GetDashboardEndpoint(), + fmt.Sprintf("http://%s", s.Framework.GetDashboardEndpoint()), s.AdminKey(), false, ) diff --git a/test/e2e/scaffold/apisix_deployer.go b/test/e2e/scaffold/apisix_deployer.go index 375e5576a..f283e4bc5 100644 --- a/test/e2e/scaffold/apisix_deployer.go +++ b/test/e2e/scaffold/apisix_deployer.go @@ -346,7 +346,7 @@ func (s *APISIXDeployer) GetAdminEndpoint(svc ...*corev1.Service) string { func (s *APISIXDeployer) DefaultDataplaneResource() DataplaneResource { return newADCDataplaneResource( "apisix-standalone", - s.adminTunnel.Endpoint(), + fmt.Sprintf("http://%s", s.adminTunnel.Endpoint()), s.AdminKey(), false, // tlsVerify ) From 3d1808d66651d6518c71306e6238ea85ce491543 Mon Sep 17 00:00:00 2001 From: ashing Date: Fri, 6 Jun 2025 18:28:59 +0800 Subject: [PATCH 4/7] fix: r Signed-off-by: ashing --- Dockerfile.dev | 7 +++++-- test/e2e/gatewayapi/controller.go | 2 -- test/e2e/scaffold/adc.go | 2 +- test/e2e/scaffold/api7_deployer.go | 2 +- test/e2e/scaffold/apisix_deployer.go | 4 +++- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Dockerfile.dev b/Dockerfile.dev index b7f1e15c1..ca2757643 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -3,7 +3,7 @@ ARG ENABLE_PROXY=false FROM node:22 AS node_builder ARG TARGETARCH -ARG ADC_COMMIT=78484e87a0168e0f86d130bfae8f808d0d1a1e41 +ARG ADC_COMMIT=e948079ed0576dbac29320ebfa01c9b7a298924c WORKDIR /app @@ -22,10 +22,13 @@ RUN apt update \ && rm -rf /app FROM debian:bullseye-slim + +ARG TARGETARCH + WORKDIR /app COPY --from=node_builder /bin/adc /bin/adc -COPY ./bin/apisix-ingress-controller . +COPY ./bin/apisix-ingress-controller_${TARGETARCH} ./apisix-ingress-controller COPY ./config/samples/config.yaml ./conf/config.yaml ENTRYPOINT ["/app/apisix-ingress-controller"] diff --git a/test/e2e/gatewayapi/controller.go b/test/e2e/gatewayapi/controller.go index fa32ab799..1412d5191 100644 --- a/test/e2e/gatewayapi/controller.go +++ b/test/e2e/gatewayapi/controller.go @@ -14,7 +14,6 @@ package gatewayapi import ( "fmt" - "log" "time" . "github.com/onsi/ginkgo/v2" @@ -171,7 +170,6 @@ spec: ResourceApplied(s1, "HTTPRoute", "httpbin", "gateway1", route1, 1) routes, err := s1.DefaultDataplaneResource().Route().List(s1.Context) Expect(err).NotTo(HaveOccurred()) - log.Println("dump routes", routes) Expect(routes).To(HaveLen(1)) assert.Equal(GinkgoT(), routes[0].Labels["k8s/controller-name"], "apisix.apache.org/apisix-ingress-controller-1") }) diff --git a/test/e2e/scaffold/adc.go b/test/e2e/scaffold/adc.go index 4a36956ae..4ccd18ca6 100644 --- a/test/e2e/scaffold/adc.go +++ b/test/e2e/scaffold/adc.go @@ -20,12 +20,12 @@ import ( "os/exec" "time" + "github.com/api7/gopkg/pkg/log" "go.uber.org/zap" "gopkg.in/yaml.v3" adctypes "github.com/apache/apisix-ingress-controller/api/adc" "github.com/apache/apisix-ingress-controller/internal/provider/adc/translator" - "github.com/api7/gopkg/pkg/log" ) // DataplaneResource defines the interface for accessing dataplane resources diff --git a/test/e2e/scaffold/api7_deployer.go b/test/e2e/scaffold/api7_deployer.go index 2df21a0ea..5415d2ab0 100644 --- a/test/e2e/scaffold/api7_deployer.go +++ b/test/e2e/scaffold/api7_deployer.go @@ -276,7 +276,7 @@ func (s *API7Deployer) GetAdminEndpoint(_ ...*corev1.Service) string { func (s *API7Deployer) DefaultDataplaneResource() DataplaneResource { return newADCDataplaneResource( "api7ee", - fmt.Sprintf("http://%s", s.Framework.GetDashboardEndpoint()), + fmt.Sprintf("http://%s", s.GetDashboardEndpoint()), s.AdminKey(), false, ) diff --git a/test/e2e/scaffold/apisix_deployer.go b/test/e2e/scaffold/apisix_deployer.go index f283e4bc5..1ada35d22 100644 --- a/test/e2e/scaffold/apisix_deployer.go +++ b/test/e2e/scaffold/apisix_deployer.go @@ -92,7 +92,9 @@ func (s *APISIXDeployer) BeforeEach() { e.Add(func() { s.DeployDataplane() s.DeployIngress() - s.createAdminTunnel(s.dataplaneService) + adminTunnel, err := s.createAdminTunnel(s.dataplaneService) + Expect(err).NotTo(HaveOccurred()) + s.adminTunnel = adminTunnel }) e.Add(s.DeployTestService) e.Wait() From 3d36cd2ddf28d571b0ecef20b5066b0cb698aa6c Mon Sep 17 00:00:00 2001 From: ashing Date: Fri, 6 Jun 2025 18:37:39 +0800 Subject: [PATCH 5/7] fix: adc build Signed-off-by: ashing --- .github/workflows/e2e-test.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index e4e8aa522..122336ba8 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -70,6 +70,18 @@ jobs: echo "building images..." make build-image + - name: Build Dockerfile.dev and extract adc binary + run: | + echo "Building Dockerfile.dev..." + docker build -f Dockerfile.dev -t adc-builder:latest . + echo "Extracting adc binary..." + docker run --name adc-temp adc-builder:latest /bin/true + docker cp adc-temp:/bin/adc ./bin/adc + docker rm adc-temp + chmod +x ./bin/adc + mv ./bin/adc /usr/local/bin/adc + echo "ADC binary extracted to /usr/local/bin/adc" + - name: Launch Kind Cluster run: | make kind-up From 36cabae7e8f926ace099b821fc9560d6ccb8cdda Mon Sep 17 00:00:00 2001 From: ashing Date: Fri, 6 Jun 2025 18:50:40 +0800 Subject: [PATCH 6/7] fix: r Signed-off-by: ashing --- .github/workflows/e2e-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index 122336ba8..e4cfe22ae 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -75,7 +75,7 @@ jobs: echo "Building Dockerfile.dev..." docker build -f Dockerfile.dev -t adc-builder:latest . echo "Extracting adc binary..." - docker run --name adc-temp adc-builder:latest /bin/true + docker run --name adc-temp --entrypoint="" adc-builder:latest /bin/true docker cp adc-temp:/bin/adc ./bin/adc docker rm adc-temp chmod +x ./bin/adc From 90128d17de607b2a7ec73d026508eacf991748a9 Mon Sep 17 00:00:00 2001 From: ashing Date: Mon, 9 Jun 2025 10:38:53 +0800 Subject: [PATCH 7/7] fix: r Signed-off-by: ashing --- test/e2e/gatewayapi/gateway.go | 2 -- test/e2e/scaffold/adc.go | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/test/e2e/gatewayapi/gateway.go b/test/e2e/gatewayapi/gateway.go index 5f6ee0499..353bd62de 100644 --- a/test/e2e/gatewayapi/gateway.go +++ b/test/e2e/gatewayapi/gateway.go @@ -15,7 +15,6 @@ package gatewayapi import ( "context" "fmt" - "log" "strings" "time" @@ -205,7 +204,6 @@ spec: tls, err := s.DefaultDataplaneResource().SSL().List(context.Background()) assert.Nil(GinkgoT(), err, "list tls error") assert.Len(GinkgoT(), tls, 1, "tls number not expect") - log.Println("tls", tls) assert.Len(GinkgoT(), tls[0].Certificates, 1, "length of certificates not expect") assert.Equal(GinkgoT(), Cert, tls[0].Certificates[0].Certificate, "tls cert not expect") assert.ElementsMatch(GinkgoT(), []string{host, "*.api6.com"}, tls[0].Snis) diff --git a/test/e2e/scaffold/adc.go b/test/e2e/scaffold/adc.go index 4ccd18ca6..aab8b50a1 100644 --- a/test/e2e/scaffold/adc.go +++ b/test/e2e/scaffold/adc.go @@ -110,7 +110,17 @@ func (a *adcDataplaneResource) dumpResources(ctx context.Context) (*translator.T ctxWithTimeout, cancel := context.WithTimeout(ctx, a.syncTimeout) defer cancel() - args := []string{"dump", "-o", "/tmp/dump.yaml"} + // Create a temporary file for the adc dump + tempFile, err := os.CreateTemp("", "adc-dump-*.yaml") + if err != nil { + return nil, err + } + defer func() { + _ = tempFile.Close() + _ = os.Remove(tempFile.Name()) + }() + + args := []string{"dump", "-o", tempFile.Name()} if !a.tlsVerify { args = append(args, "--tls-skip-verify") } @@ -147,7 +157,7 @@ func (a *adcDataplaneResource) dumpResources(ctx context.Context) (*translator.T } // Read the YAML file that was created by adc dump - yamlData, err := os.ReadFile("/tmp/dump.yaml") + yamlData, err := os.ReadFile(tempFile.Name()) if err != nil { return nil, err }