You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2021/04/01 05:14:39 UTC

[skywalking-kubernetes-event-exporter] branch main updated: chore: set up CI workflow (#1)

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

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


The following commit(s) were added to refs/heads/main by this push:
     new 2f09a4e  chore: set up CI workflow (#1)
2f09a4e is described below

commit 2f09a4ee76dc747f8d22c050c2979cbe5cdf45d8
Author: Zhenxu Ke <ke...@apache.org>
AuthorDate: Thu Apr 1 13:14:33 2021 +0800

    chore: set up CI workflow (#1)
---
 .github/workflows/build-and-test.yaml | 54 +++++++++++++++++++
 .gitignore                            |  3 +-
 .gitmodules                           |  3 --
 .golangci.yml                         | 97 +++++++++++++++++++++++++++++++++++
 .licenserc.yaml                       | 35 +++++++++++++
 Makefile                              | 28 +++++-----
 api                                   |  1 -
 assets/assets.go                      |  6 ++-
 cmd/root.go                           |  5 +-
 cmd/start.go                          |  5 +-
 configs/config.go                     |  3 +-
 go.mod                                |  6 +--
 go.sum                                | 10 ++--
 pkg/exporter/exporter.go              |  3 +-
 pkg/exporter/skywalking.go            |  8 +--
 pkg/k8s/client.go                     |  6 +--
 pkg/pipe/pipe.go                      |  3 +-
 17 files changed, 236 insertions(+), 40 deletions(-)

diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml
new file mode 100644
index 0000000..fb60450
--- /dev/null
+++ b/.github/workflows/build-and-test.yaml
@@ -0,0 +1,54 @@
+# Licensed to 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. Apache Software Foundation (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.
+#
+
+name: Check
+
+on:
+  pull_request:
+
+jobs:
+  build-and-test:
+    name: Build and Test
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          submodules: true
+
+      - uses: actions/setup-go@v2
+        with:
+          go-version: 1.16
+
+      - name: Check License
+        uses: apache/skywalking-eyes@main
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+
+      - name: Test
+        run: make test
+
+      - name: Build
+        run: make build
+
+  gateway:
+    name: Gateway
+    runs-on: ubuntu-latest
+    steps:
+      - run: echo "Just to make the check statuses passed"
+    needs:
+      - build-and-test
diff --git a/.gitignore b/.gitignore
index efbd7bb..f005814 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,8 +1,9 @@
-.*
 .idea
 coverage.txt
 bin
 
+.DS_Store
+
 # Binaries for programs and plugins
 *.exe
 *.exe~
diff --git a/.gitmodules b/.gitmodules
deleted file mode 100644
index fc7e37b..0000000
--- a/.gitmodules
+++ /dev/null
@@ -1,3 +0,0 @@
-[submodule "api"]
-	path = api
-	url = http://github.com/apache/skywalking-data-collect-protocol/
diff --git a/.golangci.yml b/.golangci.yml
new file mode 100644
index 0000000..0cae5fd
--- /dev/null
+++ b/.golangci.yml
@@ -0,0 +1,97 @@
+# 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.
+
+run:
+  skip-files:
+    - ".*\\.pb\\.go"
+    - ".*\\.gen\\.go"
+
+linters-settings:
+  govet:
+    check-shadowing: true
+  golint:
+    min-confidence: 0
+  gocyclo:
+    min-complexity: 20
+  maligned:
+    suggest-new: true
+  dupl:
+    threshold: 200
+  goconst:
+    min-len: 2
+    min-occurrences: 2
+  depguard:
+    list-type: blacklist
+    include-go-root: true
+    packages-with-error-messages:
+      fmt: "logging is allowed only by logutils.Log"
+  misspell:
+    locale: US
+  lll:
+    line-length: 150
+  goimports:
+    local-prefixes: github.com/apache/skywalking-kubernetes-event-exporter
+  gocritic:
+    enabled-tags:
+      - diagnostic
+      - experimental
+      - opinionated
+      - performance
+      - style
+    disabled-checks:
+      - ifElseChain
+  funlen:
+    lines: 100
+    statements: 50
+  whitespace:
+    multi-if: false
+    multi-func: false
+
+linters:
+  enable:
+    - bodyclose
+    - deadcode
+    - depguard
+    - dogsled
+    - dupl
+    - errcheck
+    - funlen
+    - goconst
+    - gocritic
+    - gocyclo
+    - gofmt
+    - goimports
+    - golint
+    - gosec
+    - gosimple
+    - govet
+    - ineffassign
+    - interfacer
+    - lll
+    - misspell
+    - nakedret
+    - staticcheck
+    - structcheck
+    - stylecheck
+    - typecheck
+    - unconvert
+    - unparam
+    - unused
+    - varcheck
+    - whitespace
+
+service:
+  golangci-lint-version: 1.20.x
diff --git a/.licenserc.yaml b/.licenserc.yaml
new file mode 100644
index 0000000..5534f3c
--- /dev/null
+++ b/.licenserc.yaml
@@ -0,0 +1,35 @@
+#
+# 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.
+#
+header:
+  license:
+    spdx-id: Apache-2.0
+    copyright-owner: Apache Software Foundation
+
+  paths-ignore:
+    - 'dist'
+    - 'licenses'
+    - '**/*.md'
+    - 'LICENSE'
+    - 'NOTICE'
+    - '.gitignore'
+    - 'go.mod'
+    - 'go.sum'
+    - 'api/**'
+
+  comment: on-failure
diff --git a/Makefile b/Makefile
index 3fe6c6a..c2a1f4a 100644
--- a/Makefile
+++ b/Makefile
@@ -16,6 +16,9 @@
 # under the License.
 #
 
+export PATH := $(PATH):$(HOME)/usr/local/bin
+export GO111MODULE := on
+
 APP = skywalking-kubernetes-event-exporter
 VERSION ?= latest
 OUT_DIR = bin
@@ -36,30 +39,31 @@ ARCH = amd64
 RELEASE_BIN = $(APP)-$(VERSION)-bin
 RELEASE_SRC = $(APP)-$(VERSION)-src
 
-all: clean lint license test build
-
-.PHONY: codegen
-codegen:
-	protoc -I=api --go_out=api --go-grpc_out=api api/event/Event.proto api/common/*.proto
-	cd api/skywalking/network && (rm go.mod || true) && go mod init skywalking/network && go mod tidy
+all: clean lint test build
 
 .PHONY: lint
 lint:
 	$(GO_LINT) version || curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GO_PATH)/bin
-	$(GO_LINT) run -v ./...
+	$(GO_LINT) run -v --timeout 5m ./...
 
 .PHONY: fix-lint
 fix-lint:
 	$(GO_LINT) run -v --fix ./...
 
-.PHONY: license
-license: clean
-	echo "TODO"
+.PHONY: check
+check: clean
+	$(GO) mod tidy > /dev/null
+	@if [ ! -z "`git status -s`" ]; then \
+		echo "Following files are not consistent with CI:"; \
+		git status -s; \
+		git diff; \
+		exit 1; \
+	fi
 
 .PHONY: test
 test: clean
 	$(GO_TEST) ./... -coverprofile=coverage.txt -covermode=atomic
-	@>&2 echo "Great, all tests passed."
+	@>&2 echo "Great, all tests passed!!"
 
 .PHONY: $(PLATFORMS)
 $(PLATFORMS):
@@ -75,6 +79,7 @@ docker:
 
 .PHONY: clean
 clean:
+	-rm -rf api/skywalking
 	-rm -rf bin
 	-rm -rf coverage.txt
 	-rm -rf "$(RELEASE_BIN)"*
@@ -91,7 +96,6 @@ release-src: clean
 	--exclude .DS_Store \
 	--exclude .github \
 	--exclude $(RELEASE_SRC).tgz \
-	--exclude query-protocol/schema.graphqls \
 	.
 
 release-bin: build
diff --git a/api b/api
deleted file mode 160000
index c01af3b..0000000
--- a/api
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit c01af3b883217939e374d2245eac92036fb7394a
diff --git a/assets/assets.go b/assets/assets.go
index 8cd1c3f..3e23a10 100644
--- a/assets/assets.go
+++ b/assets/assets.go
@@ -19,7 +19,11 @@
 
 package assets
 
-import _ "embed"
+import (
+	//nolint // no other possibility
+	_ "embed"
+)
 
+// DefaultConfig is the default configurations of the exporter.
 //go:embed default-config.yaml
 var DefaultConfig []byte
diff --git a/cmd/root.go b/cmd/root.go
index bcf0bc9..94349b0 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -22,11 +22,12 @@ package main
 import (
 	"io/ioutil"
 
+	"github.com/sirupsen/logrus"
+	"github.com/spf13/cobra"
+
 	"github.com/apache/skywalking-kubernetes-event-exporter/assets"
 	"github.com/apache/skywalking-kubernetes-event-exporter/configs"
 	"github.com/apache/skywalking-kubernetes-event-exporter/internal/pkg/logger"
-	"github.com/sirupsen/logrus"
-	"github.com/spf13/cobra"
 )
 
 var (
diff --git a/cmd/start.go b/cmd/start.go
index bd9a7ac..b9a54c6 100644
--- a/cmd/start.go
+++ b/cmd/start.go
@@ -24,10 +24,11 @@ import (
 	"os/signal"
 	"syscall"
 
-	"github.com/apache/skywalking-kubernetes-event-exporter/pkg/k8s"
-	"github.com/apache/skywalking-kubernetes-event-exporter/pkg/pipe"
 	"github.com/spf13/cobra"
 	_ "k8s.io/client-go/plugin/pkg/client/auth"
+
+	"github.com/apache/skywalking-kubernetes-event-exporter/pkg/k8s"
+	"github.com/apache/skywalking-kubernetes-event-exporter/pkg/pipe"
 )
 
 func init() {
diff --git a/configs/config.go b/configs/config.go
index fca06a8..1a93b2a 100644
--- a/configs/config.go
+++ b/configs/config.go
@@ -20,9 +20,10 @@
 package configs
 
 import (
-	evnt "github.com/apache/skywalking-kubernetes-event-exporter/pkg/event"
 	"gopkg.in/yaml.v3"
 	v1 "k8s.io/api/core/v1"
+
+	evnt "github.com/apache/skywalking-kubernetes-event-exporter/pkg/event"
 )
 
 type FilterConfig struct {
diff --git a/go.mod b/go.mod
index 58e9e0a..579b967 100644
--- a/go.mod
+++ b/go.mod
@@ -5,11 +5,9 @@ go 1.16
 require (
 	github.com/sirupsen/logrus v1.8.1
 	github.com/spf13/cobra v1.1.3
-	google.golang.org/grpc v1.36.0
+	google.golang.org/grpc v1.36.1
 	gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
 	k8s.io/api v0.20.5
 	k8s.io/client-go v0.20.5
-	skywalking/network v0.0.0-00010101000000-000000000000
+	skywalking.apache.org/repo/goapi v0.0.0-20210401043526-44170b5d980b
 )
-
-replace skywalking/network => ./api/skywalking/network
diff --git a/go.sum b/go.sum
index 39f5f04..fe544d9 100644
--- a/go.sum
+++ b/go.sum
@@ -88,7 +88,6 @@ github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoD
 github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
 github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
 github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
-github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
 github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
 github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
 github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
@@ -135,9 +134,8 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq
 github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
 github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
 github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
+github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4=
 github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
-github.com/golang/protobuf v1.5.1 h1:jAbXjIeW2ZSW2AwFxlGTDoc2CjI2XujLkV3ArsZFCvc=
-github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM=
 github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
 github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
 github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
@@ -516,8 +514,8 @@ google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQ
 google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
 google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
 google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
-google.golang.org/grpc v1.36.0 h1:o1bcQ6imQMIOpdrO3SWf2z5RV72WbDwdXuK0MDlc8As=
-google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
+google.golang.org/grpc v1.36.1 h1:cmUfbeGKnz9+2DD/UYsMQXeqbHZqZDs4eQwW0sFOpBY=
+google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
 google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
 google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
 google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
@@ -579,3 +577,5 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
 sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
 sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
 sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
+skywalking.apache.org/repo/goapi v0.0.0-20210401043526-44170b5d980b h1:YyVqVMDrwRZ8nQBmPBuBZ/slkQ91JN8rIp9+TZSIkOQ=
+skywalking.apache.org/repo/goapi v0.0.0-20210401043526-44170b5d980b/go.mod h1:Hb/huQB2/8vgky7w7IcLUfdoiAUS+BERl4afcDL0vvA=
diff --git a/pkg/exporter/exporter.go b/pkg/exporter/exporter.go
index 53cbcdf..a3f2284 100644
--- a/pkg/exporter/exporter.go
+++ b/pkg/exporter/exporter.go
@@ -20,9 +20,10 @@
 package exporter
 
 import (
+	v1 "k8s.io/api/core/v1"
+
 	"github.com/apache/skywalking-kubernetes-event-exporter/internal/pkg/logger"
 	"github.com/apache/skywalking-kubernetes-event-exporter/pkg/event"
-	v1 "k8s.io/api/core/v1"
 )
 
 type Exporter interface {
diff --git a/pkg/exporter/skywalking.go b/pkg/exporter/skywalking.go
index 3b557fc..75cabab 100644
--- a/pkg/exporter/skywalking.go
+++ b/pkg/exporter/skywalking.go
@@ -25,14 +25,16 @@ import (
 	"encoding/json"
 	"fmt"
 	"html/template"
-	sw "skywalking/network/event/v3"
 	"time"
 
+	sw "skywalking.apache.org/repo/goapi/collect/event/v3"
+
+	"google.golang.org/grpc"
+	k8score "k8s.io/api/core/v1"
+
 	"github.com/apache/skywalking-kubernetes-event-exporter/configs"
 	"github.com/apache/skywalking-kubernetes-event-exporter/internal/pkg/logger"
 	"github.com/apache/skywalking-kubernetes-event-exporter/pkg/event"
-	"google.golang.org/grpc"
-	k8score "k8s.io/api/core/v1"
 )
 
 type SkyWalking struct {
diff --git a/pkg/k8s/client.go b/pkg/k8s/client.go
index c80ed9a..118f0b0 100644
--- a/pkg/k8s/client.go
+++ b/pkg/k8s/client.go
@@ -29,11 +29,11 @@ import (
 )
 
 func GetClient() (*kubernetes.Clientset, error) {
-	if config, err := GetConfig(); err != nil {
+	config, err := GetConfig()
+	if err != nil {
 		return nil, err
-	} else {
-		return kubernetes.NewForConfig(config)
 	}
+	return kubernetes.NewForConfig(config)
 }
 
 // GetConfig returns the configuration to connect to the Kubernetes API server.
diff --git a/pkg/pipe/pipe.go b/pkg/pipe/pipe.go
index 5b15565..8ff7d02 100644
--- a/pkg/pipe/pipe.go
+++ b/pkg/pipe/pipe.go
@@ -22,12 +22,13 @@ package pipe
 import (
 	"fmt"
 
+	v1 "k8s.io/api/core/v1"
+
 	"github.com/apache/skywalking-kubernetes-event-exporter/configs"
 	"github.com/apache/skywalking-kubernetes-event-exporter/internal/pkg/logger"
 	"github.com/apache/skywalking-kubernetes-event-exporter/pkg/event"
 	exp "github.com/apache/skywalking-kubernetes-event-exporter/pkg/exporter"
 	"github.com/apache/skywalking-kubernetes-event-exporter/pkg/k8s"
-	v1 "k8s.io/api/core/v1"
 )
 
 type workflow struct {