This is an automated email from the ASF dual-hosted git repository.
membphis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-ingress-controller.git
The following commit(s) were added to refs/heads/master by this push:
new d43c510 ci: add lint-checker-ci, `gofmt` (#93)
d43c510 is described below
commit d43c510357c804b93cc057cd13114dcfb595c245
Author: Alex Zhang <[email protected]>
AuthorDate: Mon Dec 14 17:42:33 2020 +0800
ci: add lint-checker-ci, `gofmt` (#93)
---
.github/workflows/lint-checker.yml | 28 ++++++++++++
Makefile | 4 ++
conf/errno.go | 36 ++++++++--------
conf/init.go | 81 +++++++++++++++++------------------
log/log.go | 4 +-
main.go | 6 +--
pkg/ingress/apisix/annotation.go | 4 +-
pkg/ingress/apisix/plugin.go | 12 +++---
pkg/ingress/apisix/route.go | 2 +-
pkg/ingress/apisix/service.go | 2 +-
pkg/ingress/apisix/upstream.go | 6 +--
pkg/ingress/controller/controller.go | 12 +++---
pkg/ingress/controller/endpoint.go | 2 +-
pkg/ingress/controller/store/store.go | 1 -
pkg/ingress/controller/watch.go | 42 +++++++++---------
pkg/route.go | 18 ++++----
16 files changed, 145 insertions(+), 115 deletions(-)
diff --git a/.github/workflows/lint-checker.yml
b/.github/workflows/lint-checker.yml
new file mode 100644
index 0000000..c03cc19
--- /dev/null
+++ b/.github/workflows/lint-checker.yml
@@ -0,0 +1,28 @@
+name: lint-checker-ci
+
+on:
+ push:
+ branches:
+ - master
+ - chore/gofmt
+ pull_request:
+ branches:
+ - master
+jobs:
+ run-test:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - name: setup go
+ uses: actions/setup-go@v1
+ with:
+ go-version: '1.13'
+ - name: run gofmt
+ working-directory: ./
+ run: |
+ diffs=`gofmt -l .`
+ if [[ -n $diffs ]]; then
+ echo "Files are not formatted by gofmt:"
+ echo $diffs
+ exit 1
+ fi
diff --git a/Makefile b/Makefile
index 8df39d0..b1d54e1 100644
--- a/Makefile
+++ b/Makefile
@@ -40,6 +40,10 @@ build:
lint:
golangci-lint run
+### gofmt: Format all go codes
+gofmt:
+ find . -type f -name "*.go" | xargs gofmt -w -s
+
### unit-test: Run unit test cases
unit-test:
go test -cover -coverprofile=coverage.txt ./...
diff --git a/conf/errno.go b/conf/errno.go
index 2a01cef..92f2bdb 100644
--- a/conf/errno.go
+++ b/conf/errno.go
@@ -1,17 +1,17 @@
- // 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.
+// 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.
package conf
import "fmt"
@@ -29,10 +29,10 @@ var (
//BB 01表示更新失败
UpdateUpstreamNodesError = Message{"010101", "服务%s节点更新失败"}
AddUpstreamError = Message{"010102", "增加upstream %s失败"}
- AddUpstreamJsonError = Message{"010103", "upstream %s json
trans error"}
+ AddUpstreamJsonError = Message{"010103", "upstream %s json trans
error"}
)
-func (m Message) ToString(params ...interface{}) string{
+func (m Message) ToString(params ...interface{}) string {
params = append(params, m.Code)
- return fmt.Sprintf(m.Msg + " error_code:%s", params...)
-}
\ No newline at end of file
+ return fmt.Sprintf(m.Msg+" error_code:%s", params...)
+}
diff --git a/conf/init.go b/conf/init.go
index b088872..6105b48 100644
--- a/conf/init.go
+++ b/conf/init.go
@@ -1,52 +1,53 @@
- // 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.
+// 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.
package conf
import (
- coreinformers "k8s.io/client-go/informers/core/v1"
- restclient "k8s.io/client-go/rest"
+ "fmt"
clientSet
"github.com/gxthrj/apisix-ingress-types/pkg/client/clientset/versioned"
seven "github.com/gxthrj/seven/conf"
- "k8s.io/client-go/tools/clientcmd"
- "k8s.io/client-go/kubernetes"
+ "github.com/tidwall/gjson"
+ "io/ioutil"
"k8s.io/client-go/informers"
+ coreinformers "k8s.io/client-go/informers/core/v1"
+ "k8s.io/client-go/kubernetes"
+ restclient "k8s.io/client-go/rest"
+ "k8s.io/client-go/tools/clientcmd"
"os"
"path/filepath"
- "io/ioutil"
- "fmt"
- "github.com/tidwall/gjson"
"runtime"
)
var (
- ENV string
- basePath string
- ADMIN_URL = os.Getenv("APISIX_ADMIN_INTERNAL")
- HOSTNAME = os.Getenv("HOSTNAME")
- LOCAL_ADMIN_URL = ""
- podInformer coreinformers.PodInformer
- svcInformer coreinformers.ServiceInformer
- nsInformer coreinformers.NamespaceInformer
+ ENV string
+ basePath string
+ ADMIN_URL = os.Getenv("APISIX_ADMIN_INTERNAL")
+ HOSTNAME = os.Getenv("HOSTNAME")
+ LOCAL_ADMIN_URL = ""
+ podInformer coreinformers.PodInformer
+ svcInformer coreinformers.ServiceInformer
+ nsInformer coreinformers.NamespaceInformer
EndpointsInformer coreinformers.EndpointsInformer
- IsLeader = false
+ IsLeader = false
//etcdClient client.Client
- kubeClient kubernetes.Interface
+ kubeClient kubernetes.Interface
CoreSharedInformerFactory informers.SharedInformerFactory
injectedConfPath string
)
+
const PROD = "prod"
const HBPROD = "hb-prod"
const BETA = "beta"
@@ -130,8 +131,7 @@ type syslog struct {
// return client.NewKeysAPI(etcdClient)
//}
-
-func GetURL() string{
+func GetURL() string {
if ADMIN_URL != "" {
return ADMIN_URL
} else {
@@ -139,19 +139,19 @@ func GetURL() string{
}
}
-func GetPodInformer() coreinformers.PodInformer{
+func GetPodInformer() coreinformers.PodInformer {
return podInformer
}
-func GetSvcInformer() coreinformers.ServiceInformer{
+func GetSvcInformer() coreinformers.ServiceInformer {
return svcInformer
}
-func GetNsInformer() coreinformers.NamespaceInformer{
+func GetNsInformer() coreinformers.NamespaceInformer {
return nsInformer
}
-func GetKubeClient() kubernetes.Interface{
+func GetKubeClient() kubernetes.Interface {
return kubeClient
}
@@ -173,8 +173,8 @@ func InitKubeClient() kubernetes.Interface {
return k8sClient
}
-func InitApisixClient() clientSet.Interface{
- apisixRouteClientset, err:= clientSet.NewForConfig(config)
+func InitApisixClient() clientSet.Interface {
+ apisixRouteClientset, err := clientSet.NewForConfig(config)
ExceptNilErr(err)
return apisixRouteClientset
}
@@ -210,7 +210,7 @@ func InitInformer() {
//return podInformer, svcInformer, nsInformer
}
-func ExceptNilErr(err error) {
+func ExceptNilErr(err error) {
if err != nil {
panic(err)
}
@@ -260,4 +260,3 @@ func ExceptNilErr(err error) {
//type LevelSpec struct {
// Pod []string `json:"pod"`
//}
-
diff --git a/log/log.go b/log/log.go
index 2ac2801..d4a9e57 100644
--- a/log/log.go
+++ b/log/log.go
@@ -17,12 +17,12 @@ package log
import (
"bufio"
"fmt"
+ "github.com/api7/ingress-controller/conf"
"github.com/sirupsen/logrus"
"log/syslog"
"os"
"runtime"
"strings"
- "github.com/api7/ingress-controller/conf"
)
var logEntry *logrus.Entry
@@ -122,7 +122,7 @@ func (hook *SysLogHook) Fire(entry *logrus.Entry) error {
}
func localPrint(line string) {
- if conf.ENV != conf.BETA && conf.ENV != conf.PROD && conf.ENV !=
conf.HBPROD{
+ if conf.ENV != conf.BETA && conf.ENV != conf.PROD && conf.ENV !=
conf.HBPROD {
fmt.Print(line)
}
}
diff --git a/main.go b/main.go
index 2ab11ec..1633471 100644
--- a/main.go
+++ b/main.go
@@ -14,9 +14,9 @@
// limitations under the License.
package main
- import (
- "fmt"
- "os"
+import (
+ "fmt"
+ "os"
"github.com/api7/ingress-controller/cmd"
"github.com/api7/ingress-controller/conf"
diff --git a/pkg/ingress/apisix/annotation.go b/pkg/ingress/apisix/annotation.go
index c6c434f..cead443 100644
--- a/pkg/ingress/apisix/annotation.go
+++ b/pkg/ingress/apisix/annotation.go
@@ -15,13 +15,13 @@
package apisix
import (
- "strconv"
apisix "github.com/gxthrj/apisix-types/pkg/apis/apisix/v1"
seven "github.com/gxthrj/seven/apisix"
+ "strconv"
)
// BuildAnnotation return plugins and group
-func BuildAnnotation(annotations map[string]string) (apisix.Plugins, string){
+func BuildAnnotation(annotations map[string]string) (apisix.Plugins, string) {
plugins := make(apisix.Plugins)
cors := &CorsYaml{}
// ingress.class
diff --git a/pkg/ingress/apisix/plugin.go b/pkg/ingress/apisix/plugin.go
index ce4220c..4feb097 100644
--- a/pkg/ingress/apisix/plugin.go
+++ b/pkg/ingress/apisix/plugin.go
@@ -15,8 +15,8 @@
package apisix
import (
- "strconv"
"github.com/gxthrj/seven/apisix"
+ "strconv"
)
type CorsYaml struct {
@@ -26,7 +26,7 @@ type CorsYaml struct {
AllowMethods string `json:"allow_methods,omitempty"`
}
-func (c *CorsYaml) SetEnable(enable string){
+func (c *CorsYaml) SetEnable(enable string) {
if b, err := strconv.ParseBool(enable); err != nil {
c.Enable = false
} else {
@@ -34,18 +34,18 @@ func (c *CorsYaml) SetEnable(enable string){
}
}
-func (c *CorsYaml) SetOrigin(origin string){
+func (c *CorsYaml) SetOrigin(origin string) {
c.AllowOrigin = origin
}
-func (c *CorsYaml) SetHeaders(headers string){
+func (c *CorsYaml) SetHeaders(headers string) {
c.AllowHeaders = headers
}
-func (c *CorsYaml) SetMethods(methods string){
+func (c *CorsYaml) SetMethods(methods string) {
c.AllowMethods = methods
}
-func (c *CorsYaml) Build() *apisix.Cors{
+func (c *CorsYaml) Build() *apisix.Cors {
maxAge := int64(3600)
return apisix.BuildCors(c.Enable, &c.AllowOrigin, &c.AllowHeaders,
&c.AllowMethods, &maxAge)
}
diff --git a/pkg/ingress/apisix/route.go b/pkg/ingress/apisix/route.go
index 15f9ab2..fe4d0aa 100644
--- a/pkg/ingress/apisix/route.go
+++ b/pkg/ingress/apisix/route.go
@@ -15,10 +15,10 @@
package apisix
import (
+ "github.com/api7/ingress-controller/pkg/ingress/endpoint"
ingress "github.com/gxthrj/apisix-ingress-types/pkg/apis/config/v1"
apisix "github.com/gxthrj/apisix-types/pkg/apis/apisix/v1"
"github.com/gxthrj/seven/conf"
- "github.com/api7/ingress-controller/pkg/ingress/endpoint"
"strconv"
)
diff --git a/pkg/ingress/apisix/service.go b/pkg/ingress/apisix/service.go
index 389f131..b3e00b9 100644
--- a/pkg/ingress/apisix/service.go
+++ b/pkg/ingress/apisix/service.go
@@ -15,10 +15,10 @@
package apisix
import (
+ "github.com/api7/ingress-controller/pkg/ingress/endpoint"
ingress "github.com/gxthrj/apisix-ingress-types/pkg/apis/config/v1"
apisix "github.com/gxthrj/apisix-types/pkg/apis/apisix/v1"
"github.com/gxthrj/seven/conf"
- "github.com/api7/ingress-controller/pkg/ingress/endpoint"
"strconv"
)
diff --git a/pkg/ingress/apisix/upstream.go b/pkg/ingress/apisix/upstream.go
index cd39452..c5c08e6 100644
--- a/pkg/ingress/apisix/upstream.go
+++ b/pkg/ingress/apisix/upstream.go
@@ -15,10 +15,10 @@
package apisix
import (
+ "github.com/api7/ingress-controller/pkg/ingress/endpoint"
ingress "github.com/gxthrj/apisix-ingress-types/pkg/apis/config/v1"
apisix "github.com/gxthrj/apisix-types/pkg/apis/apisix/v1"
"github.com/gxthrj/seven/conf"
- "github.com/api7/ingress-controller/pkg/ingress/endpoint"
"strconv"
)
@@ -30,9 +30,9 @@ const (
//type ApisixUpstreamCRD ingress.ApisixUpstream
-type ApisixUpstreamBuilder struct{
+type ApisixUpstreamBuilder struct {
CRD *ingress.ApisixUpstream
- Ep endpoint.Endpoint
+ Ep endpoint.Endpoint
}
// Convert convert to apisix.Route from ingress.ApisixRoute CRD
diff --git a/pkg/ingress/controller/controller.go
b/pkg/ingress/controller/controller.go
index af9a1d9..ecaee5e 100644
--- a/pkg/ingress/controller/controller.go
+++ b/pkg/ingress/controller/controller.go
@@ -15,12 +15,12 @@
package controller
import (
+ "github.com/api7/ingress-controller/log"
"github.com/golang/glog"
clientSet
"github.com/gxthrj/apisix-ingress-types/pkg/client/clientset/versioned"
"github.com/gxthrj/apisix-ingress-types/pkg/client/informers/externalversions"
- "github.com/api7/ingress-controller/log"
- "k8s.io/client-go/kubernetes"
"k8s.io/client-go/informers"
+ "k8s.io/client-go/kubernetes"
)
var logger = log.GetLogger()
@@ -33,11 +33,11 @@ func recoverException() {
}
type Api6Controller struct {
- KubeClientSet kubernetes.Interface
- Api6ClientSet clientSet.Interface
- SharedInformerFactory externalversions.SharedInformerFactory
+ KubeClientSet kubernetes.Interface
+ Api6ClientSet clientSet.Interface
+ SharedInformerFactory externalversions.SharedInformerFactory
CoreSharedInformerFactory informers.SharedInformerFactory
- Stop chan struct{}
+ Stop chan struct{}
}
func (api6 *Api6Controller) ApisixRoute() {
diff --git a/pkg/ingress/controller/endpoint.go
b/pkg/ingress/controller/endpoint.go
index ff96da2..07de1eb 100644
--- a/pkg/ingress/controller/endpoint.go
+++ b/pkg/ingress/controller/endpoint.go
@@ -142,7 +142,7 @@ func (c *EndpointController) process(ep *CoreV1.Endpoints) {
// default
syncWithGroup("", upstreamName, ips, port)
// sync with all apisix group
- for g, _ := range sevenConf.UrlGroup {
+ for g := range sevenConf.UrlGroup {
syncWithGroup(g, upstreamName, ips,
port)
//upstreams, err :=
apisix.ListUpstream(k)
//if err == nil {
diff --git a/pkg/ingress/controller/store/store.go
b/pkg/ingress/controller/store/store.go
index 918157a..6d7a394 100644
--- a/pkg/ingress/controller/store/store.go
+++ b/pkg/ingress/controller/store/store.go
@@ -13,4 +13,3 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package store
-
diff --git a/pkg/ingress/controller/watch.go b/pkg/ingress/controller/watch.go
index b4ebc41..e4ea9f4 100644
--- a/pkg/ingress/controller/watch.go
+++ b/pkg/ingress/controller/watch.go
@@ -16,32 +16,32 @@ package controller
import (
"github.com/api7/ingress-controller/conf"
- "k8s.io/api/core/v1"
- "strconv"
- "github.com/gxthrj/seven/apisix"
+ "github.com/golang/glog"
apisixType "github.com/gxthrj/apisix-types/pkg/apis/apisix/v1"
- "github.com/gxthrj/seven/state"
+ "github.com/gxthrj/seven/apisix"
sevenConf "github.com/gxthrj/seven/conf"
- "github.com/golang/glog"
+ "github.com/gxthrj/seven/state"
+ "k8s.io/api/core/v1"
+ "strconv"
)
const (
- ADD = "ADD"
- UPDATE = "UPDATE"
- DELETE = "DELETE"
+ ADD = "ADD"
+ UPDATE = "UPDATE"
+ DELETE = "DELETE"
WatchFromKind = "watch"
)
-func Watch(){
+func Watch() {
c := &controller{
queue: make(chan interface{}, 100),
}
-
conf.EndpointsInformer.Informer().AddEventHandler(&QueueEventHandler{c:c})
+ conf.EndpointsInformer.Informer().AddEventHandler(&QueueEventHandler{c:
c})
go c.run()
}
-func (c *controller) pop() interface{}{
- e := <- c.queue
+func (c *controller) pop() interface{} {
+ e := <-c.queue
return e
}
@@ -55,21 +55,21 @@ func (c *controller) run() {
func (c *controller) process(obj interface{}) {
qo, _ := obj.(*queueObj)
ep, _ := qo.Obj.(*v1.Endpoints)
- if ep.Namespace != "kube-system"{ // todo here is some ignore namespaces
- for _, s := range ep.Subsets{
+ if ep.Namespace != "kube-system" { // todo here is some ignore
namespaces
+ for _, s := range ep.Subsets {
// if upstream need to watch
// ips
ips := make([]string, 0)
- for _, address := range s.Addresses{
+ for _, address := range s.Addresses {
ips = append(ips, address.IP)
}
// ports
- for _, port := range s.Ports{
+ for _, port := range s.Ports {
upstreamName := ep.Namespace + "_" + ep.Name +
"_" + strconv.Itoa(int(port.Port))
// find upstreamName is in apisix
// sync with all apisix group
- for k, _ := range sevenConf.UrlGroup {
- upstreams, err :=
apisix.ListUpstream(k)
+ for k := range sevenConf.UrlGroup {
+ upstreams, err := apisix.ListUpstream(k)
if err == nil {
for _, upstream := range
upstreams {
if *(upstream.Name) ==
upstreamName {
@@ -106,8 +106,8 @@ type controller struct {
}
type queueObj struct {
- OpeType string `json:"ope_type"`
- Obj interface{} `json:"obj"`
+ OpeType string `json:"ope_type"`
+ Obj interface{} `json:"obj"`
}
type QueueEventHandler struct {
@@ -123,5 +123,5 @@ func (h *QueueEventHandler) OnDelete(obj interface{}) {
}
func (h *QueueEventHandler) OnUpdate(old, update interface{}) {
- h.c.queue <- &queueObj{ UPDATE, update}
+ h.c.queue <- &queueObj{UPDATE, update}
}
diff --git a/pkg/route.go b/pkg/route.go
index b149cb1..009b48a 100644
--- a/pkg/route.go
+++ b/pkg/route.go
@@ -15,17 +15,17 @@
package pkg
import (
+ "encoding/json"
+ "github.com/api7/ingress-controller/log"
"github.com/julienschmidt/httprouter"
- "net/http"
"io"
- "encoding/json"
"io/ioutil"
- "github.com/api7/ingress-controller/log"
+ "net/http"
)
var logger = log.GetLogger()
-func Route() *httprouter.Router{
+func Route() *httprouter.Router {
router := httprouter.New()
router.GET("/healthz", Healthz)
router.GET("/apisix/healthz", Healthz)
@@ -33,20 +33,20 @@ func Route() *httprouter.Router{
return router
}
-func Healthz(w http.ResponseWriter, req *http.Request, _ httprouter.Params){
+func Healthz(w http.ResponseWriter, req *http.Request, _ httprouter.Params) {
io.WriteString(w, "ok")
}
-type CheckResponse struct{
+type CheckResponse struct {
Ok bool `json:"ok"`
}
-type WriteResponse struct{
+type WriteResponse struct {
Status string `json:"status"`
- Msg string `json:"msg"`
+ Msg string `json:"msg"`
}
-func populateMode(w http.ResponseWriter, r *http.Request, params
httprouter.Params, model interface{}) error{
+func populateMode(w http.ResponseWriter, r *http.Request, params
httprouter.Params, model interface{}) error {
body, err := ioutil.ReadAll(io.LimitReader(r.Body, 1048576))
if err != nil {
return err