Add context object to kubecfg/client

This commit is contained in:
derekwaynecarr
2014-09-30 14:27:19 -04:00
parent 33afc2f210
commit b7b1193919
6 changed files with 25 additions and 12 deletions

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
// empty to use the client preferred version. Returns an error if host cannot be converted to
// 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 == "" {
// Clients default to the preferred code API version
// 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, ", "))
}
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 {
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.
func NewOrDie(host, version string, auth *AuthInfo) *Client {
client, err := New(host, version, auth)
func NewOrDie(ctx api.Context, host, version string, auth *AuthInfo) *Client {
client, err := New(ctx, host, version, auth)
if err != nil {
panic(err)
}
@@ -152,6 +152,7 @@ type AuthInfo struct {
// Kubernetes API pattern.
// Host is the http://... base for the URL
type RESTClient struct {
ctx api.Context
host string
prefix string
secure bool
@@ -165,7 +166,7 @@ type RESTClient struct {
// NewRESTClient creates a new RESTClient. This client performs generic REST functions
// 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)
if err != nil {
return nil, err
@@ -202,6 +203,7 @@ func NewRESTClient(host string, auth *AuthInfo, path string, c runtime.Codec) (*
}
return &RESTClient{
ctx: ctx,
host: base.String(),
prefix: prefix.Path,
secure: prefix.Scheme == "https",