-
Notifications
You must be signed in to change notification settings - Fork 4
feat: validate APISIX resources in webhooks #393
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
base: master
Are you sure you want to change the base?
Changes from all commits
ba91ae8
0b74a9c
10d76b4
d9ba66c
07b7c4d
73f3836
23fb4e7
7663b68
8859187
742f11b
9b1533e
24f141d
ec74a51
e90710e
d401305
6618932
4141447
d1a32ed
a58fd8c
f032228
4dee995
eef1a88
9a29eb2
9efafc9
badcb29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -194,7 +194,7 @@ kind-down: | |
| || echo "kind cluster does not exist" | ||
|
|
||
| .PHONY: kind-load-images | ||
| kind-load-images: pull-infra-images kind-load-ingress-image kind-load-adc-image | ||
| kind-load-images: pull-infra-images build-e2e-echo-server-image kind-load-ingress-image kind-load-adc-image | ||
| @kind load docker-image hkccr.ccs.tencentyun.com/api7-dev/api7-ee-3-gateway:dev --name $(KIND_NAME) | ||
| @kind load docker-image hkccr.ccs.tencentyun.com/api7-dev/api7-ee-dp-manager:$(DASHBOARD_VERSION) --name $(KIND_NAME) | ||
| @kind load docker-image hkccr.ccs.tencentyun.com/api7-dev/api7-ee-3-integrated:$(DASHBOARD_VERSION) --name $(KIND_NAME) | ||
|
|
@@ -222,16 +222,39 @@ kind-load-adc-image: | |
| @docker tag ghcr.io/api7/adc:$(ADC_VERSION) ghcr.io/api7/adc:dev | ||
| @kind load docker-image ghcr.io/api7/adc:dev --name $(KIND_NAME) | ||
|
|
||
| .PHONY: build-e2e-echo-server-image | ||
| build-e2e-echo-server-image: | ||
| @CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/e2e-echo-server ./cmd/e2e-echo-server | ||
| @docker build -f test/e2e/images/echo-server.Dockerfile -t jmalloc/echo-server:latest . | ||
|
Comment on lines
+226
to
+228
|
||
|
|
||
| .PHONY: pull-infra-images | ||
| pull-infra-images: | ||
| @docker pull hkccr.ccs.tencentyun.com/api7-dev/api7-ee-3-gateway:dev | ||
| @docker pull hkccr.ccs.tencentyun.com/api7-dev/api7-ee-dp-manager:$(DASHBOARD_VERSION) | ||
| @docker pull hkccr.ccs.tencentyun.com/api7-dev/api7-ee-3-integrated:$(DASHBOARD_VERSION) | ||
| @docker pull kennethreitz/httpbin:latest | ||
| @docker pull jmalloc/echo-server:latest | ||
| @docker pull ghcr.io/api7/adc:dev | ||
| @docker pull apache/apisix:dev | ||
| @docker pull openresty/openresty:1.27.1.2-4-bullseye-fat | ||
| @retry_pull() { \ | ||
| source="$$1"; \ | ||
| target="$$2"; \ | ||
| for attempt in 1 2 3; do \ | ||
| if docker pull "$$source"; then \ | ||
| if [ "$$source" != "$$target" ]; then \ | ||
| docker tag "$$source" "$$target"; \ | ||
| fi; \ | ||
| return 0; \ | ||
| fi; \ | ||
| if [ $$attempt -eq 3 ]; then \ | ||
| echo "failed to pull $$source after $$attempt attempts" >&2; \ | ||
| exit 1; \ | ||
| fi; \ | ||
| echo "retrying docker pull for $$source (attempt $$((attempt + 1))/3)..." >&2; \ | ||
| sleep 5; \ | ||
| done; \ | ||
| }; \ | ||
| retry_pull "hkccr.ccs.tencentyun.com/api7-dev/api7-ee-3-gateway:dev" "hkccr.ccs.tencentyun.com/api7-dev/api7-ee-3-gateway:dev"; \ | ||
| retry_pull "hkccr.ccs.tencentyun.com/api7-dev/api7-ee-dp-manager:$(DASHBOARD_VERSION)" "hkccr.ccs.tencentyun.com/api7-dev/api7-ee-dp-manager:$(DASHBOARD_VERSION)"; \ | ||
| retry_pull "hkccr.ccs.tencentyun.com/api7-dev/api7-ee-3-integrated:$(DASHBOARD_VERSION)" "hkccr.ccs.tencentyun.com/api7-dev/api7-ee-3-integrated:$(DASHBOARD_VERSION)"; \ | ||
| dockerhub_proxy="$${DOCKERHUB_PROXY:-docker.m.daocloud.io}"; \ | ||
| retry_pull "$$dockerhub_proxy/kennethreitz/httpbin:latest" "kennethreitz/httpbin:latest"; \ | ||
| retry_pull "ghcr.io/api7/adc:dev" "ghcr.io/api7/adc:dev"; \ | ||
| retry_pull "$$dockerhub_proxy/apache/apisix:dev" "apache/apisix:dev"; \ | ||
| retry_pull "$$dockerhub_proxy/openresty/openresty:1.27.1.2-4-bullseye-fat" "openresty/openresty:1.27.1.2-4-bullseye-fat" | ||
|
|
||
| ##@ Build | ||
|
|
||
|
|
@@ -398,8 +421,12 @@ $(ADC_BIN): | |
| ifeq ($(ADC_VERSION),dev) | ||
| @echo "ADC_VERSION=dev, skip download" | ||
| else | ||
| curl -sSfL https://github.com/api7/adc/releases/download/v${ADC_VERSION}/adc_${ADC_VERSION}_${GOOS}_${GOARCH}.tar.gz \ | ||
| | tar -xz -C $(LOCALBIN) | ||
| tmp_archive=$$(mktemp); \ | ||
| trap 'rm -f "$$tmp_archive"' EXIT; \ | ||
| curl --retry 5 --retry-delay 2 --retry-connrefused -sSfL \ | ||
| -o "$$tmp_archive" \ | ||
| https://github.com/api7/adc/releases/download/v${ADC_VERSION}/adc_${ADC_VERSION}_${GOOS}_${GOARCH}.tar.gz; \ | ||
| tar -xzf "$$tmp_archive" -C $(LOCALBIN) | ||
| endif | ||
|
|
||
| gofmt: ## Apply go fmt | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,44 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| package main | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+3
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "log" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "net/http" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/gorilla/websocket" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+8
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var upgrader = websocket.Upgrader{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CheckOrigin: func(*http.Request) bool { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+6
to
+15
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/gorilla/websocket" | |
| ) | |
| var upgrader = websocket.Upgrader{ | |
| CheckOrigin: func(*http.Request) bool { | |
| return true | |
| }, | |
| } | |
| "net/url" | |
| "github.com/gorilla/websocket" | |
| ) | |
| func sameHostOrigin(r *http.Request) bool { | |
| origin := r.Header.Get("Origin") | |
| if origin == "" { | |
| return true | |
| } | |
| u, err := url.Parse(origin) | |
| if err != nil { | |
| return false | |
| } | |
| return u.Host == r.Host | |
| } | |
| var upgrader = websocket.Upgrader{ | |
| CheckOrigin: sameHostOrigin, | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,6 +174,43 @@ func (c *Client) DeleteConfig(ctx context.Context, args Task) error { | |
| return err | ||
| } | ||
|
|
||
| func (c *Client) Validate(ctx context.Context, task Task) error { | ||
| if len(task.Configs) == 0 || task.Resources == nil { | ||
| return nil | ||
| } | ||
|
|
||
| fileIOStart := time.Now() | ||
| syncFilePath, cleanup, err := prepareSyncFile(task.Resources) | ||
| if err != nil { | ||
| pkgmetrics.RecordFileIODuration("prepare_sync_file", "failure", time.Since(fileIOStart).Seconds()) | ||
| return err | ||
| } | ||
| pkgmetrics.RecordFileIODuration("prepare_sync_file", adctypes.StatusSuccess, time.Since(fileIOStart).Seconds()) | ||
| defer cleanup() | ||
|
|
||
| args := BuildADCExecuteArgs(syncFilePath, task.Labels, task.ResourceTypes) | ||
|
|
||
| var errs types.ADCValidationErrors | ||
| for _, config := range task.Configs { | ||
| if config.BackendType == "" { | ||
| config.BackendType = c.defaultMode | ||
| } | ||
| if err := c.executor.Validate(ctx, config, args); err != nil { | ||
| var validationErr types.ADCValidationError | ||
| if errors.As(err, &validationErr) { | ||
| errs.Errors = append(errs.Errors, validationErr) | ||
| continue | ||
| } | ||
| return err | ||
| } | ||
|
Comment on lines
+193
to
+205
|
||
| } | ||
|
|
||
| if len(errs.Errors) > 0 { | ||
| return errs | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (c *Client) Sync(ctx context.Context) (map[string]types.ADCExecutionErrors, error) { | ||
| c.syncMu.Lock() | ||
| defer c.syncMu.Unlock() | ||
|
|
||
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.
build-e2e-echo-server-imagehard-codesGOARCH=amd64. This will break running e2e tests on arm64 hosts/clusters (the scratch image will contain an amd64 binary). Consider using the existing$(GOARCH)Makefile variable (or building/loading a multi-arch image) so the echo-server image matches the target platform.