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

@@ -16,5 +16,6 @@ limitations under the License.
// Package latest defines the default output serializations that code should
// use and imports the required schemas. It also ensures all previously known
// and supported API versions are available for conversion.
// and supported API versions are available for conversion. Consumers may
// import this package in lieu of importing individual versions.
package latest

View File

@@ -17,13 +17,26 @@ limitations under the License.
package latest
import (
"fmt"
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta2"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta2"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
)
// Version is the string that represents the current external default version
var Version = "v1beta1"
// Version is the string that represents the current external default version.
const Version = "v1beta1"
// OldestVersion is the string that represents the oldest server version supported,
// for client code that wants to hardcode the lowest common denominator.
const OldestVersion = "v1beta1"
// Versions is the list of versions that are recognized in code. The order provided
// may be assumed to be least feature rich to most feature rich, and clients may
// choose to prefer the latter items in the list over the former items when presented
// with a set of versions to choose.
var Versions = []string{"v1beta1", "v1beta2"}
// Codec is the default codec for serializing output that should use
// the latest supported version. Use this Codec when writing to
@@ -35,3 +48,17 @@ var Codec = v1beta1.Codec
// of versioning.
// TODO: when versioning changes, make this part of each API definition.
var ResourceVersioner = runtime.NewJSONBaseResourceVersioner()
// InterfacesFor returns the default Codec and ResourceVersioner for a given version
// string, or an error if the version is not known.
func InterfacesFor(version string) (codec runtime.Codec, versioner runtime.ResourceVersioner, err error) {
switch version {
case "v1beta1":
codec, versioner = v1beta1.Codec, ResourceVersioner
case "v1beta2":
codec, versioner = v1beta2.Codec, ResourceVersioner
default:
err = fmt.Errorf("unsupported storage version: %s (valid: %s)", version, strings.Join(Versions, ", "))
}
return
}

View File

@@ -144,3 +144,14 @@ func TestCodec(t *testing.T) {
t.Errorf("unexpected unmarshalled object %#v", other)
}
}
func TestInterfacesFor(t *testing.T) {
if _, _, err := InterfacesFor(""); err == nil {
t.Fatalf("unexpected non-error: %v", err)
}
for i, version := range append([]string{Version, OldestVersion}, Versions...) {
if codec, versioner, err := InterfacesFor(version); err != nil || codec == nil || versioner == nil {
t.Fatalf("%d: unexpected result: %v", i, err)
}
}
}