Make listen-address configurable

This commit is contained in:
Darren Shepherd
2019-08-07 22:42:15 -07:00
parent 71faff9d2a
commit 8fe5d55dac
2 changed files with 18 additions and 13 deletions

View File

@@ -33,6 +33,12 @@ func main() {
Value: "default", Value: "default",
Destination: &config.Namespace, Destination: &config.Namespace,
}, },
cli.StringFlag{
Name: "listen-address",
EnvVar: "LISTEN_ADDRESS",
Value: ":8080",
Destination: &config.ListenAddress,
},
cli.BoolFlag{Name: "debug"}, cli.BoolFlag{Name: "debug"},
} }
app.Action = run app.Action = run

View File

@@ -4,8 +4,6 @@ import (
"context" "context"
"net/http" "net/http"
"github.com/rancher/norman/pkg/store/proxy"
"github.com/rancher/naok/pkg/accesscontrol" "github.com/rancher/naok/pkg/accesscontrol"
"github.com/rancher/naok/pkg/client" "github.com/rancher/naok/pkg/client"
"github.com/rancher/naok/pkg/schemas" "github.com/rancher/naok/pkg/schemas"
@@ -22,6 +20,7 @@ import (
type Config struct { type Config struct {
Kubeconfig string Kubeconfig string
Namespace string Namespace string
ListenAddress string
} }
func Run(ctx context.Context, cfg Config) error { func Run(ctx context.Context, cfg Config) error {
@@ -50,7 +49,7 @@ func Run(ctx context.Context, cfg Config) error {
return err return err
} }
starter, err := startAPI(ctx, restConfig, k8s, crd, api, rbac) starter, err := startAPI(ctx, cfg.ListenAddress, restConfig, k8s, crd, api, rbac)
if err != nil { if err != nil {
return err return err
} }
@@ -67,7 +66,7 @@ func Run(ctx context.Context, cfg Config) error {
return nil return nil
} }
func startAPI(ctx context.Context, restConfig *rest.Config, k8s *kubernetes.Clientset, crd *apiextensions.Factory, func startAPI(ctx context.Context, listenAddress string, restConfig *rest.Config, k8s *kubernetes.Clientset, crd *apiextensions.Factory,
api *apiregistration.Factory, rbac *rbaccontroller.Factory) (func() error, error) { api *apiregistration.Factory, rbac *rbaccontroller.Factory) (func() error, error) {
cf, err := client.NewFactory(restConfig) cf, err := client.NewFactory(restConfig)
@@ -82,14 +81,14 @@ func startAPI(ctx context.Context, restConfig *rest.Config, k8s *kubernetes.Clie
api.Apiregistration().V1().APIService(), api.Apiregistration().V1().APIService(),
) )
accessStore := accesscontrol.NewAccessStore(rbac.Rbac().V1()) as := accesscontrol.NewAccessStore(rbac.Rbac().V1())
return func() error { return func() error {
return serve(cf, accessStore, sf) handler, err := newAPIServer(restConfig, cf, as, sf)
if err != nil {
return err
}
logrus.Infof("listening on %s", listenAddress)
return http.ListenAndServe(listenAddress, handler)
}, nil }, nil
} }
func serve(cf proxy.ClientGetter, as *accesscontrol.AccessStore, sf schemas.SchemaFactory) error {
logrus.Infof("listening on :8989")
return http.ListenAndServe(":8989", newAPIServer(cf, as, sf))
}