mirror of https://github.com/k3s-io/k3s
Add context object to kubecfg/client
parent
33afc2f210
commit
b7b1193919
|
@ -27,6 +27,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/capabilities"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
|
@ -126,7 +127,8 @@ func main() {
|
|||
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 {
|
||||
glog.Fatalf("Invalid server address: %v", err)
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller"
|
||||
|
@ -53,8 +54,8 @@ func main() {
|
|||
if len(*master) == 0 {
|
||||
glog.Fatal("usage: controller-manager -master <master>")
|
||||
}
|
||||
|
||||
kubeClient, err := client.New(*master, latest.OldestVersion, nil)
|
||||
ctx := api.NewContext()
|
||||
kubeClient, err := client.New(ctx, *master, latest.OldestVersion, nil)
|
||||
if err != nil {
|
||||
glog.Fatalf("Invalid -master: %v", err)
|
||||
}
|
||||
|
|
|
@ -173,7 +173,11 @@ func main() {
|
|||
} else {
|
||||
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 {
|
||||
glog.Fatalf("Can't configure client: %v", err)
|
||||
}
|
||||
|
@ -194,7 +198,7 @@ func main() {
|
|||
if *keyFile != "" {
|
||||
auth.KeyFile = *keyFile
|
||||
}
|
||||
kubeClient, err = client.New(masterServer, *apiVersion, auth)
|
||||
kubeClient, err = client.New(ctx, masterServer, *apiVersion, auth)
|
||||
if err != nil {
|
||||
glog.Fatalf("Can't configure client: %v", err)
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"flag"
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/proxy"
|
||||
|
@ -54,8 +55,9 @@ func main() {
|
|||
// define api config source
|
||||
if *master != "" {
|
||||
glog.Infof("Using api calls to get config %v", *master)
|
||||
ctx := api.NewContext()
|
||||
//TODO: add auth info
|
||||
client, err := client.New(*master, latest.OldestVersion, nil)
|
||||
client, err := client.New(ctx, *master, latest.OldestVersion, nil)
|
||||
if err != nil {
|
||||
glog.Fatalf("Invalid -master: %v", err)
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -22,6 +22,7 @@ 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"
|
||||
|
@ -47,7 +48,8 @@ func main() {
|
|||
verflag.PrintAndExitIfRequested()
|
||||
|
||||
// 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 {
|
||||
glog.Fatalf("Invalid -master: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue