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

kvn 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 90f6638  chore: all modules use new config (#98)
90f6638 is described below

commit 90f6638a9e785cce0a020ae8da20fe506bd4945b
Author: Alex Zhang <tok...@apache.org>
AuthorDate: Tue Dec 15 19:20:31 2020 +0800

    chore: all modules use new config (#98)
    
    * chore: all modules use new config
    
    * chore: remove useless configmap and change the descriptions in 
docs/develop.md
---
 Dockerfile                                  |  33 ++--
 build.sh                                    |  27 ---
 cmd/ingress/ingress.go                      |  14 +-
 cmd/ingress/ingress_test.go                 |  10 --
 conf/errno.go                               |  38 ----
 conf/init.go                                | 262 ----------------------------
 docs/develop.md                             |  21 ++-
 go.mod                                      |   3 -
 go.sum                                      |   9 -
 log/log.go                                  | 171 ------------------
 main.go                                     |   2 -
 pkg/ingress/controller/apisix_route.go      |  12 +-
 pkg/ingress/controller/apisix_service.go    |  18 +-
 pkg/ingress/controller/apisix_upstream.go   |  20 ++-
 pkg/ingress/controller/controller.go        |   8 +-
 pkg/ingress/controller/endpoint.go          |  20 ++-
 pkg/ingress/controller/watch.go             |   4 +-
 pkg/ingress/endpoint/ep.go                  |   6 +-
 pkg/kube/infra.go                           |  51 ++++++
 pkg/kube/init.go                            |  61 +++++++
 pkg/route.go                                |  61 -------
 samples/deploy/configmap/apisix.yaml        |  25 ---
 samples/deploy/configmap/kustomization.yaml |  19 --
 23 files changed, 190 insertions(+), 705 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index ca8113a..7cf462b 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -17,32 +17,23 @@
 FROM golang:1.13.8 AS build-env
 LABEL maintainer="gxt...@163.com"
 
+RUN rm -rf /etc/localtime \
+    && ln -s /usr/share/zoneinfo/Hongkong /etc/localtime \
+    && dpkg-reconfigure -f noninteractive tzdata
 
-WORKDIR /go/src/github.com/api7/ingress-controller
+WORKDIR /build
 COPY . .
-RUN mkdir /root/ingress-controller \
-    && go env -w GOPROXY=https://goproxy.io,direct \
-    && export GOPROXY=https://goproxy.io \
-    && go build -o /root/ingress-controller/ingress-controller \
-    && mv /go/src/github.com/api7/ingress-controller/build.sh 
/root/ingress-controller/ \
-    && mv /go/src/github.com/api7/ingress-controller/conf.json 
/root/ingress-controller/ \
-    && rm -rf /go/src/github.com/api7/ingress-controller \
-    && rm -rf /etc/localtime \
-    && ln -s  /usr/share/zoneinfo/Hongkong /etc/localtime \
-    && dpkg-reconfigure -f noninteractive tzdata
+RUN GOPROXY=https://goproxy.io,direct make build
 
 FROM alpine:3.12.1
 LABEL maintainer="gxt...@163.com"
 
-RUN mkdir /root/ingress-controller \
-   && apk add --no-cache ca-certificates libc6-compat \
-   && update-ca-certificates \
-   && echo "hosts: files dns" > /etc/nsswitch.conf
+WORKDIR /ingress-apisix
+RUN apk add --no-cache ca-certificates libc6-compat \
+    && update-ca-certificates \
+    && echo "hosts: files dns" > /etc/nsswitch.conf
 
-
-WORKDIR /root/ingress-controller
-COPY --from=build-env /root/ingress-controller/* /root/ingress-controller/
+COPY --from=build-env /build/apisix-ingress-controller .
 COPY --from=build-env /usr/share/zoneinfo/Hongkong /etc/localtime
-EXPOSE 8080
-RUN chmod +x ./build.sh
-CMD ["/root/ingress-controller/build.sh"]
+
+ENTRYPOINT ["/ingress-apisix/apisix-ingress-controller", "ingress"]
diff --git a/build.sh b/build.sh
deleted file mode 100644
index 029b829..0000000
--- a/build.sh
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/bin/sh
-#
-# 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.
-#
-
-pwd=`pwd`
-
-sed -i -e "s%#k8sAuthFile#%`echo $K8S_AUTH_FILE`%g" ${pwd}/conf.json
-sed -i -e "s%#syslogAddress#%`echo $SYSLOG_HOST`%g" ${pwd}/conf.json
-sed -i -e "s%#apisixBaseUrl#%`echo $APISIX_BASE_URL`%g" ${pwd}/conf.json
-
-cd /root/ingress-controller
-exec ./ingress-controller ingress
-
diff --git a/cmd/ingress/ingress.go b/cmd/ingress/ingress.go
index 0575356..f07174b 100644
--- a/cmd/ingress/ingress.go
+++ b/cmd/ingress/ingress.go
@@ -26,10 +26,10 @@ import (
        api6Informers 
"github.com/gxthrj/apisix-ingress-types/pkg/client/informers/externalversions"
        "github.com/spf13/cobra"
 
-       "github.com/api7/ingress-controller/conf"
        "github.com/api7/ingress-controller/pkg/api"
        "github.com/api7/ingress-controller/pkg/config"
        "github.com/api7/ingress-controller/pkg/ingress/controller"
+       "github.com/api7/ingress-controller/pkg/kube"
        "github.com/api7/ingress-controller/pkg/log"
 )
 
@@ -85,19 +85,23 @@ func NewIngressCommand() *cobra.Command {
                        }
                        log.Info("use configuration\n", string(data))
 
-                       kubeClientSet := conf.GetKubeClient()
-                       apisixClientset := conf.InitApisixClient()
+                       // TODO: Move these logics to the inside of 
pkg/ingress/controller.
+                       if err := kube.InitInformer(cfg); err != nil {
+                               dief("failed to initialize kube informers: %s", 
err)
+                       }
+                       kubeClientSet := kube.GetKubeClient()
+                       apisixClientset := kube.GetApisixClient()
                        sharedInformerFactory := 
api6Informers.NewSharedInformerFactory(apisixClientset, 0)
                        stop := make(chan struct{})
                        c := &controller.Api6Controller{
                                KubeClientSet:             kubeClientSet,
                                Api6ClientSet:             apisixClientset,
                                SharedInformerFactory:     
sharedInformerFactory,
-                               CoreSharedInformerFactory: 
conf.CoreSharedInformerFactory,
+                               CoreSharedInformerFactory: 
kube.CoreSharedInformerFactory,
                                Stop:                      stop,
                        }
                        epInformer := 
c.CoreSharedInformerFactory.Core().V1().Endpoints()
-                       conf.EndpointsInformer = epInformer
+                       kube.EndpointsInformer = epInformer
                        // endpoint
                        c.Endpoint()
                        go c.CoreSharedInformerFactory.Start(stop)
diff --git a/cmd/ingress/ingress_test.go b/cmd/ingress/ingress_test.go
index 8cde8cf..b4460c9 100644
--- a/cmd/ingress/ingress_test.go
+++ b/cmd/ingress/ingress_test.go
@@ -27,7 +27,6 @@ import (
 
        "github.com/stretchr/testify/assert"
 
-       "github.com/api7/ingress-controller/conf"
        "github.com/api7/ingress-controller/pkg/config"
        "github.com/api7/ingress-controller/pkg/log"
        "github.com/api7/ingress-controller/pkg/types"
@@ -60,10 +59,6 @@ func (fws *fakeWriteSyncer) bytes() (p []byte) {
 }
 
 func TestSignalHandler(t *testing.T) {
-       // TODO remove these lines.
-       conf.ENV = "local"
-       conf.SetConfPath("./testdata/conf.json")
-       conf.Init()
        cmd := NewIngressCommand()
        waitCh := make(chan struct{})
        go func() {
@@ -100,11 +95,6 @@ func TestNewIngressCommandEffectiveLog(t *testing.T) {
        })
        defer os.Remove("./test.log")
 
-       // TODO remove these lines.
-       conf.ENV = "local"
-       conf.SetConfPath("./testdata/conf.json")
-       conf.Init()
-
        stopCh := make(chan struct{})
        go func() {
                assert.Nil(t, cmd.Execute())
diff --git a/conf/errno.go b/conf/errno.go
deleted file mode 100644
index 92f2bdb..0000000
--- a/conf/errno.go
+++ /dev/null
@@ -1,38 +0,0 @@
-// 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"
-
-type Message struct {
-       Code string
-       Msg  string
-}
-
-var (
-       //AA 01 表示ingress-controller本身的错误
-       //BB 00 表示系统信息
-       SystemError = Message{"010001", "system errno"}
-
-       //BB 01表示更新失败
-       UpdateUpstreamNodesError = Message{"010101", "服务%s节点更新失败"}
-       AddUpstreamError         = Message{"010102", "增加upstream %s失败"}
-       AddUpstreamJsonError     = Message{"010103", "upstream %s json trans 
error"}
-)
-
-func (m Message) ToString(params ...interface{}) string {
-       params = append(params, m.Code)
-       return fmt.Sprintf(m.Msg+" error_code:%s", params...)
-}
diff --git a/conf/init.go b/conf/init.go
deleted file mode 100644
index 6105b48..0000000
--- a/conf/init.go
+++ /dev/null
@@ -1,262 +0,0 @@
-// 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"
-       clientSet 
"github.com/gxthrj/apisix-ingress-types/pkg/client/clientset/versioned"
-       seven "github.com/gxthrj/seven/conf"
-       "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"
-       "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
-       EndpointsInformer coreinformers.EndpointsInformer
-       IsLeader          = false
-       //etcdClient client.Client
-       kubeClient                kubernetes.Interface
-       CoreSharedInformerFactory informers.SharedInformerFactory
-
-       injectedConfPath string
-)
-
-const PROD = "prod"
-const HBPROD = "hb-prod"
-const BETA = "beta"
-const DEV = "dev"
-const TEST = "test"
-const LOCAL = "local"
-const confPath = "/root/ingress-controller/conf.json"
-const AispeechUpstreamKey = "/apisix/customer/upstream/map"
-
-func setEnvironment() {
-       if env := os.Getenv("ENV"); env == "" {
-               ENV = LOCAL
-       } else {
-               ENV = env
-       }
-       _, basePath, _, _ = runtime.Caller(1)
-}
-
-// Only use in unit tests.
-func SetConfPath(path string) {
-       injectedConfPath = path
-}
-
-func ConfPath() string {
-       if injectedConfPath != "" {
-               return injectedConfPath
-       }
-       if ENV == LOCAL {
-               return filepath.Join(filepath.Dir(basePath), "conf.json")
-       } else {
-               return confPath
-       }
-}
-
-type etcdConfig struct {
-       Addresses []string
-}
-
-var EtcdConfig etcdConfig
-var K8sAuth k8sAuth
-var Syslog syslog
-
-var config *restclient.Config
-
-func Init() {
-       // 获取当前环境
-       setEnvironment()
-       // 获取配置文件路径
-       filePath := ConfPath()
-       // 获取配置文件内容
-       if configurationContent, err := ioutil.ReadFile(filePath); err != nil {
-               panic(fmt.Sprintf("failed to read configuration file: %s", 
filePath))
-       } else {
-               configuration := gjson.ParseBytes(configurationContent)
-               // apisix baseUrl
-               apisixConf := configuration.Get("conf.apisix")
-               apisixBaseUrl := apisixConf.Get("base_url").String()
-               seven.SetBaseUrl(apisixBaseUrl)
-               // k8sAuth conf
-               k8sAuthConf := configuration.Get("conf.k8sAuth")
-               K8sAuth.file = k8sAuthConf.Get("file").String()
-               // syslog conf
-               syslogConf := configuration.Get("conf.syslog")
-               Syslog.Host = syslogConf.Get("host").String()
-       }
-       // init etcd client
-       //etcdClient = NewEtcdClient()
-       // init informer
-       InitInformer()
-}
-
-type k8sAuth struct {
-       file string
-}
-
-type syslog struct {
-       Host string
-}
-
-//func GetEtcdAPI() client.KeysAPI{
-//     return client.NewKeysAPI(etcdClient)
-//}
-
-func GetURL() string {
-       if ADMIN_URL != "" {
-               return ADMIN_URL
-       } else {
-               return "http://172.16.20.90:30116/apisix/admin";
-       }
-}
-
-func GetPodInformer() coreinformers.PodInformer {
-       return podInformer
-}
-
-func GetSvcInformer() coreinformers.ServiceInformer {
-       return svcInformer
-}
-
-func GetNsInformer() coreinformers.NamespaceInformer {
-       return nsInformer
-}
-
-func GetKubeClient() kubernetes.Interface {
-       return kubeClient
-}
-
-func InitKubeClient() kubernetes.Interface {
-       //var err error
-       //if ENV == LOCAL {
-       //      clientConfig, err := clientcmd.LoadFromFile(K8sAuth.file)
-       //      ExceptNilErr(err)
-       //
-       //      config, err = clientcmd.NewDefaultClientConfig(*clientConfig, 
&clientcmd.ConfigOverrides{}).ClientConfig()
-       //      ExceptNilErr(err)
-       //} else {
-       //      config, err = restclient.InClusterConfig()
-       //      ExceptNilErr(err)
-       //}
-
-       k8sClient, err := kubernetes.NewForConfig(config)
-       ExceptNilErr(err)
-       return k8sClient
-}
-
-func InitApisixClient() clientSet.Interface {
-       apisixRouteClientset, err := clientSet.NewForConfig(config)
-       ExceptNilErr(err)
-       return apisixRouteClientset
-}
-
-func InitInformer() {
-       // 生成一个k8s client
-       //var config *restclient.Config
-       var err error
-       if ENV == LOCAL {
-               clientConfig, err := clientcmd.LoadFromFile(K8sAuth.file)
-               ExceptNilErr(err)
-
-               config, err = clientcmd.NewDefaultClientConfig(*clientConfig, 
&clientcmd.ConfigOverrides{}).ClientConfig()
-               ExceptNilErr(err)
-       } else {
-               config, err = restclient.InClusterConfig()
-               ExceptNilErr(err)
-       }
-
-       //k8sClient, err := kubernetes.NewForConfig(config)
-       kubeClient = InitKubeClient()
-       ExceptNilErr(err)
-
-       // 创建一个informerFactory
-       //sharedInformerFactory := 
informers.NewSharedInformerFactory(k8sClient, 0)
-       // 创建一个informerFactory
-       CoreSharedInformerFactory = 
informers.NewSharedInformerFactory(kubeClient, 0)
-
-       // 创建 informers
-       podInformer = CoreSharedInformerFactory.Core().V1().Pods()
-       svcInformer = CoreSharedInformerFactory.Core().V1().Services()
-       nsInformer = CoreSharedInformerFactory.Core().V1().Namespaces()
-       //return podInformer, svcInformer, nsInformer
-}
-
-func ExceptNilErr(err error) {
-       if err != nil {
-               panic(err)
-       }
-}
-
-//func NewEtcdClient() client.Client {
-//     cfg := client.Config{
-//             Endpoints: EtcdConfig.Addresses,
-//             Transport: client.DefaultTransport,
-//     }
-//     if c, err := client.New(cfg); err != nil {
-//             panic(fmt.Sprintf("failed to initialize etcd watcher. %s", 
err.Error()))
-//     } else {
-//             return c
-//     }
-//}
-
-// EtcdWatcher
-//type EtcdWatcher struct {
-//     client     client.Client
-//     etcdKey         string
-//     ctx        context.Context
-//     cancels    []context.CancelFunc
-//}
-//
-//
-//type BalancerRules struct {
-//     RuleSpec *RuleSpec `json:"spec"`
-//}
-//
-//type RuleSpec struct {
-//     Ewma []string `json:"ewma"`
-//     Sllb []Sllb `json:"sllb"`
-//}
-//
-//type Sllb struct {
-//     Name string `json:"name"`
-//     Threshold int64 `json:"threshold"`
-//     Open string `json:"open"`
-//     MakeZero string `json:"makeZero"`
-//}
-//
-//type BalancerLevel struct {
-//     LevelSpec *LevelSpec `json:"spec"`
-//}
-//
-//type LevelSpec struct {
-//     Pod []string `json:"pod"`
-//}
diff --git a/docs/develop.md b/docs/develop.md
index d833a5e..3a63ab6 100644
--- a/docs/develop.md
+++ b/docs/develop.md
@@ -45,24 +45,23 @@ Tips: The Kubernetes cluster deployment method is 
recommended for production and
 
 2. Location: ~/.kube/config
 
-3. Copy the config file to the local development environment, and set the path 
of configure file to the k8sAuth item 
($GOPATH/src/github.com/apache/apisix-ingress-controller/conf/conf.json#conf.k8sAuth).
+3. Copy the config file to your local development environment, the path should 
be configured in apisix-ingress-controller by specifying `--kuebconfig` option.
 
-### Configure Apache APISIX service address
+### Configure APISIX service address
 
-Configure the service address of Apache APISIX to conf/apisix/base_url 
($GOPATH/src/github.com/apache/apisix-ingress-controller/conf/conf.json).
+Your APISIX service address should be configured in apisix-ingress-controller 
by specifying `--apisix-base-url` option.
 
 ## Start ingress-controller locally
 
-* Create CRDs
+* Build and run apisix-ingress-controller
 
 ```shell
-kubectl apply -k samples/deploy/crd/v1beta1
-```
-
-* Run apisix-ingress-controller
-
-```shell
-# go run main.go -logtostderr -v=5
+$ make build
+$ ./apisix-ingress-controller ingress \
+  --kubeconfig /path/to/kubeconfig \
+  --http-listen :8080 \
+  --log-output stderr \
+  --apisix-base-url http://apisix-service:port/apisix
 ```
 
 Tips: The program may print some error logs, indicating that the resource 
cannot be found. Continue with the following steps to define the route through 
CRDs.
diff --git a/go.mod b/go.mod
index e42f082..40660d1 100644
--- a/go.mod
+++ b/go.mod
@@ -9,12 +9,9 @@ require (
        github.com/gxthrj/apisix-ingress-types v0.1.2
        github.com/gxthrj/apisix-types v0.1.0
        github.com/gxthrj/seven v0.1.9
-       github.com/julienschmidt/httprouter v1.2.0
        github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // 
indirect
-       github.com/sirupsen/logrus v1.4.2
        github.com/spf13/cobra v1.1.1
        github.com/stretchr/testify v1.4.0
-       github.com/tidwall/gjson v1.6.4
        go.uber.org/zap v1.13.0
        gopkg.in/yaml.v2 v2.2.8
        k8s.io/api v0.0.0-20190819141258-3544db3b9e44
diff --git a/go.sum b/go.sum
index 0e95dff..65077f1 100644
--- a/go.sum
+++ b/go.sum
@@ -233,8 +233,6 @@ github.com/sergi/go-diff v1.1.0 
h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
 github.com/sergi/go-diff v1.1.0/go.mod 
h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
 github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod 
h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
 github.com/sirupsen/logrus v1.2.0/go.mod 
h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
-github.com/sirupsen/logrus v1.4.2 
h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
-github.com/sirupsen/logrus v1.4.2/go.mod 
h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
 github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod 
h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
 github.com/smartystreets/goconvey v1.6.4/go.mod 
h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
 github.com/soheilhy/cmux v0.1.4/go.mod 
h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
@@ -256,12 +254,6 @@ github.com/stretchr/testify v1.3.0/go.mod 
h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
 github.com/stretchr/testify v1.4.0 
h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
 github.com/stretchr/testify v1.4.0/go.mod 
h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
 github.com/subosito/gotenv v1.2.0/go.mod 
h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
-github.com/tidwall/gjson v1.6.4 h1:JKsCsJqRVFz8eYCsQ5E/ANRbK6CanAtA9IUvGsXklyo=
-github.com/tidwall/gjson v1.6.4/go.mod 
h1:BaHyNc5bjzYkPqgLq7mdVzeiRtULKULXLgZFKsxEHI0=
-github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
-github.com/tidwall/match v1.0.1/go.mod 
h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
-github.com/tidwall/pretty v1.0.2 
h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
-github.com/tidwall/pretty v1.0.2/go.mod 
h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
 github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod 
h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
 github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
 github.com/ugorji/go v1.1.7/go.mod 
h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
@@ -352,7 +344,6 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod 
h1:STP8DvDyc/dI5b8T5h
 golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod 
h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod 
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod 
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod 
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod 
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod 
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod 
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
diff --git a/log/log.go b/log/log.go
deleted file mode 100644
index d4a9e57..0000000
--- a/log/log.go
+++ /dev/null
@@ -1,171 +0,0 @@
-// 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 log
-
-import (
-       "bufio"
-       "fmt"
-       "github.com/api7/ingress-controller/conf"
-       "github.com/sirupsen/logrus"
-       "log/syslog"
-       "os"
-       "runtime"
-       "strings"
-)
-
-var logEntry *logrus.Entry
-
-func GetLogger() *logrus.Entry {
-       if logEntry == nil {
-               var log = logrus.New()
-               setNull(log)
-               log.SetLevel(logrus.DebugLevel)
-               if conf.ENV != conf.LOCAL {
-                       log.SetLevel(logrus.InfoLevel)
-               }
-               log.SetFormatter(&logrus.JSONFormatter{})
-               logEntry = log.WithFields(logrus.Fields{
-                       "app": "ingress-controller",
-               })
-               hook, err := createHook("udp", fmt.Sprintf("%s:514", 
conf.Syslog.Host),
-                       syslog.LOG_LOCAL4, "ingress-controller")
-               if err != nil {
-                       panic("failed to create log hook " + conf.Syslog.Host)
-               }
-               log.AddHook(hook)
-       }
-       return logEntry
-}
-
-func setNull(log *logrus.Logger) {
-       src, err := os.OpenFile(os.DevNull, os.O_APPEND|os.O_WRONLY, 
os.ModeAppend)
-       if err != nil {
-               fmt.Println("err", err)
-       }
-       writer := bufio.NewWriter(src)
-       log.SetOutput(writer)
-}
-
-type SysLogHook struct {
-       Writer    *syslog.Writer
-       NetWork   string
-       Raddr     string
-       Formatter func(file, function string, line int) string
-       LineName  string
-}
-
-func createHook(network, raddr string, priority syslog.Priority, tag string) 
(*SysLogHook, error) {
-       if w, err := syslog.Dial(network, raddr, priority, tag); err != nil {
-               return nil, err
-       } else {
-               return &SysLogHook{w, network, raddr,
-                       func(file, function string, line int) string {
-                               return fmt.Sprintf("%s:%d", file, line)
-                       },
-                       "line",
-               }, nil
-       }
-}
-
-func (hook *SysLogHook) Fire(entry *logrus.Entry) error {
-       //entry.Data[hook.LineName] = hook.Formatter(findCaller(5))
-       en := entry.WithField(hook.LineName, hook.Formatter(findCaller(5)))
-       en.Level = entry.Level
-       en.Message = entry.Message
-       en.Time = entry.Time
-       line, err := en.String()
-       if err != nil {
-               fmt.Fprintf(os.Stderr, "Unable to read entry, %v", err)
-               return err
-       }
-
-       switch en.Level {
-       case logrus.PanicLevel:
-               hook.Writer.Crit(line)
-               localPrint(line)
-               return nil
-       case logrus.FatalLevel:
-               hook.Writer.Crit(line)
-               localPrint(line)
-               return nil
-       case logrus.ErrorLevel:
-               hook.Writer.Err(line)
-               localPrint(line)
-               return nil
-       case logrus.WarnLevel:
-               hook.Writer.Warning(line)
-               localPrint(line)
-               return nil
-       case logrus.InfoLevel:
-               hook.Writer.Info(line)
-               localPrint(line)
-               return nil
-       case logrus.DebugLevel:
-               hook.Writer.Debug(line)
-               localPrint(line)
-               return nil
-       default:
-               return nil
-       }
-}
-
-func localPrint(line string) {
-       if conf.ENV != conf.BETA && conf.ENV != conf.PROD && conf.ENV != 
conf.HBPROD {
-               fmt.Print(line)
-       }
-}
-
-func (hook *SysLogHook) Levels() []logrus.Level {
-       return logrus.AllLevels
-}
-
-func findCaller(skip int) (string, string, int) {
-       var (
-               pc       uintptr
-               file     string
-               function string
-               line     int
-       )
-       for i := 0; i < 10; i++ {
-               pc, file, line = getCaller(skip + i)
-               if !strings.HasPrefix(file, "logrus") {
-                       break
-               }
-       }
-       if pc != 0 {
-               frames := runtime.CallersFrames([]uintptr{pc})
-               frame, _ := frames.Next()
-               function = frame.Function
-       }
-       return file, function, line
-}
-
-func getCaller(skip int) (uintptr, string, int) {
-       pc, file, line, ok := runtime.Caller(skip)
-       if !ok {
-               return 0, "", 0
-       }
-       n := 0
-       for i := len(file) - 1; i > 0; i-- {
-               if file[i] == '/' {
-                       n += 1
-                       if n >= 2 {
-                               file = file[i+1:]
-                               break
-                       }
-               }
-       }
-       return pc, file, line
-}
diff --git a/main.go b/main.go
index 1633471..2831a5b 100644
--- a/main.go
+++ b/main.go
@@ -19,11 +19,9 @@ import (
        "os"
 
        "github.com/api7/ingress-controller/cmd"
-       "github.com/api7/ingress-controller/conf"
 )
 
 func main() {
-       conf.Init()
        root := cmd.NewAPISIXIngressControllerCommand()
        if err := root.Execute(); err != nil {
                fmt.Fprintln(os.Stderr, err.Error())
diff --git a/pkg/ingress/controller/apisix_route.go 
b/pkg/ingress/controller/apisix_route.go
index 65decd2..eed0825 100644
--- a/pkg/ingress/controller/apisix_route.go
+++ b/pkg/ingress/controller/apisix_route.go
@@ -31,6 +31,8 @@ import (
        "k8s.io/client-go/tools/cache"
        "k8s.io/client-go/util/workqueue"
        "time"
+
+       "github.com/api7/ingress-controller/pkg/log"
 )
 
 type ApisixRouteController struct {
@@ -113,7 +115,7 @@ func (c *ApisixRouteController) Run(stop <-chan struct{}) 
error {
        //defer c.workqueue.ShutDown()
        // 同步缓存
        if ok := cache.WaitForCacheSync(stop); !ok {
-               logger.Errorf("同步缓存失败")
+               log.Errorf("同步缓存失败")
                return fmt.Errorf("failed to wait for caches to sync")
        }
        go wait.Until(c.runWorker, time.Second, stop)
@@ -179,14 +181,14 @@ func (c *ApisixRouteController) syncHandler(rqo 
*RouteQueueObj) error {
 func (c *ApisixRouteController) add(key string) error {
        namespace, name, err := cache.SplitMetaNamespaceKey(key)
        if err != nil {
-               logger.Errorf("invalid resource key: %s", key)
+               log.Errorf("invalid resource key: %s", key)
                return fmt.Errorf("invalid resource key: %s", key)
        }
 
        apisixIngressRoute, err := 
c.apisixRouteList.ApisixRoutes(namespace).Get(name)
        if err != nil {
                if errors.IsNotFound(err) {
-                       logger.Infof("apisixRoute %s is removed", key)
+                       log.Infof("apisixRoute %s is removed", key)
                        return nil
                }
                runtime.HandleError(fmt.Errorf("failed to list apisixRoute 
%s/%s", key, err.Error()))
@@ -206,14 +208,14 @@ func (c *ApisixRouteController) sync(rqo *RouteQueueObj) 
error {
        key := rqo.Key
        namespace, name, err := cache.SplitMetaNamespaceKey(key)
        if err != nil {
-               logger.Errorf("invalid resource key: %s", key)
+               log.Errorf("invalid resource key: %s", key)
                return fmt.Errorf("invalid resource key: %s", key)
        }
 
        apisixIngressRoute, err := 
c.apisixRouteList.ApisixRoutes(namespace).Get(name)
        if err != nil {
                if errors.IsNotFound(err) {
-                       logger.Infof("apisixRoute %s is removed", key)
+                       log.Infof("apisixRoute %s is removed", key)
                        return nil
                }
                runtime.HandleError(fmt.Errorf("failed to list apisixRoute 
%s/%s", key, err.Error()))
diff --git a/pkg/ingress/controller/apisix_service.go 
b/pkg/ingress/controller/apisix_service.go
index cdd1cc6..e446736 100644
--- a/pkg/ingress/controller/apisix_service.go
+++ b/pkg/ingress/controller/apisix_service.go
@@ -16,8 +16,8 @@ package controller
 
 import (
        "fmt"
-       "github.com/api7/ingress-controller/pkg/ingress/apisix"
-       "github.com/golang/glog"
+       "time"
+
        apisixV1 "github.com/gxthrj/apisix-ingress-types/pkg/apis/config/v1"
        clientSet 
"github.com/gxthrj/apisix-ingress-types/pkg/client/clientset/versioned"
        apisixScheme 
"github.com/gxthrj/apisix-ingress-types/pkg/client/clientset/versioned/scheme"
@@ -31,7 +31,9 @@ import (
        "k8s.io/client-go/kubernetes/scheme"
        "k8s.io/client-go/tools/cache"
        "k8s.io/client-go/util/workqueue"
-       "time"
+
+       "github.com/api7/ingress-controller/pkg/ingress/apisix"
+       "github.com/api7/ingress-controller/pkg/log"
 )
 
 type ApisixServiceController struct {
@@ -67,7 +69,7 @@ func BuildApisixServiceController(
 func (c *ApisixServiceController) Run(stop <-chan struct{}) error {
        // 同步缓存
        if ok := cache.WaitForCacheSync(stop); !ok {
-               glog.Errorf("同步ApisixService缓存失败")
+               log.Error("同步ApisixService缓存失败")
                return fmt.Errorf("failed to wait for caches to sync")
        }
        go wait.Until(c.runWorker, time.Second, stop)
@@ -111,21 +113,21 @@ func (c *ApisixServiceController) processNextWorkItem() 
bool {
 func (c *ApisixServiceController) syncHandler(key string) error {
        namespace, name, err := cache.SplitMetaNamespaceKey(key)
        if err != nil {
-               logger.Errorf("invalid resource key: %s", key)
+               log.Errorf("invalid resource key: %s", key)
                return fmt.Errorf("invalid resource key: %s", key)
        }
 
        apisixServiceYaml, err := 
c.apisixServiceList.ApisixServices(namespace).Get(name)
        if err != nil {
                if errors.IsNotFound(err) {
-                       logger.Infof("apisixUpstream %s is removed", key)
+                       log.Infof("apisixUpstream %s is removed", key)
                        return nil
                }
                runtime.HandleError(fmt.Errorf("failed to list apisixUpstream 
%s/%s", key, err.Error()))
                return err
        }
-       logger.Info(namespace)
-       logger.Info(name)
+       log.Info(namespace)
+       log.Info(name)
        apisixService := apisix.ApisixServiceCRD(*apisixServiceYaml)
        services, upstreams, _ := apisixService.Convert()
        comb := state.ApisixCombination{Routes: nil, Services: services, 
Upstreams: upstreams}
diff --git a/pkg/ingress/controller/apisix_upstream.go 
b/pkg/ingress/controller/apisix_upstream.go
index 63deac0..e9436be 100644
--- a/pkg/ingress/controller/apisix_upstream.go
+++ b/pkg/ingress/controller/apisix_upstream.go
@@ -16,9 +16,8 @@ package controller
 
 import (
        "fmt"
-       "github.com/api7/ingress-controller/pkg/ingress/apisix"
-       "github.com/api7/ingress-controller/pkg/ingress/endpoint"
-       "github.com/golang/glog"
+       "time"
+
        apisixV1 "github.com/gxthrj/apisix-ingress-types/pkg/apis/config/v1"
        clientSet 
"github.com/gxthrj/apisix-ingress-types/pkg/client/clientset/versioned"
        apisixScheme 
"github.com/gxthrj/apisix-ingress-types/pkg/client/clientset/versioned/scheme"
@@ -32,7 +31,10 @@ import (
        "k8s.io/client-go/kubernetes/scheme"
        "k8s.io/client-go/tools/cache"
        "k8s.io/client-go/util/workqueue"
-       "time"
+
+       "github.com/api7/ingress-controller/pkg/ingress/apisix"
+       "github.com/api7/ingress-controller/pkg/ingress/endpoint"
+       "github.com/api7/ingress-controller/pkg/log"
 )
 
 type ApisixUpstreamController struct {
@@ -68,7 +70,7 @@ func BuildApisixUpstreamController(
 func (c *ApisixUpstreamController) Run(stop <-chan struct{}) error {
        // 同步缓存
        if ok := cache.WaitForCacheSync(stop); !ok {
-               glog.Errorf("同步ApisixUpstream缓存失败")
+               log.Error("同步ApisixUpstream缓存失败")
                return fmt.Errorf("failed to wait for caches to sync")
        }
        go wait.Until(c.runWorker, time.Second, stop)
@@ -112,21 +114,21 @@ func (c *ApisixUpstreamController) processNextWorkItem() 
bool {
 func (c *ApisixUpstreamController) syncHandler(key string) error {
        namespace, name, err := cache.SplitMetaNamespaceKey(key)
        if err != nil {
-               logger.Errorf("invalid resource key: %s", key)
+               log.Errorf("invalid resource key: %s", key)
                return fmt.Errorf("invalid resource key: %s", key)
        }
 
        apisixUpstreamYaml, err := 
c.apisixUpstreamList.ApisixUpstreams(namespace).Get(name)
        if err != nil {
                if errors.IsNotFound(err) {
-                       logger.Infof("apisixUpstream %s is removed", key)
+                       log.Infof("apisixUpstream %s is removed", key)
                        return nil
                }
                runtime.HandleError(fmt.Errorf("failed to list apisixUpstream 
%s/%s", key, err.Error()))
                return err
        }
-       logger.Info(namespace)
-       logger.Info(name)
+       log.Info(namespace)
+       log.Info(name)
        //apisixUpstream := apisix.ApisixUpstreamCRD(*apisixUpstreamYaml)
        aub := apisix.ApisixUpstreamBuilder{CRD: apisixUpstreamYaml, Ep: 
&endpoint.EndpointRequest{}}
        upstreams, _ := aub.Convert()
diff --git a/pkg/ingress/controller/controller.go 
b/pkg/ingress/controller/controller.go
index ecaee5e..11ddaa4 100644
--- a/pkg/ingress/controller/controller.go
+++ b/pkg/ingress/controller/controller.go
@@ -15,20 +15,18 @@
 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"
        "k8s.io/client-go/informers"
        "k8s.io/client-go/kubernetes"
-)
 
-var logger = log.GetLogger()
+       "github.com/api7/ingress-controller/pkg/log"
+)
 
 // recover any exception
 func recoverException() {
        if err := recover(); err != nil {
-               glog.Error(err)
+               log.Error(err)
        }
 }
 
diff --git a/pkg/ingress/controller/endpoint.go 
b/pkg/ingress/controller/endpoint.go
index 07de1eb..7c42a22 100644
--- a/pkg/ingress/controller/endpoint.go
+++ b/pkg/ingress/controller/endpoint.go
@@ -16,7 +16,6 @@ package controller
 
 import (
        "fmt"
-       "github.com/api7/ingress-controller/conf"
        "github.com/golang/glog"
        apisixType "github.com/gxthrj/apisix-types/pkg/apis/apisix/v1"
        "github.com/gxthrj/seven/apisix"
@@ -32,6 +31,9 @@ import (
        "k8s.io/client-go/util/workqueue"
        "strconv"
        "time"
+
+       "github.com/api7/ingress-controller/pkg/kube"
+       "github.com/api7/ingress-controller/pkg/log"
 )
 
 type EndpointController struct {
@@ -44,11 +46,11 @@ type EndpointController struct {
 func BuildEndpointController(kubeclientset kubernetes.Interface) 
*EndpointController {
        controller := &EndpointController{
                kubeclientset:  kubeclientset,
-               endpointList:   conf.EndpointsInformer.Lister(),
-               endpointSynced: conf.EndpointsInformer.Informer().HasSynced,
+               endpointList:   kube.EndpointsInformer.Lister(),
+               endpointSynced: kube.EndpointsInformer.Informer().HasSynced,
                workqueue:      
workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), 
"endpoints"),
        }
-       conf.EndpointsInformer.Informer().AddEventHandler(
+       kube.EndpointsInformer.Informer().AddEventHandler(
                cache.ResourceEventHandlerFuncs{
                        AddFunc:    controller.addFunc,
                        UpdateFunc: controller.updateFunc,
@@ -60,7 +62,7 @@ func BuildEndpointController(kubeclientset 
kubernetes.Interface) *EndpointContro
 func (c *EndpointController) Run(stop <-chan struct{}) error {
        // 同步缓存
        if ok := cache.WaitForCacheSync(stop); !ok {
-               glog.Errorf("同步Endpoint缓存失败")
+               log.Errorf("同步Endpoint缓存失败")
                return fmt.Errorf("failed to wait for caches to sync")
        }
        go wait.Until(c.runWorker, time.Second, stop)
@@ -76,7 +78,7 @@ func (c *EndpointController) processNextWorkItem() bool {
        defer recoverException()
        obj, shutdown := c.workqueue.Get()
        if shutdown {
-               glog.V(2).Info("shutdown")
+               log.Info("shutdown")
                return false
        }
        err := func(obj interface{}) error {
@@ -105,17 +107,17 @@ func (c *EndpointController) processNextWorkItem() bool {
 func (c *EndpointController) syncHandler(key string) error {
        namespace, name, err := cache.SplitMetaNamespaceKey(key)
        if name == "cinfoserver" || name == "file-resync2-server" {
-               glog.V(2).Infof("find endpoint %s/%s", namespace, name)
+               log.Infof("find endpoint %s/%s", namespace, name)
        }
        if err != nil {
-               logger.Errorf("invalid resource key: %s", key)
+               log.Errorf("invalid resource key: %s", key)
                return fmt.Errorf("invalid resource key: %s", key)
        }
 
        endpointYaml, err := c.endpointList.Endpoints(namespace).Get(name)
        if err != nil {
                if errors.IsNotFound(err) {
-                       logger.Infof("endpoint %s is removed", key)
+                       log.Infof("endpoint %s is removed", key)
                        return nil
                }
                runtime.HandleError(fmt.Errorf("failed to list endpoint %s/%s", 
key, err.Error()))
diff --git a/pkg/ingress/controller/watch.go b/pkg/ingress/controller/watch.go
index e4ea9f4..ce4a2ca 100644
--- a/pkg/ingress/controller/watch.go
+++ b/pkg/ingress/controller/watch.go
@@ -15,7 +15,7 @@
 package controller
 
 import (
-       "github.com/api7/ingress-controller/conf"
+       "github.com/api7/ingress-controller/pkg/kube"
        "github.com/golang/glog"
        apisixType "github.com/gxthrj/apisix-types/pkg/apis/apisix/v1"
        "github.com/gxthrj/seven/apisix"
@@ -36,7 +36,7 @@ func Watch() {
        c := &controller{
                queue: make(chan interface{}, 100),
        }
-       conf.EndpointsInformer.Informer().AddEventHandler(&QueueEventHandler{c: 
c})
+       kube.EndpointsInformer.Informer().AddEventHandler(&QueueEventHandler{c: 
c})
        go c.run()
 }
 
diff --git a/pkg/ingress/endpoint/ep.go b/pkg/ingress/endpoint/ep.go
index e3dac75..ad77d4a 100644
--- a/pkg/ingress/endpoint/ep.go
+++ b/pkg/ingress/endpoint/ep.go
@@ -15,7 +15,7 @@
 package endpoint
 
 import (
-       "github.com/api7/ingress-controller/conf"
+       "github.com/api7/ingress-controller/pkg/kube"
        "github.com/golang/glog"
        "github.com/gxthrj/apisix-types/pkg/apis/apisix/v1"
 )
@@ -28,7 +28,7 @@ type EndpointRequest struct{}
 
 func (epr *EndpointRequest) BuildEps(ns, name string, port int) []*v1.Node {
        nodes := make([]*v1.Node, 0)
-       epInformers := conf.EndpointsInformer
+       epInformers := kube.EndpointsInformer
        if ep, err := epInformers.Lister().Endpoints(ns).Get(name); err != nil {
                glog.Errorf("find endpoint %s/%s err: %s", ns, name, 
err.Error())
        } else {
@@ -47,7 +47,7 @@ func (epr *EndpointRequest) BuildEps(ns, name string, port 
int) []*v1.Node {
 // BuildEps build nodes from endpoints for upstream
 func BuildEps(ns, name string, port int) []*v1.Node {
        nodes := make([]*v1.Node, 0)
-       epInformers := conf.EndpointsInformer
+       epInformers := kube.EndpointsInformer
        if ep, err := epInformers.Lister().Endpoints(ns).Get(name); err != nil {
                glog.Errorf("find endpoint %s/%s err: %s", ns, name, 
err.Error())
        } else {
diff --git a/pkg/kube/infra.go b/pkg/kube/infra.go
new file mode 100644
index 0000000..9552746
--- /dev/null
+++ b/pkg/kube/infra.go
@@ -0,0 +1,51 @@
+// 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 kube
+
+import (
+       "os"
+
+       "k8s.io/client-go/rest"
+       "k8s.io/client-go/tools/clientcmd"
+)
+
+// BuildRestConfig builds the rest.Config object from kubeconfig filepath and
+// context, if kubeconfig is missing, building from in-cluster configuration.
+func BuildRestConfig(kubeconfig, context string) (*rest.Config, error) {
+       if kubeconfig != "" {
+               info, err := os.Stat(kubeconfig)
+               if err != nil || info.Size() == 0 {
+                       // If the specified kubeconfig doesn't exists / empty 
file / any other error
+                       // from file stat, fall back to default
+                       kubeconfig = ""
+               }
+       }
+
+       //Config loading rules:
+       // 1. kubeconfig if it not empty string
+       // 2. Config(s) in KUBECONFIG environment variable
+       // 3. In cluster config if running in-cluster
+       // 4. Use $HOME/.kube/config
+       loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
+       loadingRules.DefaultClientConfig = &clientcmd.DefaultClientConfig
+       loadingRules.ExplicitPath = kubeconfig
+       configOverrides := &clientcmd.ConfigOverrides{
+               ClusterDefaults: clientcmd.ClusterDefaults,
+               CurrentContext:  context,
+       }
+
+       clientConfig := 
clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, 
configOverrides)
+       return clientConfig.ClientConfig()
+}
diff --git a/pkg/kube/init.go b/pkg/kube/init.go
new file mode 100644
index 0000000..ef167d2
--- /dev/null
+++ b/pkg/kube/init.go
@@ -0,0 +1,61 @@
+// 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 kube
+
+import (
+       clientSet 
"github.com/gxthrj/apisix-ingress-types/pkg/client/clientset/versioned"
+       "k8s.io/client-go/informers"
+       coreinformers "k8s.io/client-go/informers/core/v1"
+       "k8s.io/client-go/kubernetes"
+
+       "github.com/api7/ingress-controller/pkg/config"
+)
+
+var (
+       EndpointsInformer         coreinformers.EndpointsInformer
+       kubeClient                kubernetes.Interface
+       apisixKubeClient          *clientSet.Clientset
+       CoreSharedInformerFactory informers.SharedInformerFactory
+)
+
+func GetKubeClient() kubernetes.Interface {
+       return kubeClient
+}
+
+func GetApisixClient() clientSet.Interface {
+       return apisixKubeClient
+}
+
+// initInformer initializes all related shared informers.
+// Deprecate: will be refactored in the future without notification.
+func InitInformer(cfg *config.Config) error {
+       var err error
+       restConfig, err := BuildRestConfig(cfg.Kubernetes.Kubeconfig, "")
+       if err != nil {
+               return err
+       }
+       kubeClient, err = kubernetes.NewForConfig(restConfig)
+       if err != nil {
+               return err
+       }
+
+       apisixKubeClient, err = clientSet.NewForConfig(restConfig)
+       if err != nil {
+               return err
+       }
+       CoreSharedInformerFactory = 
informers.NewSharedInformerFactory(kubeClient, 0)
+
+       return nil
+}
diff --git a/pkg/route.go b/pkg/route.go
deleted file mode 100644
index 009b48a..0000000
--- a/pkg/route.go
+++ /dev/null
@@ -1,61 +0,0 @@
-// 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 pkg
-
-import (
-       "encoding/json"
-       "github.com/api7/ingress-controller/log"
-       "github.com/julienschmidt/httprouter"
-       "io"
-       "io/ioutil"
-       "net/http"
-)
-
-var logger = log.GetLogger()
-
-func Route() *httprouter.Router {
-       router := httprouter.New()
-       router.GET("/healthz", Healthz)
-       router.GET("/apisix/healthz", Healthz)
-       //router.GET("/apisix/sync/upstream/:name", syncPodWithUpstream)
-       return router
-}
-
-func Healthz(w http.ResponseWriter, req *http.Request, _ httprouter.Params) {
-       io.WriteString(w, "ok")
-}
-
-type CheckResponse struct {
-       Ok bool `json:"ok"`
-}
-
-type WriteResponse struct {
-       Status string `json:"status"`
-       Msg    string `json:"msg"`
-}
-
-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
-       }
-       if err := r.Body.Close(); err != nil {
-               return err
-       }
-       if err := json.Unmarshal(body, model); err != nil {
-               return err
-       }
-       return nil
-}
diff --git a/samples/deploy/configmap/apisix.yaml 
b/samples/deploy/configmap/apisix.yaml
deleted file mode 100644
index d1d9c61..0000000
--- a/samples/deploy/configmap/apisix.yaml
+++ /dev/null
@@ -1,25 +0,0 @@
-#
-# 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: v1
-kind: ConfigMap
-metadata:
-  name: apisix-config
-data:
-  SYSLOG_HOST: 127.0.0.1
-  APISIX_BASE_URL: "http://apisix.default.svc.cluster.local:9180/apisix/admin";
-  ENV: "prod"
diff --git a/samples/deploy/configmap/kustomization.yaml 
b/samples/deploy/configmap/kustomization.yaml
deleted file mode 100644
index 3258fd2..0000000
--- a/samples/deploy/configmap/kustomization.yaml
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# 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.
-#
-
-resources:
-  - ./apisix.yaml

Reply via email to