Skip to content

Commit

Permalink
chore: introduce a CLI interface and a Makefile. (#66)
Browse files Browse the repository at this point in the history
* chore: introduce a CLI interface and a Makefile.

The CLI interface is not in use now.

* fix: fixed build.sh
  • Loading branch information
tokers committed Dec 9, 2020
1 parent 939b749 commit ca028cd
Show file tree
Hide file tree
Showing 9 changed files with 379 additions and 152 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@

.idea
.DS_Store
apisix-ingress-controller
33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# 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.
#
default: help

### build: Build apisix-ingress-controller
build:
go build -o apisix-ingress-controller main.go

### lint: Do static lint check
lint:
golangci-lint run

### help: Show Makefile rules
help:
@echo Makefile rules:
@echo
@grep -E '^### [-A-Za-z0-9_]+:' Makefile | sed 's/###/ /'

.PHONY: build lint help
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ 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
exec ./ingress-controller ingress

19 changes: 19 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"github.com/spf13/cobra"

"github.com/api7/ingress-controller/cmd/ingress"
)

// NewAPISIXIngressControllerCommand creates the apisix-ingress-controller command.
func NewAPISIXIngressControllerCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "apisix-ingress-controller [command]",
Long: "Yet another Ingress controller for Kubernetes using Apache APISIX as the high performance reverse proxy. Please note that all flags in this command line is not in use for now, but will be enabled in the near future.",
Version: "", // TODO: fill the version info.
}

cmd.AddCommand(ingress.NewIngressCommand())
return cmd
}
75 changes: 75 additions & 0 deletions cmd/ingress/ingress.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package ingress

import (
"flag"
"net/http"
"time"

"github.com/golang/glog"
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/log"
"github.com/api7/ingress-controller/pkg"
"github.com/api7/ingress-controller/pkg/ingress/controller"
)

// NewIngressCommand creates the ingress sub command for apisix-ingress-controller.
func NewIngressCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "ingress [flags]",
Short: "launch the controller",
Example: `Run apisix-ingress-controller from configuration file:
apisix-ingress-controller ingress --config-path /path/to/config.json`,
Run: func(cmd *cobra.Command, args []string) {
flag.Parse()
defer glog.Flush()
var logger = log.GetLogger()
kubeClientSet := conf.GetKubeClient()
apisixClientset := conf.InitApisixClient()
sharedInformerFactory := api6Informers.NewSharedInformerFactory(apisixClientset, 0)
stop := make(chan struct{})
c := &controller.Api6Controller{
KubeClientSet: kubeClientSet,
Api6ClientSet: apisixClientset,
SharedInformerFactory: sharedInformerFactory,
CoreSharedInformerFactory: conf.CoreSharedInformerFactory,
Stop: stop,
}
epInformer := c.CoreSharedInformerFactory.Core().V1().Endpoints()
conf.EndpointsInformer = epInformer
// endpoint
c.Endpoint()
go c.CoreSharedInformerFactory.Start(stop)

// ApisixRoute
c.ApisixRoute()
// ApisixUpstream
c.ApisixUpstream()
// ApisixService
c.ApisixService()

go func() {
time.Sleep(time.Duration(10) * time.Second)
c.SharedInformerFactory.Start(stop)
}()

router := pkg.Route()
err := http.ListenAndServe(":8080", router)
if err != nil {
logger.Fatal("ListenAndServe: ", err)
}
},
}

// TODO: Uncomment these lines.
// cmd.PersistentFlags().StringVar(&configPath, "config-path", "", "file path for the configuration of apisix-ingress-controller")
// cmd.PersistentFlags().StringVar(&conf.Kubeconfig, "kubeconfig", "", "Kubernetes configuration file (by default in-cluster configuration will be used)")
// cmd.PersistentFlags().StringSliceVar(&conf.Etcd.Endpoints, "etcd-endpoints", nil, "etcd endpoints")
// cmd.PersistentFlags().StringVar(&conf.APISIX.BaseURL, "apisix-base-url", "", "the base URL for APISIX instance")
// cmd.PersistentFlags().StringVar(&conf.SyslogServer, "syslog-server", "", "syslog server address")

return cmd
}
2 changes: 1 addition & 1 deletion conf/conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
"base_url": "http://172.16.20.90:30116/apisix/admin"
}
}
}
}
16 changes: 4 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,18 @@ module github.com/api7/ingress-controller
go 1.13

require (
github.com/coreos/etcd v3.3.18+incompatible
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7 // indirect
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/google/uuid v1.1.1 // indirect
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.3.0
github.com/pkg/errors v0.8.1
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.3.5
go.uber.org/zap v1.13.0 // indirect
google.golang.org/genproto v0.0.0-20191205163323-51378566eb59 // indirect
google.golang.org/grpc v1.25.1 // indirect
gopkg.in/resty.v1 v1.12.0
gopkg.in/yaml.v2 v2.2.4
github.com/tidwall/gjson v1.6.4
gopkg.in/yaml.v2 v2.2.8
k8s.io/api v0.0.0-20190819141258-3544db3b9e44
k8s.io/apimachinery v0.0.0-20190817020851-f2f3a405f61d
k8s.io/client-go v0.0.0-20190819141724-e14f31a72a77
Expand Down

0 comments on commit ca028cd

Please sign in to comment.