You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ho...@apache.org on 2022/04/20 09:04:18 UTC

[skywalking-kubernetes-event-exporter] branch add-e2e created (now cb9bf5f)

This is an automated email from the ASF dual-hosted git repository.

hoshea pushed a change to branch add-e2e
in repository https://gitbox.apache.org/repos/asf/skywalking-kubernetes-event-exporter.git


      at cb9bf5f  add e2e tests

This branch includes the following new commits:

     new cb9bf5f  add e2e tests

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[skywalking-kubernetes-event-exporter] 01/01: add e2e tests

Posted by ho...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hoshea pushed a commit to branch add-e2e
in repository https://gitbox.apache.org/repos/asf/skywalking-kubernetes-event-exporter.git

commit cb9bf5f618db36fd69f2b65d577234dd8cc7e083
Author: Hoshea <fg...@gmail.com>
AuthorDate: Wed Apr 20 17:03:58 2022 +0800

    add e2e tests
---
 .github/workflows/build-and-test.yaml              |  21 ++++-
 Makefile                                           |  17 ++++
 deployments/base/deployment.yaml                   |   2 +-
 .../deployment.yaml => test/config/config.yaml}    |  52 ++++-------
 .../deployment.yaml => test/kustomization.yaml}    |  52 ++++-------
 .../{base/deployment.yaml => test/namespace.yaml}  |  34 +------
 scripts/prepare-e2e.sh                             | 100 +++++++++++++++++++++
 test/e2e/e2e.yaml                                  |  59 ++++++++++++
 test/e2e/env                                       |   2 +
 test/e2e/expected/events.yaml                      |  42 +++++++++
 test/e2e/kind.yaml                                 |  21 +++++
 11 files changed, 301 insertions(+), 101 deletions(-)

diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml
index ac62b95..5bda351 100644
--- a/.github/workflows/build-and-test.yaml
+++ b/.github/workflows/build-and-test.yaml
@@ -20,6 +20,13 @@ name: Check
 
 on:
   pull_request:
+    paths-ignore:
+      - "**.md"
+      - "**.txt"
+
+concurrency:
+  group: sw-k8s-event-exporter-${{ github.event.pull_request.number || github.ref }}
+  cancel-in-progress: true
 
 jobs:
   build-and-test:
@@ -39,14 +46,22 @@ jobs:
         env:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 
-      - name: Test
+      - name: Lint
+        run: make lint
+
+      - name: Unit tests
         run: make test
 
       - name: Build
-        run: make
+        run: make build
 
       - name: Build Docker Image
-        run: make -C build/package/docker
+        run: VERSION=test HUB=apache make -C build/package/docker
+
+      - name: E2E tests
+        uses: apache/skywalking-infra-e2e@main
+        with:
+          e2e-file: $GITHUB_WORKSPACE/test/e2e/e2e.yaml
 
   gateway:
     name: Gateway
diff --git a/Makefile b/Makefile
index 73aa083..76859ce 100644
--- a/Makefile
+++ b/Makefile
@@ -18,6 +18,11 @@
 
 include scripts/base.mk
 
+E2E_CLI_VERSION=${E2E_CLI_VERSION:-'2a33478'}
+
+# Whether to skip docker build in E2E tests
+E2E_SKIP_BUILD ?= 0
+
 all: clean lint test build
 
 .PHONY: lint
@@ -88,3 +93,15 @@ release: verify release-src release-bin
 	shasum -a 512 $(RELEASE_SRC).tgz > $(RELEASE_SRC).tgz.sha512
 	gpg --batch --yes --armor --detach-sig $(RELEASE_BIN).tgz
 	shasum -a 512 $(RELEASE_BIN).tgz > $(RELEASE_BIN).tgz.sha512
+
+### Run E2E tests locally.
+.PHONY: e2e
+e2e: check-e2e-cli
+	ifeq ($(E2E_SKIP_BUILD), 0)
+		VERSION=test HUB=apache make -C build/package/docker build
+	endif
+	e2e run -c test/e2e/e2e.yaml
+
+.PHONY: check-e2e-cli
+check-e2e-cli:
+	e2e -h || go install github.com/apache/skywalking-infra-e2e/cmd/e2e@$(E2E_CLI_VERSION)
diff --git a/deployments/base/deployment.yaml b/deployments/base/deployment.yaml
index fab2b61..c8cf5f6 100644
--- a/deployments/base/deployment.yaml
+++ b/deployments/base/deployment.yaml
@@ -34,7 +34,7 @@ spec:
       containers:
         - name: skywalking-event-exporter
           image: skywalking-event-exporter
-          imagePullPolicy: Always
+          imagePullPolicy: IfNotPresent
           args:
             - start
             - -v=debug
diff --git a/deployments/base/deployment.yaml b/deployments/test/config/config.yaml
similarity index 50%
copy from deployments/base/deployment.yaml
copy to deployments/test/config/config.yaml
index fab2b61..183e644 100644
--- a/deployments/base/deployment.yaml
+++ b/deployments/test/config/config.yaml
@@ -17,36 +17,22 @@
 # under the License.
 #
 
----
-apiVersion: apps/v1
-kind: Deployment
-metadata:
-  name: skywalking-event-exporter
-spec:
-  replicas: 1
-  template:
-    metadata:
-      labels:
-        app: skywalking-event-exporter
-        version: v1
-    spec:
-      serviceAccountName: skywalking-event-exporter
-      containers:
-        - name: skywalking-event-exporter
-          image: skywalking-event-exporter
-          imagePullPolicy: Always
-          args:
-            - start
-            - -v=debug
-            - -c=/data/config.yaml
-          volumeMounts:
-            - mountPath: /data
-              name: config
-      volumes:
-        - name: config
-          configMap:
-            name: skywalking-event-exporter-cm
-  selector:
-    matchLabels:
-      app: skywalking-event-exporter
-      version: v1
+filters:
+  - namespace: test
+    exporters:
+      - skywalking
+
+exporters:
+  skywalking:
+    template:
+      source:
+        service: "{{ .Service.Name }}"
+        serviceInstance: "{{ .Pod.Name }}"
+        endpoint: ""
+      message: "{{ .Event.Message }}"
+    address: "skywalking-oap.skywalking:11800"
+    enableTLS: false
+    insecureSkipVerify: true
+    trustedCertPath: "/certs/ca.crt"
+    clientCertPath: "/certs/tls.crt"
+    clientKeyPath: "/certs/tls.key"
diff --git a/deployments/base/deployment.yaml b/deployments/test/kustomization.yaml
similarity index 50%
copy from deployments/base/deployment.yaml
copy to deployments/test/kustomization.yaml
index fab2b61..ca25a2d 100644
--- a/deployments/base/deployment.yaml
+++ b/deployments/test/kustomization.yaml
@@ -17,36 +17,22 @@
 # under the License.
 #
 
----
-apiVersion: apps/v1
-kind: Deployment
-metadata:
-  name: skywalking-event-exporter
-spec:
-  replicas: 1
-  template:
-    metadata:
-      labels:
-        app: skywalking-event-exporter
-        version: v1
-    spec:
-      serviceAccountName: skywalking-event-exporter
-      containers:
-        - name: skywalking-event-exporter
-          image: skywalking-event-exporter
-          imagePullPolicy: Always
-          args:
-            - start
-            - -v=debug
-            - -c=/data/config.yaml
-          volumeMounts:
-            - mountPath: /data
-              name: config
-      volumes:
-        - name: config
-          configMap:
-            name: skywalking-event-exporter-cm
-  selector:
-    matchLabels:
-      app: skywalking-event-exporter
-      version: v1
+apiVersion: kustomize.config.k8s.io/v1beta1
+kind: Kustomization
+resources:
+  - ../base
+  - ./namespace.yaml
+
+namespace: e2e-test
+
+configMapGenerator:
+  - files:
+      - config.yaml=config/config.yaml
+    name: skywalking-event-exporter-cm
+
+generatorOptions:
+  disableNameSuffixHash: true
+images:
+  - name: skywalking-event-exporter
+    newName: apache/skywalking-kubernetes-event-exporter
+    newTag: test
diff --git a/deployments/base/deployment.yaml b/deployments/test/namespace.yaml
similarity index 51%
copy from deployments/base/deployment.yaml
copy to deployments/test/namespace.yaml
index fab2b61..c33d14a 100644
--- a/deployments/base/deployment.yaml
+++ b/deployments/test/namespace.yaml
@@ -18,35 +18,7 @@
 #
 
 ---
-apiVersion: apps/v1
-kind: Deployment
+apiVersion: v1
+kind: Namespace
 metadata:
-  name: skywalking-event-exporter
-spec:
-  replicas: 1
-  template:
-    metadata:
-      labels:
-        app: skywalking-event-exporter
-        version: v1
-    spec:
-      serviceAccountName: skywalking-event-exporter
-      containers:
-        - name: skywalking-event-exporter
-          image: skywalking-event-exporter
-          imagePullPolicy: Always
-          args:
-            - start
-            - -v=debug
-            - -c=/data/config.yaml
-          volumeMounts:
-            - mountPath: /data
-              name: config
-      volumes:
-        - name: config
-          configMap:
-            name: skywalking-event-exporter-cm
-  selector:
-    matchLabels:
-      app: skywalking-event-exporter
-      version: v1
+  name: e2e-test
diff --git a/scripts/prepare-e2e.sh b/scripts/prepare-e2e.sh
new file mode 100755
index 0000000..e2454de
--- /dev/null
+++ b/scripts/prepare-e2e.sh
@@ -0,0 +1,100 @@
+#!/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)
+
+# prepare base dir
+TMP_DIR=/tmp/sw-event-exporter-e2e
+BIN_DIR=$TMP_DIR/bin
+mkdir -p $TMP_DIR $BIN_DIR && cd $TMP_DIR
+
+export PATH=$BIN_DIR:$PATH
+
+KUBECTL_VERSION=${KUBECTL_VERSION:-'v1.19.1'}
+SWCTL_VERSION=${SWCTL_VERSION:-'0.10.0'}
+HELM_VERSION=${HELM_VERSION:-'helm-v3.0.0'}
+
+prepare_ok=true
+
+function error_check() {
+    if [ $? -ne 0 ]; then
+        echo "[ERROR] Failed to install $1, please check"
+        prepare_ok=false
+    fi
+}
+
+function install_kubectl()
+{
+    if ! command -v kubectl &> /dev/null; then
+      echo "Installing kubectl"
+      mkdir -p $TMP_DIR/kubectl && cd $TMP_DIR/kubectl
+      curl -LO https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/${OS}/${ARCH}/kubectl && chmod +x ./kubectl && mv ./kubectl ${BIN_DIR}
+      error_check "kubectl"
+    fi
+}
+
+function install_swctl()
+{
+    if ! command -v swctl &> /dev/null; then
+      echo "Installing swctl"
+      mkdir -p $TMP_DIR/swctl && cd $TMP_DIR/swctl
+      curl -kLo skywalking-cli.tar.gz https://github.com/apache/skywalking-cli/archive/${SWCTL_VERSION}.tar.gz
+      tar -zxf skywalking-cli.tar.gz --strip=1
+      VERSION=${SWCTL_VERSION} make install DESTDIR=${BIN_DIR}
+      error_check "swctl"
+    fi
+}
+
+function install_yq()
+{
+    if ! command -v yq &> /dev/null; then
+      echo "Installing yq"
+      mkdir -p $TMP_DIR/yq && cd $TMP_DIR/yq
+      wget https://github.com/mikefarah/yq/releases/download/v4.11.1/yq_${OS}_${ARCH}.tar.gz -O - |\
+      tar xz && mv yq_${OS}_${ARCH} ${BIN_DIR}/yq
+      error_check "yq"
+    fi
+}
+
+function install_helm() {
+  if ! command -v helm &> /dev/null; then
+    echo "Installing helm"
+    mkdir -p $TMP_DIR/helm && cd $TMP_DIR/helm
+    curl -sSL https://get.helm.sh/${HELM_VERSION}-${OS}-${ARCH}.tar.gz | tar xz -C $BIN_DIR --strip-components=1 ${OS}-${ARCH}/helm
+    mv ${OS}-${ARCH}/helm ${BIN_DIR}/helm
+    error_check "helm"
+  fi
+}
+
+function install_all()
+{
+    install_kubectl
+    install_swctl
+    install_yq
+    install_helm
+
+    if [ "$prepare_ok" = false ]; then
+        echo "Install e2e dependencies failed"
+        exit 1
+    else
+        echo "Install e2e dependencies successfully"
+        exit 0
+    fi
+}
+
+install_all
diff --git a/test/e2e/e2e.yaml b/test/e2e/e2e.yaml
new file mode 100644
index 0000000..212c339
--- /dev/null
+++ b/test/e2e/e2e.yaml
@@ -0,0 +1,59 @@
+# 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
+  init-system-environment: ./env
+  kind:
+    import-images:
+      - apache/skywalking-kubernetes-event-exporter:test
+    expose-ports:
+      - namespace: skywalking
+        resource: service/skywalking-oap
+        port: 12800
+  steps:
+    - name: Install tools
+      command: bash scripts/prepare-e2e.sh
+    - name: Deploy SkyWalking OAP and UI
+      command: |
+        helm repo add skywalking https://apache.jfrog.io/artifactory/skywalking-helm
+        helm install --create-namespace skywalking skywalking/skywalking -n skywalking \
+          --set oap.replicas=1 \
+          --set oap.storageType=h2 \
+          --set oap.image.tag=$OAP_IMAGE_TAG \
+          --set ui.image.tag=$UI_IMAGE_TAG \
+          --set elasticsearch.enabled=false \
+          --set oap.env.JAVA_OPTS='-Dmode='
+      wait:
+        - namespace: skywalking
+          resource: pod
+          for: condition=Ready
+    - name: Deploy k8s event exporter
+      command: kubectl apply -k deployments/test
+      wait:
+        - namespace: e2e-test
+          resource: pod
+          for: condition=Ready
+  timeout: 10m
+
+verify:
+  retry:
+    count: 10
+    interval: 5s
+  cases:
+#    - query: /Users/hoshea/swctl --display yaml --base-url=http://localhost:12800/graphql event ls
+    - query: swctl --display yaml --base-url=http://${service_skywalking_oap_host}:${service_skywalking_oap_12800}/graphql event ls
+      expected: expected/events.yaml
diff --git a/test/e2e/env b/test/e2e/env
new file mode 100644
index 0000000..3d952dc
--- /dev/null
+++ b/test/e2e/env
@@ -0,0 +1,2 @@
+OAP_IMAGE_TAG=9.0.0
+UI_IMAGE_TAG=9.0.0
diff --git a/test/e2e/expected/events.yaml b/test/e2e/expected/events.yaml
new file mode 100644
index 0000000..b7ea899
--- /dev/null
+++ b/test/e2e/expected/events.yaml
@@ -0,0 +1,42 @@
+# 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.
+
+events:
+  {{- contains .events }}
+  - uuid: {{ notEmpty .uuid }}
+    source:
+      service: ""
+      serviceinstance: ""
+      endpoint: ""
+    name: Started
+    type: Normal
+    message: Started container skywalking-event-exporter
+    parameters: []
+    starttime: {{ gt .starttime 0 }}
+    endtime: {{ gt .endtime 0 }}
+  - uuid: {{ notEmpty .uuid }}
+    source:
+      service: ""
+      serviceinstance: ""
+      endpoint: ""
+    name: Created
+    type: Normal
+    message: Created container skywalking-event-exporter
+    parameters: []
+    starttime: {{ gt .starttime 0 }}
+    endtime: {{ gt .endtime 0 }}
+  {{- end }}
+total: {{ ge .total 2 }}
+
diff --git a/test/e2e/kind.yaml b/test/e2e/kind.yaml
new file mode 100644
index 0000000..a04057c
--- /dev/null
+++ b/test/e2e/kind.yaml
@@ -0,0 +1,21 @@
+# 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.
+
+kind: Cluster
+apiVersion: kind.x-k8s.io/v1alpha4
+nodes:
+  - role: control-plane
+  - role: worker
+  - role: worker