Add context object to kubecfg/client

pull/6/head
derekwaynecarr 2014-09-30 14:27:19 -04:00
parent 33afc2f210
commit b7b1193919
6 changed files with 25 additions and 12 deletions

View File

@ -27,6 +27,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver" "github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/capabilities" "github.com/GoogleCloudPlatform/kubernetes/pkg/capabilities"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
@ -126,7 +127,8 @@ func main() {
Port: *minionPort, Port: *minionPort,
} }
client, err := client.New(net.JoinHostPort(*address, strconv.Itoa(int(*port))), *storageVersion, nil) ctx := api.NewContext()
client, err := client.New(ctx, net.JoinHostPort(*address, strconv.Itoa(int(*port))), *storageVersion, nil)
if err != nil { if err != nil {
glog.Fatalf("Invalid server address: %v", err) glog.Fatalf("Invalid server address: %v", err)
} }

View File

@ -27,6 +27,7 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller" "github.com/GoogleCloudPlatform/kubernetes/pkg/controller"
@ -53,8 +54,8 @@ func main() {
if len(*master) == 0 { if len(*master) == 0 {
glog.Fatal("usage: controller-manager -master <master>") glog.Fatal("usage: controller-manager -master <master>")
} }
ctx := api.NewContext()
kubeClient, err := client.New(*master, latest.OldestVersion, nil) kubeClient, err := client.New(ctx, *master, latest.OldestVersion, nil)
if err != nil { if err != nil {
glog.Fatalf("Invalid -master: %v", err) glog.Fatalf("Invalid -master: %v", err)
} }

View File

@ -173,7 +173,11 @@ func main() {
} else { } else {
masterServer = "http://localhost:8080" masterServer = "http://localhost:8080"
} }
kubeClient, err := client.New(masterServer, *apiVersion, nil)
// TODO: get the namespace context when kubecfg ns is completed
ctx := api.NewContext()
kubeClient, err := client.New(ctx, masterServer, *apiVersion, nil)
if err != nil { if err != nil {
glog.Fatalf("Can't configure client: %v", err) glog.Fatalf("Can't configure client: %v", err)
} }
@ -194,7 +198,7 @@ func main() {
if *keyFile != "" { if *keyFile != "" {
auth.KeyFile = *keyFile auth.KeyFile = *keyFile
} }
kubeClient, err = client.New(masterServer, *apiVersion, auth) kubeClient, err = client.New(ctx, masterServer, *apiVersion, auth)
if err != nil { if err != nil {
glog.Fatalf("Can't configure client: %v", err) glog.Fatalf("Can't configure client: %v", err)
} }

View File

@ -20,6 +20,7 @@ import (
"flag" "flag"
"time" "time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/proxy" "github.com/GoogleCloudPlatform/kubernetes/pkg/proxy"
@ -54,8 +55,9 @@ func main() {
// define api config source // define api config source
if *master != "" { if *master != "" {
glog.Infof("Using api calls to get config %v", *master) glog.Infof("Using api calls to get config %v", *master)
ctx := api.NewContext()
//TODO: add auth info //TODO: add auth info
client, err := client.New(*master, latest.OldestVersion, nil) client, err := client.New(ctx, *master, latest.OldestVersion, nil)
if err != nil { if err != nil {
glog.Fatalf("Invalid -master: %v", err) glog.Fatalf("Invalid -master: %v", err)
} }

View File

@ -102,7 +102,7 @@ type Client struct {
// to a URL will prepend the server path. The API version to use may be specified or left // to a URL will prepend the server path. The API version to use may be specified or left
// empty to use the client preferred version. Returns an error if host cannot be converted to // empty to use the client preferred version. Returns an error if host cannot be converted to
// a valid URL. // a valid URL.
func New(host, version string, auth *AuthInfo) (*Client, error) { func New(ctx api.Context, host, version string, auth *AuthInfo) (*Client, error) {
if version == "" { if version == "" {
// Clients default to the preferred code API version // Clients default to the preferred code API version
// TODO: implement version negotation (highest version supported by server) // TODO: implement version negotation (highest version supported by server)
@ -113,7 +113,7 @@ func New(host, version string, auth *AuthInfo) (*Client, error) {
return nil, fmt.Errorf("API version '%s' is not recognized (valid values: %s)", version, strings.Join(latest.Versions, ", ")) return nil, fmt.Errorf("API version '%s' is not recognized (valid values: %s)", version, strings.Join(latest.Versions, ", "))
} }
prefix := fmt.Sprintf("/api/%s/", version) prefix := fmt.Sprintf("/api/%s/", version)
restClient, err := NewRESTClient(host, auth, prefix, versionInterfaces.Codec) restClient, err := NewRESTClient(ctx, host, auth, prefix, versionInterfaces.Codec)
if err != nil { if err != nil {
return nil, fmt.Errorf("API URL '%s' is not valid: %v", host, err) return nil, fmt.Errorf("API URL '%s' is not valid: %v", host, err)
} }
@ -121,8 +121,8 @@ func New(host, version string, auth *AuthInfo) (*Client, error) {
} }
// NewOrDie creates a Kubernetes client and panics if the provided host is invalid. // NewOrDie creates a Kubernetes client and panics if the provided host is invalid.
func NewOrDie(host, version string, auth *AuthInfo) *Client { func NewOrDie(ctx api.Context, host, version string, auth *AuthInfo) *Client {
client, err := New(host, version, auth) client, err := New(ctx, host, version, auth)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -152,6 +152,7 @@ type AuthInfo struct {
// Kubernetes API pattern. // Kubernetes API pattern.
// Host is the http://... base for the URL // Host is the http://... base for the URL
type RESTClient struct { type RESTClient struct {
ctx api.Context
host string host string
prefix string prefix string
secure bool secure bool
@ -165,7 +166,7 @@ type RESTClient struct {
// NewRESTClient creates a new RESTClient. This client performs generic REST functions // NewRESTClient creates a new RESTClient. This client performs generic REST functions
// such as Get, Put, Post, and Delete on specified paths. // such as Get, Put, Post, and Delete on specified paths.
func NewRESTClient(host string, auth *AuthInfo, path string, c runtime.Codec) (*RESTClient, error) { func NewRESTClient(ctx api.Context, host string, auth *AuthInfo, path string, c runtime.Codec) (*RESTClient, error) {
prefix, err := normalizePrefix(host, path) prefix, err := normalizePrefix(host, path)
if err != nil { if err != nil {
return nil, err return nil, err
@ -202,6 +203,7 @@ func NewRESTClient(host string, auth *AuthInfo, path string, c runtime.Codec) (*
} }
return &RESTClient{ return &RESTClient{
ctx: ctx,
host: base.String(), host: base.String(),
prefix: prefix.Path, prefix: prefix.Path,
secure: prefix.Scheme == "https", secure: prefix.Scheme == "https",

View File

@ -22,6 +22,7 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz" _ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz"
@ -47,7 +48,8 @@ func main() {
verflag.PrintAndExitIfRequested() verflag.PrintAndExitIfRequested()
// TODO: security story for plugins! // TODO: security story for plugins!
kubeClient, err := client.New(*master, latest.OldestVersion, nil) ctx := api.NewContext()
kubeClient, err := client.New(ctx, *master, latest.OldestVersion, nil)
if err != nil { if err != nil {
glog.Fatalf("Invalid -master: %v", err) glog.Fatalf("Invalid -master: %v", err)
} }