From 28af678748443fbc15357eb2b7b70cfce9a088ad Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 26 Sep 2019 19:14:16 +0800 Subject: [PATCH] fix apigateway clientset bug --- cmd/hypersphere/hypersphere.go | 3 +++ cmd/ks-apigateway/apiserver.go | 14 +++++----- cmd/ks-apigateway/app/server.go | 46 +++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 cmd/ks-apigateway/app/server.go diff --git a/cmd/hypersphere/hypersphere.go b/cmd/hypersphere/hypersphere.go index 13ad5cdfe..08d901b5b 100644 --- a/cmd/hypersphere/hypersphere.go +++ b/cmd/hypersphere/hypersphere.go @@ -8,6 +8,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" controllermanager "kubesphere.io/kubesphere/cmd/controller-manager/app" + ksapigateway "kubesphere.io/kubesphere/cmd/ks-apigateway/app" ksapiserver "kubesphere.io/kubesphere/cmd/ks-apiserver/app" ksaiam "kubesphere.io/kubesphere/cmd/ks-iam/app" "os" @@ -46,11 +47,13 @@ func NewHyperSphereCommand() (*cobra.Command, []func() *cobra.Command) { apiserver := func() *cobra.Command { return ksapiserver.NewAPIServerCommand() } controllermanager := func() *cobra.Command { return controllermanager.NewControllerManagerCommand() } iam := func() *cobra.Command { return ksaiam.NewAPIServerCommand() } + apigateway := func() *cobra.Command { return ksapigateway.NewAPIGatewayCommand() } commandFns := []func() *cobra.Command{ apiserver, controllermanager, iam, + apigateway, } cmd := &cobra.Command{ diff --git a/cmd/ks-apigateway/apiserver.go b/cmd/ks-apigateway/apiserver.go index 808f093cc..4191a9521 100644 --- a/cmd/ks-apigateway/apiserver.go +++ b/cmd/ks-apigateway/apiserver.go @@ -18,8 +18,8 @@ package main import ( - "github.com/mholt/caddy/caddy/caddymain" - "github.com/mholt/caddy/caddyhttp/httpserver" + "kubesphere.io/kubesphere/cmd/ks-apigateway/app" + "os" // Install apis _ "kubesphere.io/kubesphere/pkg/apigateway/caddy-plugin/authenticate" @@ -28,8 +28,10 @@ import ( ) func main() { - httpserver.RegisterDevDirective("authenticate", "jwt") - httpserver.RegisterDevDirective("authentication", "jwt") - httpserver.RegisterDevDirective("swagger", "jwt") - caddymain.Run() + + cmd := app.NewAPIGatewayCommand() + + if err := cmd.Execute(); err != nil { + os.Exit(1) + } } diff --git a/cmd/ks-apigateway/app/server.go b/cmd/ks-apigateway/app/server.go new file mode 100644 index 000000000..e1a8751eb --- /dev/null +++ b/cmd/ks-apigateway/app/server.go @@ -0,0 +1,46 @@ +package app + +import ( + "github.com/mholt/caddy/caddy/caddymain" + "github.com/mholt/caddy/caddyhttp/httpserver" + "github.com/spf13/cobra" + apiserverconfig "kubesphere.io/kubesphere/pkg/server/config" + "kubesphere.io/kubesphere/pkg/simple/client" + "kubesphere.io/kubesphere/pkg/utils/signals" +) + +func NewAPIGatewayCommand() *cobra.Command { + + cmd := &cobra.Command{ + Use: "ks-apigateway", + Long: `The KubeSphere API Gateway, which is responsible +for proxy request to the right backend. API Gateway also proxy +Kubernetes API Server for KubeSphere authorization purpose. +`, + RunE: func(cmd *cobra.Command, args []string) error { + + err := apiserverconfig.Load() + if err != nil { + return err + } + + return Run(signals.SetupSignalHandler()) + }, + } + + return cmd +} + +func Run(stopCh <-chan struct{}) error { + + csop := &client.ClientSetOptions{} + csop.SetKubernetesOptions(apiserverconfig.Get().KubernetesOptions) + client.NewClientSetFactory(csop, stopCh) + + httpserver.RegisterDevDirective("authenticate", "jwt") + httpserver.RegisterDevDirective("authentication", "jwt") + httpserver.RegisterDevDirective("swagger", "jwt") + caddymain.Run() + + return nil +}