Refactor the client (again) to better support auth

* Allows consumers to provide their own transports for common cases.
* Supports KUBE_API_VERSION on test cases for controlling which
  api version they test against
* Provides a common flag registration method for CLIs that need
  to connect to an API server (to avoid duplicating flags)
* Ensures errors are properly returned by the server
* Add a Context field to client.Config
This commit is contained in:
Clayton Coleman
2014-09-29 20:15:00 -04:00
parent 88bf01b008
commit ff2eca97d9
26 changed files with 1281 additions and 704 deletions

View File

@@ -22,8 +22,6 @@ import (
"net/http"
"strconv"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz"
masterPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/master"
@@ -35,11 +33,15 @@ import (
)
var (
master = flag.String("master", "", "The address of the Kubernetes API server")
port = flag.Int("port", masterPkg.SchedulerPort, "The port that the scheduler's http service runs on")
address = flag.String("address", "127.0.0.1", "The address to serve from")
port = flag.Int("port", masterPkg.SchedulerPort, "The port that the scheduler's http service runs on")
address = flag.String("address", "127.0.0.1", "The address to serve from")
clientConfig = &client.Config{}
)
func init() {
client.BindClientConfigFlags(flag.CommandLine, clientConfig)
}
func main() {
flag.Parse()
util.InitLogs()
@@ -47,11 +49,9 @@ func main() {
verflag.PrintAndExitIfRequested()
// TODO: security story for plugins!
ctx := api.NewContext()
kubeClient, err := client.New(ctx, *master, latest.OldestVersion, nil)
kubeClient, err := client.New(clientConfig)
if err != nil {
glog.Fatalf("Invalid -master: %v", err)
glog.Fatalf("Invalid API configuration: %v", err)
}
go http.ListenAndServe(net.JoinHostPort(*address, strconv.Itoa(*port)), nil)