Allow server and client to take api version as argument

* Defaults to v1beta1
* apiserver takes -storage_version which controls etcd storage version
  and the version of the client used to connect to other apiservers
* Changed signature of client.New to add version parameter
* All controller code and component code prefers the oldest (most common)
  server version
This commit is contained in:
Clayton Coleman
2014-09-11 19:01:29 -04:00
parent ca5355908f
commit 5483333e29
22 changed files with 309 additions and 164 deletions

View File

@@ -38,15 +38,16 @@ import (
)
var (
port = flag.Uint("port", 8080, "The port to listen on. Default 8080.")
port = flag.Uint("port", 8080, "The port to listen on. Default 8080")
address = flag.String("address", "127.0.0.1", "The address on the local server to listen to. Default 127.0.0.1")
apiPrefix = flag.String("api_prefix", "/api", "The prefix for API requests on the server. Default '/api'")
storageVersion = flag.String("storage_version", "", "The version to store resources with. Defaults to server preferred")
cloudProvider = flag.String("cloud_provider", "", "The provider for cloud services. Empty string for no provider.")
cloudConfigFile = flag.String("cloud_config", "", "The path to the cloud provider configuration file. Empty string for no configuration file.")
minionRegexp = flag.String("minion_regexp", "", "If non empty, and -cloud_provider is specified, a regular expression for matching minion VMs")
minionPort = flag.Uint("minion_port", 10250, "The port at which kubelet will be listening on the minions.")
healthCheckMinions = flag.Bool("health_check_minions", true, "If true, health check minions and filter unhealthy ones. [default true]")
minionCacheTTL = flag.Duration("minion_cache_ttl", 30*time.Second, "Duration of time to cache minion information. [default 30 seconds]")
healthCheckMinions = flag.Bool("health_check_minions", true, "If true, health check minions and filter unhealthy ones. Default true")
minionCacheTTL = flag.Duration("minion_cache_ttl", 30*time.Second, "Duration of time to cache minion information. Default 30 seconds")
etcdServerList util.StringList
machineList util.StringList
corsAllowedOriginList util.StringList
@@ -125,15 +126,20 @@ func main() {
Port: *minionPort,
}
client, err := client.New(net.JoinHostPort(*address, strconv.Itoa(int(*port))), nil)
client, err := client.New(net.JoinHostPort(*address, strconv.Itoa(int(*port))), *storageVersion, nil)
if err != nil {
glog.Fatalf("Invalid server address: %v", err)
}
helper, err := master.NewEtcdHelper(etcdServerList, *storageVersion)
if err != nil {
glog.Fatalf("Invalid storage version: %v", err)
}
m := master.New(&master.Config{
Client: client,
Cloud: cloud,
EtcdServers: etcdServerList,
EtcdHelper: helper,
HealthCheckMinions: *healthCheckMinions,
Minions: machineList,
MinionCacheTTL: *minionCacheTTL,

View File

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

View File

@@ -106,19 +106,27 @@ func startComponents(manifestURL string) (apiServerURL string) {
}
}
cl := client.NewOrDie(apiServer.URL, nil)
cl := client.NewOrDie(apiServer.URL, "", nil)
cl.PollPeriod = time.Second * 1
cl.Sync = true
helper, err := master.NewEtcdHelper(servers, "")
if err != nil {
glog.Fatalf("Unable to get etcd helper: %v", err)
}
// Master
m := master.New(&master.Config{
Client: cl,
EtcdServers: servers,
EtcdHelper: helper,
Minions: machineList,
PodInfoGetter: fakePodInfoGetter{},
})
storage, codec := m.API_v1beta1()
handler.delegate = apiserver.Handle(storage, codec, "/api/v1beta1")
mux := http.NewServeMux()
apiserver.NewAPIGroup(m.API_v1beta1()).InstallREST(mux, "/api/v1beta1")
apiserver.NewAPIGroup(m.API_v1beta2()).InstallREST(mux, "/api/v1beta2")
apiserver.InstallSupport(mux)
handler.delegate = mux
// Scheduler
scheduler.New((&factory.ConfigFactory{cl}).Create()).Run()
@@ -303,7 +311,7 @@ func main() {
// Wait for the synchronization threads to come up.
time.Sleep(time.Second * 10)
kubeClient := client.NewOrDie(apiServerURL, nil)
kubeClient := client.NewOrDie(apiServerURL, "", nil)
// Run tests in parallel
testFuncs := []testFunc{

View File

@@ -58,6 +58,7 @@ var (
templateFile = flag.String("template_file", "", "If present, load this file as a golang template and use it for output printing")
templateStr = flag.String("template", "", "If present, parse this string as a golang template and use it for output printing")
imageName = flag.String("image", "", "Image used when updating a replicationController. Will apply to the first container in the pod template.")
apiVersion = flag.String("api_version", latest.Version, "The version of the API to use against this server.")
)
var parser = kubecfg.NewParser(map[string]runtime.Object{
@@ -125,12 +126,12 @@ func readConfigData() []byte {
// readConfig reads and parses pod, replicationController, and service
// configuration files. If any errors log and exit non-zero.
func readConfig(storage string) []byte {
func readConfig(storage string, serverCodec runtime.Codec) []byte {
if len(*config) == 0 {
glog.Fatal("Need config file (-c)")
}
data, err := parser.ToWireFormat(readConfigData(), storage, latest.Codec)
data, err := parser.ToWireFormat(readConfigData(), storage, latest.Codec, serverCodec)
if err != nil {
glog.Fatalf("Error parsing %v as an object for %v: %v\n", *config, storage, err)
@@ -160,9 +161,9 @@ func main() {
} else {
masterServer = "http://localhost:8080"
}
kubeClient, err := client.New(masterServer, nil)
kubeClient, err := client.New(masterServer, *apiVersion, nil)
if err != nil {
glog.Fatalf("Unable to parse %s as a URL: %v", masterServer, err)
glog.Fatalf("Can't configure client: %v", err)
}
// TODO: this won't work if TLS is enabled with client cert auth, but no
@@ -172,9 +173,9 @@ func main() {
if err != nil {
glog.Fatalf("Error loading auth: %v", err)
}
kubeClient, err = client.New(masterServer, auth)
kubeClient, err = client.New(masterServer, *apiVersion, auth)
if err != nil {
glog.Fatalf("Unable to parse %s as a URL: %v", masterServer, err)
glog.Fatalf("Can't configure client: %v", err)
}
}
@@ -296,7 +297,7 @@ func executeAPIRequest(method string, c *client.Client) bool {
ParseSelectorParam("labels", *selector)
if setBody {
if version != 0 {
data := readConfig(storage)
data := readConfig(storage, c.RESTClient.Codec)
obj, err := latest.Codec.Decode(data)
if err != nil {
glog.Fatalf("error setting resource version: %v", err)
@@ -306,13 +307,13 @@ func executeAPIRequest(method string, c *client.Client) bool {
glog.Fatalf("error setting resource version: %v", err)
}
jsonBase.SetResourceVersion(version)
data, err = latest.Codec.Encode(obj)
data, err = c.RESTClient.Codec.Encode(obj)
if err != nil {
glog.Fatalf("error setting resource version: %v", err)
}
r.Body(data)
} else {
r.Body(readConfig(storage))
r.Body(readConfig(storage, c.RESTClient.Codec))
}
}
result := r.Do()

View File

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