Skip to content

Commit

Permalink
feat: add kubernetes discovery module (apache#4880)
Browse files Browse the repository at this point in the history
Co-authored-by: zhixiogndu <adugeek@gmail.com>
Co-authored-by: zhixiongdu <zhixiongdu@upchina.com>
  • Loading branch information
3 people authored Feb 23, 2022
1 parent 8579a02 commit f7b50f2
Show file tree
Hide file tree
Showing 12 changed files with 1,987 additions and 2 deletions.
90 changes: 90 additions & 0 deletions .github/workflows/kubernetes-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: CI Kubernetes

on:
push:
branches: [ master, 'release/**' ]
paths-ignore:
- 'docs/**'
- '**/*.md'
pull_request:
branches: [ master, 'release/**' ]
paths-ignore:
- 'docs/**'
- '**/*.md'

concurrency:
group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && github.run_number || github.ref }}
cancel-in-progress: true

jobs:
kubernetes-discovery:
strategy:
fail-fast: false
matrix:
platform:
- ubuntu-18.04
os_name:
- linux_openresty
- linux_openresty_1_17

runs-on: ${{ matrix.platform }}
timeout-minutes: 15
env:
SERVER_NAME: ${{ matrix.os_name }}
OPENRESTY_VERSION: default

steps:
- name: Check out code
uses: actions/checkout@v2.4.0
with:
submodules: recursive

- name: Extract branch name
if: ${{ startsWith(github.ref, 'refs/heads/release/') }}
id: branch_env
shell: bash
run: |
echo "##[set-output name=version;]$(echo ${GITHUB_REF##*/})"
- name: Setup kubernetes cluster
run: |
KIND_VERSION="v0.11.1"
KUBECTL_VERSION="v1.22.0"
curl -Lo ./kind "https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-$(uname)-amd64"
curl -Lo ./kubectl "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl"
chmod +x ./kind
chmod +x ./kubectl
./kind create cluster --name apisix-test --config ./t_kubernetes/configs/kind.yaml
./kubectl wait --for=condition=Ready nodes --all --timeout=180s
./kubectl apply -f ./t_kubernetes/configs/account.yaml
./kubectl apply -f ./t_kubernetes/configs/endpoint.yaml
KUBERNETES_CLIENT_TOKEN_CONTENT=$(./kubectl get secrets | grep apisix-test | awk '{system("./kubectl get secret -o jsonpath={.data.token} "$1" | base64 --decode")}')
KUBERNETES_CLIENT_TOKEN_DIR="/tmp/var/run/secrets/kubernetes.io/serviceaccount"
KUBERNETES_CLIENT_TOKEN_FILE=${KUBERNETES_CLIENT_TOKEN_DIR}/token
mkdir -p ${KUBERNETES_CLIENT_TOKEN_DIR}
echo -n "$KUBERNETES_CLIENT_TOKEN_CONTENT" > ${KUBERNETES_CLIENT_TOKEN_FILE}
echo 'KUBERNETES_SERVICE_HOST=127.0.0.1'
echo 'KUBERNETES_SERVICE_PORT=6443'
echo 'KUBERNETES_CLIENT_TOKEN='"${KUBERNETES_CLIENT_TOKEN_CONTENT}"
echo 'KUBERNETES_CLIENT_TOKEN_FILE='${KUBERNETES_CLIENT_TOKEN_FILE}
./kubectl proxy -p 6445 &
- name: Linux Install
run: |
sudo apt install -y cpanminus build-essential libncurses5-dev libreadline-dev libssl-dev perl libpcre3 libpcre3-dev libldap2-dev
sudo cpanm --notest Test::Nginx >build.log 2>&1 || (cat build.log && exit 1)
sudo --preserve-env=OPENRESTY_VERSION ./ci/${{ matrix.os_name }}_runner.sh do_install
- name: Run test cases
run: |
./ci/kubernetes-ci.sh run_case
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,12 @@ install: runtime

$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/discovery
$(ENV_INSTALL) apisix/discovery/*.lua $(ENV_INST_LUADIR)/apisix/discovery/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/discovery/{consul_kv,dns,eureka,nacos}
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/discovery/{consul_kv,dns,eureka,nacos,kubernetes}
$(ENV_INSTALL) apisix/discovery/consul_kv/*.lua $(ENV_INST_LUADIR)/apisix/discovery/consul_kv
$(ENV_INSTALL) apisix/discovery/dns/*.lua $(ENV_INST_LUADIR)/apisix/discovery/dns
$(ENV_INSTALL) apisix/discovery/eureka/*.lua $(ENV_INST_LUADIR)/apisix/discovery/eureka
$(ENV_INSTALL) apisix/discovery/nacos/*.lua $(ENV_INST_LUADIR)/apisix/discovery/nacos
$(ENV_INSTALL) apisix/discovery/kubernetes/*.lua $(ENV_INST_LUADIR)/apisix/discovery/kubernetes

$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/http
$(ENV_INSTALL) apisix/http/*.lua $(ENV_INST_LUADIR)/apisix/http/
Expand Down
Loading

0 comments on commit f7b50f2

Please sign in to comment.