Skip to content

Commit 0bb0e4b

Browse files
committed
fix: adc dump
Signed-off-by: ashing <[email protected]>
1 parent 094a551 commit 0bb0e4b

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

test/e2e/gatewayapi/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ spec:
167167
BeforeEach(func() {
168168
beforeEach(s1, "gateway1")
169169
})
170-
FIt("Apply resource ", func() {
170+
It("Apply resource ", func() {
171171
ResourceApplied(s1, "HTTPRoute", "httpbin", "gateway1", route1, 1)
172172
routes, err := s1.DefaultDataplaneResource().Route().List(s1.Context)
173-
log.Println("routes", routes)
174173
Expect(err).NotTo(HaveOccurred())
174+
log.Println("dump routes", routes)
175175
Expect(routes).To(HaveLen(1))
176176
assert.Equal(GinkgoT(), routes[0].Labels["k8s/controller-name"], "apisix.apache.org/apisix-ingress-controller-1")
177177
})

test/e2e/scaffold/adc.go

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ package scaffold
1515
import (
1616
"bytes"
1717
"context"
18-
"encoding/json"
18+
"errors"
1919
"os"
2020
"os/exec"
2121
"time"
2222

23+
"go.uber.org/zap"
24+
"gopkg.in/yaml.v3"
25+
2326
adctypes "github.com/apache/apisix-ingress-controller/api/adc"
2427
"github.com/apache/apisix-ingress-controller/internal/provider/adc/translator"
28+
"github.com/api7/gopkg/pkg/log"
2529
)
2630

2731
// DataplaneResource defines the interface for accessing dataplane resources
@@ -88,6 +92,19 @@ func (a *adcDataplaneResource) Consumer() ConsumerResource {
8892
return &adcConsumerResource{a}
8993
}
9094

95+
func init() {
96+
// dashboard sdk log
97+
l, err := log.NewLogger(
98+
log.WithOutputFile("stderr"),
99+
log.WithLogLevel("debug"),
100+
log.WithSkipFrames(3),
101+
)
102+
if err != nil {
103+
panic(err)
104+
}
105+
log.DefaultLogger = l
106+
}
107+
91108
// dumpResources executes adc dump command and returns the resources
92109
func (a *adcDataplaneResource) dumpResources(ctx context.Context) (*translator.TranslateResult, error) {
93110
ctxWithTimeout, cancel := context.WithTimeout(ctx, a.syncTimeout)
@@ -99,6 +116,7 @@ func (a *adcDataplaneResource) dumpResources(ctx context.Context) (*translator.T
99116
}
100117

101118
adcEnv := []string{
119+
"ADC_RUNNING_MODE=", // need to set empty
102120
"ADC_BACKEND=" + a.backend,
103121
"ADC_SERVER=" + a.serverAddr,
104122
"ADC_TOKEN=" + a.token,
@@ -111,12 +129,31 @@ func (a *adcDataplaneResource) dumpResources(ctx context.Context) (*translator.T
111129
cmd.Env = append(cmd.Env, os.Environ()...)
112130
cmd.Env = append(cmd.Env, adcEnv...)
113131

132+
log.Debug("running adc command", zap.String("command", cmd.String()), zap.Strings("env", adcEnv))
133+
114134
if err := cmd.Run(); err != nil {
135+
stderrStr := stderr.String()
136+
stdoutStr := stdout.String()
137+
errMsg := stderrStr
138+
if errMsg == "" {
139+
errMsg = stdoutStr
140+
}
141+
log.Errorw("failed to run adc",
142+
zap.Error(err),
143+
zap.String("output", stdoutStr),
144+
zap.String("stderr", stderrStr),
145+
)
146+
return nil, errors.New("failed to dump resources: " + errMsg + ", exit err: " + err.Error())
147+
}
148+
149+
// Read the YAML file that was created by adc dump
150+
yamlData, err := os.ReadFile("/tmp/dump.yaml")
151+
if err != nil {
115152
return nil, err
116153
}
117154

118155
var resources adctypes.Resources
119-
if err := json.Unmarshal(stdout.Bytes(), &resources); err != nil {
156+
if err := yaml.Unmarshal(yamlData, &resources); err != nil {
120157
return nil, err
121158
}
122159

test/e2e/scaffold/api7_deployer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func (s *API7Deployer) GetAdminEndpoint(_ ...*corev1.Service) string {
276276
func (s *API7Deployer) DefaultDataplaneResource() DataplaneResource {
277277
return newADCDataplaneResource(
278278
"api7ee",
279-
s.Framework.GetDashboardEndpoint(),
279+
fmt.Sprintf("http://%s", s.Framework.GetDashboardEndpoint()),
280280
s.AdminKey(),
281281
false,
282282
)

test/e2e/scaffold/apisix_deployer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func (s *APISIXDeployer) GetAdminEndpoint(svc ...*corev1.Service) string {
346346
func (s *APISIXDeployer) DefaultDataplaneResource() DataplaneResource {
347347
return newADCDataplaneResource(
348348
"apisix-standalone",
349-
s.adminTunnel.Endpoint(),
349+
fmt.Sprintf("http://%s", s.adminTunnel.Endpoint()),
350350
s.AdminKey(),
351351
false, // tlsVerify
352352
)

0 commit comments

Comments
 (0)