-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: introduce a CLI interface and a Makefile. (#66)
* chore: introduce a CLI interface and a Makefile. The CLI interface is not in use now. * fix: fixed build.sh
- Loading branch information
Showing
9 changed files
with
379 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ | |
|
||
.idea | ||
.DS_Store | ||
apisix-ingress-controller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ | |
"base_url": "http://172.16.20.90:30116/apisix/admin" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.