Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into okaybase
Browse files Browse the repository at this point in the history
  • Loading branch information
tokers committed Apr 2, 2021
2 parents ac9887f + 8006297 commit d083e12
Show file tree
Hide file tree
Showing 17 changed files with 720 additions and 139 deletions.
19 changes: 5 additions & 14 deletions .github/workflows/e2e-test-ci.yml
Expand Up @@ -7,25 +7,16 @@ on:
pull_request:
branches:
- master
- ci/e2e
jobs:
e2e-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install minikube
- name: Install kind
run: |
sh ./utils/minikube.sh
- name: Output cluster info
run: kubectl cluster-info
- name: Add images
run: |
IMAGE_TAG=dev make build-image-to-minikube
eval $(minikube docker-env)
docker pull apache/apisix:dev
docker pull bitnami/etcd:3.4.14-debian-10-r0
docker pull kennethreitz/httpbin
docker images
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.10.0/kind-linux-amd64
chmod +x ./kind
sudo mv kind /usr/local/bin
- name: Setup Go Env
uses: actions/setup-go@v1
with:
Expand All @@ -37,7 +28,7 @@ jobs:
- name: Run e2e test cases
working-directory: ./
run: |
make e2e-test E2E_SKIP_BUILD=1 E2E_CONCURRENCY=1
make e2e-test E2E_CONCURRENCY=2
- name: upload coverage profile
working-directory: ./test/e2e
run: |
Expand Down
64 changes: 46 additions & 18 deletions Makefile
Expand Up @@ -18,6 +18,7 @@ default: help

VERSION ?= 0.4.0
RELEASE_SRC = apache-apisix-ingress-controller-${VERSION}-src
LOCAL_REGISTRY="localhost:5000"
IMAGE_TAG ?= dev

GINKGO ?= $(shell which ginkgo)
Expand All @@ -36,31 +37,37 @@ GO_LDFLAGS ?= "-X=$(VERSYM)=$(VERSION) -X=$(GITSHASYM)=$(GITSHA) -X=$(BUILDOSSYM
E2E_CONCURRENCY ?= 1
E2E_SKIP_BUILD ?= 0

### build: Build apisix-ingress-controller
### build: Build apisix-ingress-controller
.PHONY: build
build:
go build \
-o apisix-ingress-controller \
-ldflags $(GO_LDFLAGS) \
main.go

### build-image: Build apisix-ingress-controller image
### build-image: Build apisix-ingress-controller image
.PHONY: build-image
build-image:
docker build -t apache/apisix-ingress-controller:$(IMAGE_TAG) .

### lint: Do static lint check
### lint: Do static lint check
.PHONY: lint
lint:
golangci-lint run

### gofmt: Format all go codes
### gofmt: Format all go codes
.PHONY: gofmt
gofmt:
find . -type f -name "*.go" | xargs gofmt -w -s

### unit-test: Run unit test cases
### unit-test: Run unit test cases
.PHONY: unit-test
unit-test:
go test -cover -coverprofile=coverage.txt ./...

### e2e-test: Run e2e test cases (minikube is required)
e2e-test: ginkgo-check build-image-to-minikube
### e2e-test: Run e2e test cases (kind is required)
.PHONY: e2e-test
e2e-test: ginkgo-check push-images-to-kind
kubectl apply -f $(PWD)/samples/deploy/crd/v1beta1/ApisixRoute.yaml
kubectl apply -f $(PWD)/samples/deploy/crd/v1beta1/ApisixUpstream.yaml
kubectl apply -f $(PWD)/samples/deploy/crd/v1beta1/ApisixTls.yaml
Expand All @@ -73,30 +80,54 @@ ifeq ("$(wildcard $(GINKGO))", "")
exit 1
endif

# build images to minikube node directly, it's an internal directive, so don't
# expose it's help message.
build-image-to-minikube:
### push-images-to-kind: Push images used in e2e test suites to kind.
.PHONY: push-images-to-kind
push-images-to-kind: kind-up
ifeq ($(E2E_SKIP_BUILD), 0)
@minikube version > /dev/null 2>&1 || (echo "ERROR: minikube is required."; exit 1)
@eval $$(minikube docker-env);\
docker pull apache/apisix:dev
docker tag apache/apisix:dev $(LOCAL_REGISTRY)/apache/apisix:dev
docker push $(LOCAL_REGISTRY)/apache/apisix:dev

docker pull bitnami/etcd:3.4.14-debian-10-r0
docker tag bitnami/etcd:3.4.14-debian-10-r0 $(LOCAL_REGISTRY)/bitnami/etcd:3.4.14-debian-10-r0
docker push $(LOCAL_REGISTRY)/bitnami/etcd:3.4.14-debian-10-r0

docker pull kennethreitz/httpbin
docker tag kennethreitz/httpbin $(LOCAL_REGISTRY)/kennethreitz/httpbin
docker push $(LOCAL_REGISTRY)/kennethreitz/httpbin

docker build -t apache/apisix-ingress-controller:$(IMAGE_TAG) .
docker tag apache/apisix-ingress-controller:$(IMAGE_TAG) $(LOCAL_REGISTRY)/apache/apisix-ingress-controller:$(IMAGE_TAG)
docker push $(LOCAL_REGISTRY)/apache/apisix-ingress-controller:$(IMAGE_TAG)
endif

### license-check: Do Apache License Header check
### kind-up: Launch a Kubernetes cluster with a image registry by Kind.
.PHONY: kind-up
kind-up:
./utils/kind-with-registry.sh
### kind-reset: Delete the Kubernetes cluster created by "make kind-up"
.PHONY: kind-reset
kind-reset:
kind delete cluster --name apisix

### license-check: Do Apache License Header check
.PHONY: license-check
license-check:
ifeq ("$(wildcard .actions/openwhisk-utilities/scancode/scanCode.py)", "")
git clone https://github.com/apache/openwhisk-utilities.git .actions/openwhisk-utilities
cp .actions/ASF* .actions/openwhisk-utilities/scancode/
endif
.actions/openwhisk-utilities/scancode/scanCode.py --config .actions/ASF-Release.cfg ./

### help: Show Makefile rules
### help: Show Makefile rules
.PHONY: help
help:
@echo Makefile rules:
@echo
@grep -E '^### [-A-Za-z0-9_]+:' Makefile | sed 's/###/ /'

### release-src: Release source
### release-src: Release source
.PHONY: release-src
release-src:
tar -zcvf $(RELEASE_SRC).tgz \
--exclude .github \
Expand All @@ -118,6 +149,3 @@ release-src:
mv $(RELEASE_SRC).tgz release/$(RELEASE_SRC).tgz
mv $(RELEASE_SRC).tgz.asc release/$(RELEASE_SRC).tgz.asc
mv $(RELEASE_SRC).tgz.sha512 release/$(RELEASE_SRC).tgz.sha512

.PHONY: build lint help

2 changes: 2 additions & 0 deletions pkg/apisix/resource.go
Expand Up @@ -81,6 +81,7 @@ type routeItem struct {
Uris []string `json:"uris"`
Desc string `json:"desc"`
Methods []string `json:"methods"`
Priority int `json:"priority"`
Plugins map[string]interface{} `json:"plugins"`
}

Expand Down Expand Up @@ -114,6 +115,7 @@ func (i *item) route(clusterName string) (*v1.Route, error) {
UpstreamId: route.UpstreamId,
ServiceId: route.ServiceId,
Plugins: route.Plugins,
Priority: route.Priority,
}, nil
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/apisix/route.go
Expand Up @@ -32,6 +32,7 @@ type routeReqBody struct {
Desc string `json:"desc,omitempty"`
Name string `json:"name,omitempty"`
URI string `json:"uri,omitempty"`
Priority int `json:"priority,omitempty"`
Uris []string `json:"uris,omitempty"`
Vars [][]v1.StringOrSlice `json:"vars,omitempty"`
Host string `json:"host,omitempty"`
Expand Down Expand Up @@ -160,6 +161,7 @@ func (r *routeClient) Create(ctx context.Context, obj *v1.Route) (*v1.Route, err
return nil, err
}
data, err := json.Marshal(routeReqBody{
Priority: obj.Priority,
Desc: obj.Name,
Name: obj.Name,
URI: obj.Path,
Expand Down Expand Up @@ -229,6 +231,7 @@ func (r *routeClient) Update(ctx context.Context, obj *v1.Route) (*v1.Route, err
return nil, err
}
body, err := json.Marshal(routeReqBody{
Priority: obj.Priority,
Desc: obj.Name,
Name: obj.Name,
Host: obj.Host,
Expand Down
9 changes: 9 additions & 0 deletions pkg/kube/translation/apisix_route.go
Expand Up @@ -100,9 +100,17 @@ func (t *translator) TranslateRouteV2alpha1(ar *configv2alpha1.ApisixRoute) ([]*
upstreams []*apisixv1.Upstream
)

ruleNameMap := make(map[string]struct{})
upstreamMap := make(map[string]*apisixv1.Upstream)

for _, part := range ar.Spec.HTTP {
if part.Name == "" {
return nil, nil, errors.New("empty route rule name")
}
if _, ok := ruleNameMap[part.Name]; ok {
return nil, nil, errors.New("duplicated route rule name")
}
ruleNameMap[part.Name] = struct{}{}
if part.Match == nil {
return nil, nil, errors.New("empty route match section")
}
Expand Down Expand Up @@ -168,6 +176,7 @@ func (t *translator) TranslateRouteV2alpha1(ar *configv2alpha1.ApisixRoute) ([]*
ID: id.GenID(routeName),
ResourceVersion: ar.ResourceVersion,
},
Priority: part.Priority,
Vars: exprs,
Hosts: part.Match.Hosts,
Uris: part.Match.Paths,
Expand Down

0 comments on commit d083e12

Please sign in to comment.