This is an automated email from the ASF dual-hosted git repository. hanahmily pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/skywalking-swck.git
The following commit(s) were added to refs/heads/master by this push: new aad0db9 add e2e test[OAP+UI+Agent] (#46) aad0db9 is described below commit aad0db9b0616073fa80b0ff4c1f9755ee826db54 Author: dashanji <71587243+dasha...@users.noreply.github.com> AuthorDate: Wed Nov 17 07:59:38 2021 +0800 add e2e test[OAP+UI+Agent] (#46) * add e2e test * Bump up SkyWalking Java agent to 8.8.0. * Add imagePullPolicy: IfNotPresent to avoid tagging the controller's image in the kind cluster. --- .github/workflows/go.yml | 19 +++- Makefile | 5 + config/operator/manager/manager.yaml | 1 + hack/prepare-e2e.sh | 77 +++++++++++++++ hack/wait-webhook.sh | 41 ++++++++ .../manifests/injector/templates/annotations.yaml | 2 +- pkg/operator/repo/assets.gen.go | 6 +- test/e2e/demo.yaml | 56 +++++++++++ test/e2e/e2e.yaml | 109 +++++++++++++++++++++ test/e2e/kind.yaml | 41 ++++++++ .../e2e/skywalking-components.yaml | 61 +++++------- test/e2e/verify/endpoint.yaml | 19 ++++ test/e2e/verify/metrics.yaml | 19 ++++ .../manager.yaml => test/e2e/verify/service.yaml | 44 +-------- 14 files changed, 421 insertions(+), 79 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 6c317f5..0fad3f2 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -80,9 +80,26 @@ jobs: run: ./hack/install-kubebuilder.sh - name: tests run: make test + e2e-tests: + name: e2e tests(oap+ui+agent) + runs-on: ubuntu-latest + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + id: go + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + - name: Update dependencies + run: GOPROXY=https://proxy.golang.org go mod download + - name: Run E2E Test + uses: apache/skywalking-infra-e2e@996ed8902e941e2883fcf0ac5b3090364942d205 # always prefer to use a revision instead of `main`. + with: + e2e-file: test/e2e/e2e.yaml # need to run E2E file path checks: name: build runs-on: ubuntu-20.04 - needs: [check, build, unit-tests] + needs: [check, build, unit-tests, e2e-tests] steps: - run: echo 'success' diff --git a/Makefile b/Makefile index 38fb18f..3143263 100644 --- a/Makefile +++ b/Makefile @@ -50,6 +50,11 @@ clean: test: generate operator-manifests go test ./... -coverprofile cover.out +# Run e2e-test +e2e-test: + @echo "Run e2e..." + e2e run -c test/e2e/e2e.yaml + # Build manager binary operator: generate go build -o bin/manager cmd/manager/manager.go diff --git a/config/operator/manager/manager.yaml b/config/operator/manager/manager.yaml index 2eb0b50..d0699c9 100644 --- a/config/operator/manager/manager.yaml +++ b/config/operator/manager/manager.yaml @@ -45,6 +45,7 @@ spec: args: - --enable-leader-election image: controller:latest + imagePullPolicy: IfNotPresent name: manager resources: limits: diff --git a/hack/prepare-e2e.sh b/hack/prepare-e2e.sh new file mode 100755 index 0000000..9a7f356 --- /dev/null +++ b/hack/prepare-e2e.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. + +OS=$(go env GOOS) +ARCH=$(go env GOHOSTARCH) + +INSTALL_DIR=/usr/local/bin + +prepare_ok=true +# install kubectl +function install_kubectl() +{ + if ! command -v kubectl &> /dev/null; then + curl -LO https://dl.k8s.io/release/v1.19.1/bin/${OS}/${ARCH}/kubectl && chmod +x ./kubectl && mv ./kubectl ${INSTALL_DIR} + if [ $? -ne 0 ]; then + echo "install kubectl error, please check" + $prepare_ok=false + fi + fi +} +# install swctl +function install_swctl() +{ + if ! command -v swctl &> /dev/null; then + wget https://github.com/apache/skywalking-cli/archive/0.9.0.tar.gz -O - |\ + tar xz && cd skywalking-cli-0.9.0 && make ${OS} && mv bin/swctl-*-${OS}-amd64 ${INSTALL_DIR}/swctl \ + && cd .. && rm -r skywalking-cli-0.9.0 + if [ $? -ne 0 ]; then + echo "install swctl error, please check" + $prepare_ok=false + fi + fi +} +# install yq +function install_yq() +{ + if ! command -v yq &> /dev/null; then + echo "install yq..." + wget https://github.com/mikefarah/yq/releases/download/v4.11.1/yq_${OS}_${ARCH}.tar.gz -O - |\ + tar xz && mv yq_${OS}_${ARCH} ${INSTALL_DIR}/yq + if [ $? -ne 0 ]; then + echo "install yq error, please check" + $prepare_ok=false + fi + fi +} + +function install_all() +{ + echo "check e2e dependencies..." + install_kubectl + install_swctl + install_yq + if [ "$prepare_ok" = false ]; then + echo "check e2e dependencies failed" + exit + else + echo "check e2e dependencies successfully" + fi +} + +install_all \ No newline at end of file diff --git a/hack/wait-webhook.sh b/hack/wait-webhook.sh new file mode 100644 index 0000000..dea5931 --- /dev/null +++ b/hack/wait-webhook.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. + +TIMEOUT=60 + +MANIFEST=$(mktemp) + +cat <<EOF > $MANIFEST +apiVersion: operator.skywalking.apache.org/v1alpha1 +kind: OAPServer +metadata: + name: dummy +spec: + version: 8.8.1 + instances: 1 + image: apache/skywalking-oap-server:8.8.1 +EOF + +timeout $TIMEOUT bash -c -- "\ + while ! kubectl create -f $MANIFEST 2> /dev/null; \ + do \ + sleep 0.1; \ + done" + +# make sure the dummy OAPServer will be deleted +trap "kubectl delete OAPServer dummy; rm $MANIFEST" 0 2 3 15 diff --git a/pkg/operator/manifests/injector/templates/annotations.yaml b/pkg/operator/manifests/injector/templates/annotations.yaml index 57b0ed5..c8ad963 100644 --- a/pkg/operator/manifests/injector/templates/annotations.yaml +++ b/pkg/operator/manifests/injector/templates/annotations.yaml @@ -30,7 +30,7 @@ annotations: envName: nil - name: sidecar.skywalking.apache.org/initcontainer.Image - defaultValue: apache/skywalking-java-agent:8.7.0-jdk8 + defaultValue: apache/skywalking-java-agent:8.8.0-java8 validateFunc: nil envName: nil diff --git a/pkg/operator/repo/assets.gen.go b/pkg/operator/repo/assets.gen.go index 63dbe68..a7a529a 100644 --- a/pkg/operator/repo/assets.gen.go +++ b/pkg/operator/repo/assets.gen.go @@ -21,7 +21,7 @@ // fetcher/templates/configmap.yaml (3.082kB) // fetcher/templates/deployment.yaml (2.084kB) // fetcher/templates/service_account.yaml (1.088kB) -// injector/templates/annotations.yaml (3.361kB) +// injector/templates/annotations.yaml (3.362kB) // injector/templates/configmap.yaml (1.2kB) // injector/templates/javaagent.yaml (1.462kB) // oapserver/templates/cluster_role.yaml (1.241kB) @@ -435,7 +435,7 @@ annotations: envName: nil - name: sidecar.skywalking.apache.org/initcontainer.Image - defaultValue: apache/skywalking-java-agent:8.7.0-jdk8 + defaultValue: apache/skywalking-java-agent:8.8.0-java8 validateFunc: nil envName: nil @@ -511,7 +511,7 @@ func injectorTemplatesAnnotationsYaml() (*asset, error) { } info := bindataFileInfo{name: "injector/templates/annotations.yaml", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x29, 0x36, 0xc1, 0x23, 0x27, 0xb2, 0x7a, 0x2, 0xed, 0x56, 0x6f, 0x83, 0x49, 0x8, 0x1c, 0x78, 0xf7, 0xfa, 0x7b, 0xe3, 0xa3, 0xc2, 0x7a, 0xb0, 0x5b, 0x5b, 0xd0, 0x7c, 0xb5, 0xe3, 0x1e, 0x85}} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xd2, 0x9a, 0xe0, 0xe4, 0x15, 0x93, 0xed, 0xf7, 0xf7, 0x7b, 0xff, 0x1a, 0x27, 0x8f, 0x85, 0x54, 0xa1, 0x2d, 0x26, 0x53, 0x89, 0x7b, 0x7d, 0xf4, 0x6c, 0x32, 0xfe, 0xc, 0xbd, 0x76, 0x36, 0x59}} return a, nil } diff --git a/test/e2e/demo.yaml b/test/e2e/demo.yaml new file mode 100644 index 0000000..fb1e2f1 --- /dev/null +++ b/test/e2e/demo.yaml @@ -0,0 +1,56 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: demo + namespace: skywalking-system +spec: + selector: + matchLabels: + app: demo + template: + metadata: + labels: + swck-java-agent-injected: "true" + app: demo + annotations: + strategy.skywalking.apache.org/agent.Overlay: "true" + agent.skywalking.apache.org/collector.backend_service: "skywalking-system-oap.skywalking-system:11800" + spec: + containers: + - name: demo1 + imagePullPolicy: IfNotPresent + image: ghcr.io/apache/skywalking-swck-spring-demo:v0.0.1 + command: ["java"] + args: ["$(AGENT_OPTS)","-jar","/app.jar"] + ports: + - containerPort: 8085 +--- +apiVersion: v1 +kind: Service +metadata: + name: demo + namespace: skywalking-system +spec: + type: ClusterIP + ports: + - name: 8085-tcp + port: 8085 + protocol: TCP + targetPort: 8085 + selector: + app: demo diff --git a/test/e2e/e2e.yaml b/test/e2e/e2e.yaml new file mode 100644 index 0000000..570a4df --- /dev/null +++ b/test/e2e/e2e.yaml @@ -0,0 +1,109 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. + +setup: + env: kind + file: kind.yaml + steps: + - name: prepare e2e.yaml + command: bash hack/prepare-e2e.sh + - name: install cert-manager + command: | + # kind k8s cluster is in $TMPDIR + export KUBECONFIG=$TMPDIR/e2e-k8s.config + kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.3.1/cert-manager.yaml + wait: + - namespace: cert-manager + resource: pod + for: condition=Ready + - name: install operator + command: | + export OPERATOR_IMG=controller + make operator-docker-build + kind load docker-image controller + make operator-install + make operator-deploy + wait: + - namespace: skywalking-swck-system + resource: pod + for: condition=Ready + - name: wait webhook installing + command: | + bash hack/wait-webhook.sh + - name: setup oapserver and ui + command: | + kubectl create namespace skywalking-system + kubectl apply -f test/e2e/skywalking-components.yaml + wait: + - namespace: skywalking-system + resource: OAPServer/skywalking-system + for: condition=Available + - namespace: skywalking-system + resource: UI/skywalking-system + for: condition=Available + - name: setup java agent demo + command: | + kubectl label namespace skywalking-system swck-injection=enabled + kubectl apply -f test/e2e/demo.yaml + wait: + - namespace: skywalking-system + resource: deployment/demo + for: condition=Available + kind: + expose-ports: + - namespace: skywalking-system + resource: service/demo + port: 8085 + - namespace: skywalking-system + resource: service/skywalking-system-oap + port: 12800 + - namespace: skywalking-system + resource: service/skywalking-system-ui + port: 80 + timeout: 20m + +cleanup: + # always never success failure + on: always + +trigger: + action: http + interval: 30s + times: 5 + url: http://${service_demo_host}:${service_demo_8085}/hello + method: GET + +verify: + # verify with retry strategy + retry: + # max retry count + count: 10 + # the interval between two attempts, e.g. 10s, 1m. + interval: 10s + cases: + # test oapserver + - query: swctl --display yaml --base-url=http://${service_skywalking_system_oap_host}:${service_skywalking_system_oap_12800}/graphql service ls + expected: verify/service.yaml + - query: swctl --display yaml --base-url=http://${service_skywalking_system_oap_host}:${service_skywalking_system_oap_12800}/graphql metrics linear --name service_cpm --service-name Your_ApplicationName | yq e 'to_entries' - + expected: verify/metrics.yaml + - query: swctl --display yaml --base-url=http://${service_skywalking_system_oap_host}:${service_skywalking_system_oap_12800}/graphql endpoint list --keyword=hello --service-name Your_ApplicationName + expected: verify/endpoint.yaml + - query: swctl --display yaml --base-url=http://${service_skywalking_system_oap_host}:${service_skywalking_system_oap_12800}/graphql metrics linear --name endpoint_cpm --endpoint-name GET:/hello --service-name Your_ApplicationName | yq e 'to_entries' - + expected: verify/metrics.yaml + # test ui + - query: swctl --display yaml --base-url=http://${service_skywalking_system_ui_host}:${service_skywalking_system_ui_80}/graphql service ls + expected: verify/service.yaml + - query: swctl --display yaml --base-url=http://${service_skywalking_system_ui_host}:${service_skywalking_system_ui_80}/graphql endpoint list --keyword=hello --service-name Your_ApplicationName + expected: verify/endpoint.yaml \ No newline at end of file diff --git a/test/e2e/kind.yaml b/test/e2e/kind.yaml new file mode 100644 index 0000000..fcb7a90 --- /dev/null +++ b/test/e2e/kind.yaml @@ -0,0 +1,41 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. + +# this config file contains all config fields with comments +# NOTE: this is not a particularly useful config file +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +# patch the generated kubeadm config with some extra settings +kubeadmConfigPatches: +- | + apiVersion: kubelet.config.k8s.io/v1beta1 + kind: KubeletConfiguration + evictionHard: + nodefs.available: "0%" +# patch it further using a JSON 6902 patch +kubeadmConfigPatchesJSON6902: +- group: kubeadm.k8s.io + version: v1beta2 + kind: ClusterConfiguration + patch: | + - op: add + path: /apiServer/certSANs/- + value: my-hostname +# 1 control plane node +nodes: +# the control plane node config +- role: control-plane + image: kindest/node:v1.19.1 + diff --git a/config/operator/manager/manager.yaml b/test/e2e/skywalking-components.yaml similarity index 52% copy from config/operator/manager/manager.yaml copy to test/e2e/skywalking-components.yaml index 2eb0b50..45a435f 100644 --- a/config/operator/manager/manager.yaml +++ b/test/e2e/skywalking-components.yaml @@ -15,42 +15,33 @@ # specific language governing permissions and limitations # under the License. -apiVersion: v1 -kind: Namespace +apiVersion: operator.skywalking.apache.org/v1alpha1 +kind: OAPServer metadata: - labels: - control-plane: controller-manager - name: system + name: skywalking-system + namespace: skywalking-system +spec: + version: 8.8.1 + instances: 1 + image: apache/skywalking-oap-server:8.8.1 + service: + template: + type: ClusterIP + --- -apiVersion: apps/v1 -kind: Deployment +apiVersion: operator.skywalking.apache.org/v1alpha1 +kind: UI metadata: - name: controller-manager - namespace: system - labels: - control-plane: controller-manager + name: skywalking-system + namespace: skywalking-system spec: - selector: - matchLabels: - control-plane: controller-manager - replicas: 1 - template: - metadata: - labels: - control-plane: controller-manager - spec: - containers: - - command: - - /manager - args: - - --enable-leader-election - image: controller:latest - name: manager - resources: - limits: - cpu: 100m - memory: 30Mi - requests: - cpu: 100m - memory: 20Mi - terminationGracePeriodSeconds: 10 + version: 8.8.1 + instances: 1 + image: apache/skywalking-ui:8.8.1 + OAPServerAddress: http://skywalking-system-oap.skywalking-system:12800 + service: + template: + type: ClusterIP + ingress: + host: demo.ui.skywalking + \ No newline at end of file diff --git a/test/e2e/verify/endpoint.yaml b/test/e2e/verify/endpoint.yaml new file mode 100644 index 0000000..adc7517 --- /dev/null +++ b/test/e2e/verify/endpoint.yaml @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. + +{{- contains .}} +- id: {{ b64enc "Your_ApplicationName" }}.1_{{ b64enc "GET:/hello" }} + name: 'GET:/hello' +{{- end}} \ No newline at end of file diff --git a/test/e2e/verify/metrics.yaml b/test/e2e/verify/metrics.yaml new file mode 100644 index 0000000..fa76e89 --- /dev/null +++ b/test/e2e/verify/metrics.yaml @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. + +{{- contains . }} +- key: {{ notEmpty .key }} + value: {{ gt .value 0 }} +{{- end }} \ No newline at end of file diff --git a/config/operator/manager/manager.yaml b/test/e2e/verify/service.yaml similarity index 50% copy from config/operator/manager/manager.yaml copy to test/e2e/verify/service.yaml index 2eb0b50..92d9d73 100644 --- a/config/operator/manager/manager.yaml +++ b/test/e2e/verify/service.yaml @@ -15,42 +15,8 @@ # specific language governing permissions and limitations # under the License. -apiVersion: v1 -kind: Namespace -metadata: - labels: - control-plane: controller-manager - name: system ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: controller-manager - namespace: system - labels: - control-plane: controller-manager -spec: - selector: - matchLabels: - control-plane: controller-manager - replicas: 1 - template: - metadata: - labels: - control-plane: controller-manager - spec: - containers: - - command: - - /manager - args: - - --enable-leader-election - image: controller:latest - name: manager - resources: - limits: - cpu: 100m - memory: 30Mi - requests: - cpu: 100m - memory: 20Mi - terminationGracePeriodSeconds: 10 +{{- contains . }} +- id: {{ b64enc "Your_ApplicationName" }}.1 + name: Your_ApplicationName + group: "" +{{- end }} \ No newline at end of file