mirror of
https://github.com/niusmallnan/steve.git
synced 2025-09-11 01:49:42 +00:00
Make listen-address configurable
This commit is contained in:
6
main.go
6
main.go
@@ -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
|
||||||
|
@@ -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"
|
||||||
@@ -20,8 +18,9 @@ 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))
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user