Merge pull request #1623 from smarterclayton/rename_jsonbase

Rename JSONBase -> TypeMeta in preparation for v1beta3
This commit is contained in:
Daniel Smith
2014-10-07 10:50:28 -07:00
70 changed files with 466 additions and 466 deletions

View File

@@ -64,7 +64,7 @@ func NamespaceFrom(ctx Context) (string, bool) {
}
// ValidNamespace returns false if the namespace on the context differs from the resource. If the resource has no namespace, it is set to the value in the context.
func ValidNamespace(ctx Context, resource *JSONBase) bool {
func ValidNamespace(ctx Context, resource *TypeMeta) bool {
ns, ok := NamespaceFrom(ctx)
if len(resource.Namespace) == 0 {
resource.Namespace = ns

View File

@@ -45,18 +45,18 @@ func TestValidNamespace(t *testing.T) {
ctx := api.NewDefaultContext()
namespace, _ := api.NamespaceFrom(ctx)
resource := api.ReplicationController{}
if !api.ValidNamespace(ctx, &resource.JSONBase) {
if !api.ValidNamespace(ctx, &resource.TypeMeta) {
t.Errorf("expected success")
}
if namespace != resource.Namespace {
t.Errorf("expected resource to have the default namespace assigned during validation")
}
resource = api.ReplicationController{JSONBase: api.JSONBase{Namespace: "other"}}
if api.ValidNamespace(ctx, &resource.JSONBase) {
resource = api.ReplicationController{TypeMeta: api.TypeMeta{Namespace: "other"}}
if api.ValidNamespace(ctx, &resource.TypeMeta) {
t.Errorf("Expected error that resource and context errors do not match because resource has different namespace")
}
ctx = api.NewContext()
if api.ValidNamespace(ctx, &resource.JSONBase) {
if api.ValidNamespace(ctx, &resource.TypeMeta) {
t.Errorf("Expected error that resource and context errors do not match since context has no namespace")
}
}

View File

@@ -47,13 +47,13 @@ var Codec = v1beta1.Codec
// ResourceVersioner describes a default versioner that can handle all types
// of versioning.
// TODO: when versioning changes, make this part of each API definition.
var ResourceVersioner = runtime.NewJSONBaseResourceVersioner()
var ResourceVersioner = runtime.NewTypeMetaResourceVersioner()
// SelfLinker can set or get the SelfLink field of all API types.
// TODO: when versioning changes, make this part of each API definition.
// TODO(lavalamp): Combine SelfLinker & ResourceVersioner interfaces, force all uses
// to go through the InterfacesFor method below.
var SelfLinker = runtime.NewJSONBaseSelfLinker()
var SelfLinker = runtime.NewTypeMetaSelfLinker()
// VersionInterfaces contains the interfaces one should use for dealing with types of a particular version.
type VersionInterfaces struct {

View File

@@ -32,8 +32,8 @@ import (
// apiObjectFuzzer can randomly populate api objects.
var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
func(j *internal.JSONBase, c fuzz.Continue) {
// We have to customize the randomization of JSONBases because their
func(j *internal.TypeMeta, c fuzz.Continue) {
// We have to customize the randomization of TypeMetas because their
// APIVersion and Kind must remain blank in memory.
j.APIVersion = ""
j.Kind = ""
@@ -120,7 +120,7 @@ func TestInternalRoundTrip(t *testing.T) {
}
func TestResourceVersioner(t *testing.T) {
pod := internal.Pod{JSONBase: internal.JSONBase{ResourceVersion: 10}}
pod := internal.Pod{TypeMeta: internal.TypeMeta{ResourceVersion: 10}}
version, err := ResourceVersioner.ResourceVersion(&pod)
if err != nil {
t.Fatalf("unexpected error: %v", err)

View File

@@ -29,7 +29,7 @@ var versionFromSelfLink = regexp.MustCompile("/api/([^/]*)/")
// object, or an error if the object doesn't follow the conventions
// that would allow this.
func GetReference(obj runtime.Object) (*ObjectReference, error) {
jsonBase, err := runtime.FindJSONBase(obj)
jsonBase, err := runtime.FindTypeMeta(obj)
if err != nil {
return nil, err
}
@@ -44,7 +44,7 @@ func GetReference(obj runtime.Object) (*ObjectReference, error) {
return &ObjectReference{
Kind: kind,
APIVersion: version[1],
// TODO: correct Name and UID when JSONBase makes a distinction
// TODO: correct Name and UID when TypeMeta makes a distinction
Name: jsonBase.ID(),
UID: jsonBase.ID(),
ResourceVersion: jsonBase.ResourceVersion(),

View File

@@ -35,7 +35,7 @@ func TestGetReference(t *testing.T) {
}{
"pod": {
obj: &Pod{
JSONBase: JSONBase{
TypeMeta: TypeMeta{
ID: "foo",
ResourceVersion: 42,
SelfLink: "/api/v1beta1/pods/foo",
@@ -51,7 +51,7 @@ func TestGetReference(t *testing.T) {
},
"serviceList": {
obj: &ServiceList{
JSONBase: JSONBase{
TypeMeta: TypeMeta{
ID: "foo",
ResourceVersion: 42,
SelfLink: "/api/v1beta2/services",
@@ -67,7 +67,7 @@ func TestGetReference(t *testing.T) {
},
"badSelfLink": {
obj: &ServiceList{
JSONBase: JSONBase{
TypeMeta: TypeMeta{
ID: "foo",
ResourceVersion: 42,
SelfLink: "v1beta2/services",

View File

@@ -40,8 +40,8 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
func(j *runtime.PluginBase, c fuzz.Continue) {
// Do nothing; this struct has only a Kind field and it must stay blank in memory.
},
func(j *runtime.JSONBase, c fuzz.Continue) {
// We have to customize the randomization of JSONBases because their
func(j *runtime.TypeMeta, c fuzz.Continue) {
// We have to customize the randomization of TypeMetas because their
// APIVersion and Kind must remain blank in memory.
j.APIVersion = ""
j.Kind = ""
@@ -57,8 +57,8 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
c.Fuzz(&nsec)
j.CreationTimestamp = util.Unix(sec, nsec).Rfc3339Copy()
},
func(j *api.JSONBase, c fuzz.Continue) {
// We have to customize the randomization of JSONBases because their
func(j *api.TypeMeta, c fuzz.Continue) {
// We have to customize the randomization of TypeMetas because their
// APIVersion and Kind must remain blank in memory.
j.APIVersion = ""
j.Kind = ""
@@ -110,7 +110,7 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
func runTest(t *testing.T, codec runtime.Codec, source runtime.Object) {
name := reflect.TypeOf(source).Elem().Name()
apiObjectFuzzer.Fuzz(source)
j, err := runtime.FindJSONBase(source)
j, err := runtime.FindTypeMeta(source)
if err != nil {
t.Fatalf("Unexpected error %v for %#v", err, source)
}

View File

@@ -65,7 +65,7 @@ type ContainerManifest struct {
// ContainerManifestList is used to communicate container manifests to kubelet.
type ContainerManifestList struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
Items []ContainerManifest `json:"items,omitempty" yaml:"items,omitempty"`
}
@@ -244,8 +244,8 @@ type Lifecycle struct {
// The below types are used by kube_client and api_server.
// JSONBase is shared by all objects sent to, or returned from the client.
type JSONBase struct {
// TypeMeta is shared by all objects sent to, or returned from the client.
type TypeMeta struct {
Kind string `json:"kind,omitempty" yaml:"kind,omitempty"`
ID string `json:"id,omitempty" yaml:"id,omitempty"`
CreationTimestamp util.Time `json:"creationTimestamp,omitempty" yaml:"creationTimestamp,omitempty"`
@@ -353,7 +353,7 @@ type PodState struct {
// PodList is a list of Pods.
type PodList struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
Items []Pod `json:"items" yaml:"items,omitempty"`
}
@@ -361,7 +361,7 @@ func (*PodList) IsAnAPIObject() {}
// Pod is a collection of containers, used as either input (create, update) or as output (list, get).
type Pod struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
DesiredState PodState `json:"desiredState,omitempty" yaml:"desiredState,omitempty"`
CurrentState PodState `json:"currentState,omitempty" yaml:"currentState,omitempty"`
@@ -378,7 +378,7 @@ type ReplicationControllerState struct {
// ReplicationControllerList is a collection of replication controllers.
type ReplicationControllerList struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
Items []ReplicationController `json:"items,omitempty" yaml:"items,omitempty"`
}
@@ -386,7 +386,7 @@ func (*ReplicationControllerList) IsAnAPIObject() {}
// ReplicationController represents the configuration of a replication controller.
type ReplicationController struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
DesiredState ReplicationControllerState `json:"desiredState,omitempty" yaml:"desiredState,omitempty"`
CurrentState ReplicationControllerState `json:"currentState,omitempty" yaml:"currentState,omitempty"`
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
@@ -402,7 +402,7 @@ type PodTemplate struct {
// ServiceList holds a list of services.
type ServiceList struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
Items []Service `json:"items" yaml:"items"`
}
@@ -412,7 +412,7 @@ func (*ServiceList) IsAnAPIObject() {}
// (for example 3306) that the proxy listens on, and the selector that determines which pods
// will answer requests sent through the proxy.
type Service struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
// Required.
Port int `json:"port" yaml:"port"`
@@ -436,7 +436,7 @@ func (*Service) IsAnAPIObject() {}
// Endpoints is a collection of endpoints that implement the actual service, for example:
// Name: "mysql", Endpoints: ["10.10.1.1:1909", "10.10.2.2:8834"]
type Endpoints struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
Endpoints []string `json:"endpoints,omitempty" yaml:"endpoints,omitempty"`
}
@@ -444,7 +444,7 @@ func (*Endpoints) IsAnAPIObject() {}
// EndpointsList is a list of endpoints.
type EndpointsList struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
Items []Endpoints `json:"items,omitempty" yaml:"items,omitempty"`
}
@@ -463,9 +463,9 @@ type ResourceName string
type ResourceList map[ResourceName]util.IntOrString
// Minion is a worker node in Kubernetenes.
// The name of the minion according to etcd is in JSONBase.ID.
// The name of the minion according to etcd is in TypeMeta.ID.
type Minion struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
// Queried from cloud provider, if available.
HostIP string `json:"hostIP,omitempty" yaml:"hostIP,omitempty"`
// Resources available on the node
@@ -476,7 +476,7 @@ func (*Minion) IsAnAPIObject() {}
// MinionList is a list of minions.
type MinionList struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
Items []Minion `json:"items,omitempty" yaml:"items,omitempty"`
}
@@ -484,7 +484,7 @@ func (*MinionList) IsAnAPIObject() {}
// Binding is written by a scheduler to cause a pod to be bound to a host.
type Binding struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
PodID string `json:"podID" yaml:"podID"`
Host string `json:"host" yaml:"host"`
}
@@ -495,7 +495,7 @@ func (*Binding) IsAnAPIObject() {}
// TODO: this could go in apiserver, but I'm including it here so clients needn't
// import both.
type Status struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
// One of: "Success", "Failure", "Working" (for operations not yet completed)
Status string `json:"status,omitempty" yaml:"status,omitempty"`
// A human-readable description of the status of this operation.
@@ -649,14 +649,14 @@ const (
// ServerOp is an operation delivered to API clients.
type ServerOp struct {
JSONBase `yaml:",inline" json:",inline"`
TypeMeta `yaml:",inline" json:",inline"`
}
func (*ServerOp) IsAnAPIObject() {}
// ServerOpList is a list of operations, as delivered to API clients.
type ServerOpList struct {
JSONBase `yaml:",inline" json:",inline"`
TypeMeta `yaml:",inline" json:",inline"`
Items []ServerOp `yaml:"items,omitempty" json:"items,omitempty"`
}
@@ -683,7 +683,7 @@ type ObjectReference struct {
// Event is a report of an event somewhere in the cluster.
// TODO: Decide whether to store these separately or with the object they apply to.
type Event struct {
JSONBase `yaml:",inline" json:",inline"`
TypeMeta `yaml:",inline" json:",inline"`
// Required. The object that this event is about.
InvolvedObject ObjectReference `json:"involvedObject,omitempty" yaml:"involvedObject,omitempty"`
@@ -716,7 +716,7 @@ func (*Event) IsAnAPIObject() {}
// EventList is a list of events.
type EventList struct {
JSONBase `yaml:",inline" json:",inline"`
TypeMeta `yaml:",inline" json:",inline"`
Items []Event `yaml:"items,omitempty" json:"items,omitempty"`
}

View File

@@ -62,13 +62,13 @@ func init() {
// MinionList.Items had a wrong name in v1beta1
func(in *newer.MinionList, out *MinionList, s conversion.Scope) error {
s.Convert(&in.JSONBase, &out.JSONBase, 0)
s.Convert(&in.TypeMeta, &out.TypeMeta, 0)
s.Convert(&in.Items, &out.Items, 0)
out.Minions = out.Items
return nil
},
func(in *MinionList, out *newer.MinionList, s conversion.Scope) error {
s.Convert(&in.JSONBase, &out.JSONBase, 0)
s.Convert(&in.TypeMeta, &out.TypeMeta, 0)
if len(in.Items) == 0 {
s.Convert(&in.Minions, &out.Items, 0)
} else {

View File

@@ -116,10 +116,10 @@ func TestVolumeMountConversionToNew(t *testing.T) {
func TestMinionListConversionToNew(t *testing.T) {
oldMinion := func(id string) v1beta1.Minion {
return v1beta1.Minion{JSONBase: v1beta1.JSONBase{ID: id}}
return v1beta1.Minion{TypeMeta: v1beta1.TypeMeta{ID: id}}
}
newMinion := func(id string) newer.Minion {
return newer.Minion{JSONBase: newer.JSONBase{ID: id}}
return newer.Minion{TypeMeta: newer.TypeMeta{ID: id}}
}
oldMinions := []v1beta1.Minion{
oldMinion("foo"),
@@ -163,10 +163,10 @@ func TestMinionListConversionToNew(t *testing.T) {
func TestMinionListConversionToOld(t *testing.T) {
oldMinion := func(id string) v1beta1.Minion {
return v1beta1.Minion{JSONBase: v1beta1.JSONBase{ID: id}}
return v1beta1.Minion{TypeMeta: v1beta1.TypeMeta{ID: id}}
}
newMinion := func(id string) newer.Minion {
return newer.Minion{JSONBase: newer.JSONBase{ID: id}}
return newer.Minion{TypeMeta: newer.TypeMeta{ID: id}}
}
oldMinions := []v1beta1.Minion{
oldMinion("foo"),

View File

@@ -65,7 +65,7 @@ type ContainerManifest struct {
// ContainerManifestList is used to communicate container manifests to kubelet.
type ContainerManifestList struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
Items []ContainerManifest `json:"items,omitempty" yaml:"items,omitempty"`
}
@@ -255,8 +255,8 @@ type Lifecycle struct {
// The below types are used by kube_client and api_server.
// JSONBase is shared by all objects sent to, or returned from the client.
type JSONBase struct {
// TypeMeta is shared by all objects sent to, or returned from the client.
type TypeMeta struct {
Kind string `json:"kind,omitempty" yaml:"kind,omitempty"`
ID string `json:"id,omitempty" yaml:"id,omitempty"`
CreationTimestamp util.Time `json:"creationTimestamp,omitempty" yaml:"creationTimestamp,omitempty"`
@@ -266,7 +266,7 @@ type JSONBase struct {
Namespace string `json:"namespace",omitempty" yaml:"namespace,omitempty"`
}
func (*JSONBase) IsAnAPIObject() {}
func (*TypeMeta) IsAnAPIObject() {}
// PodStatus represents a status of a pod.
type PodStatus string
@@ -359,7 +359,7 @@ type PodState struct {
// PodList is a list of Pods.
type PodList struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
Items []Pod `json:"items" yaml:"items,omitempty"`
}
@@ -367,7 +367,7 @@ func (*PodList) IsAnAPIObject() {}
// Pod is a collection of containers, used as either input (create, update) or as output (list, get).
type Pod struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
DesiredState PodState `json:"desiredState,omitempty" yaml:"desiredState,omitempty"`
CurrentState PodState `json:"currentState,omitempty" yaml:"currentState,omitempty"`
@@ -384,7 +384,7 @@ type ReplicationControllerState struct {
// ReplicationControllerList is a collection of replication controllers.
type ReplicationControllerList struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
Items []ReplicationController `json:"items,omitempty" yaml:"items,omitempty"`
}
@@ -392,7 +392,7 @@ func (*ReplicationControllerList) IsAnAPIObject() {}
// ReplicationController represents the configuration of a replication controller.
type ReplicationController struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
DesiredState ReplicationControllerState `json:"desiredState,omitempty" yaml:"desiredState,omitempty"`
CurrentState ReplicationControllerState `json:"currentState,omitempty" yaml:"currentState,omitempty"`
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
@@ -408,7 +408,7 @@ type PodTemplate struct {
// ServiceList holds a list of services.
type ServiceList struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
Items []Service `json:"items" yaml:"items"`
}
@@ -418,7 +418,7 @@ func (*ServiceList) IsAnAPIObject() {}
// (for example 3306) that the proxy listens on, and the selector that determines which pods
// will answer requests sent through the proxy.
type Service struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
// Required.
Port int `json:"port" yaml:"port"`
@@ -442,7 +442,7 @@ func (*Service) IsAnAPIObject() {}
// Endpoints is a collection of endpoints that implement the actual service, for example:
// Name: "mysql", Endpoints: ["10.10.1.1:1909", "10.10.2.2:8834"]
type Endpoints struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
Endpoints []string `json:"endpoints,omitempty" yaml:"endpoints,omitempty"`
}
@@ -450,7 +450,7 @@ func (*Endpoints) IsAnAPIObject() {}
// EndpointsList is a list of endpoints.
type EndpointsList struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
Items []Endpoints `json:"items,omitempty" yaml:"items,omitempty"`
}
@@ -468,9 +468,9 @@ type ResourceName string
type ResourceList map[ResourceName]util.IntOrString
// Minion is a worker node in Kubernetenes.
// The name of the minion according to etcd is in JSONBase.ID.
// The name of the minion according to etcd is in TypeMeta.ID.
type Minion struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
// Queried from cloud provider, if available.
HostIP string `json:"hostIP,omitempty" yaml:"hostIP,omitempty"`
// Resources available on the node
@@ -481,7 +481,7 @@ func (*Minion) IsAnAPIObject() {}
// MinionList is a list of minions.
type MinionList struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
// DEPRECATED: the below Minions is due to a naming mistake and
// will be replaced with Items in the future.
Minions []Minion `json:"minions,omitempty" yaml:"minions,omitempty"`
@@ -492,7 +492,7 @@ func (*MinionList) IsAnAPIObject() {}
// Binding is written by a scheduler to cause a pod to be bound to a host.
type Binding struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
PodID string `json:"podID" yaml:"podID"`
Host string `json:"host" yaml:"host"`
}
@@ -503,7 +503,7 @@ func (*Binding) IsAnAPIObject() {}
// TODO: this could go in apiserver, but I'm including it here so clients needn't
// import both.
type Status struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
// One of: "Success", "Failure", "Working" (for operations not yet completed)
Status string `json:"status,omitempty" yaml:"status,omitempty"`
// A human-readable description of the status of this operation.
@@ -644,14 +644,14 @@ const (
// ServerOp is an operation delivered to API clients.
type ServerOp struct {
JSONBase `yaml:",inline" json:",inline"`
TypeMeta `yaml:",inline" json:",inline"`
}
func (*ServerOp) IsAnAPIObject() {}
// ServerOpList is a list of operations, as delivered to API clients.
type ServerOpList struct {
JSONBase `yaml:",inline" json:",inline"`
TypeMeta `yaml:",inline" json:",inline"`
Items []ServerOp `yaml:"items,omitempty" json:"items,omitempty"`
}
@@ -678,7 +678,7 @@ type ObjectReference struct {
// Event is a report of an event somewhere in the cluster.
// TODO: Decide whether to store these separately or with the object they apply to.
type Event struct {
JSONBase `yaml:",inline" json:",inline"`
TypeMeta `yaml:",inline" json:",inline"`
// Required. The object that this event is about.
InvolvedObject ObjectReference `json:"involvedObject,omitempty" yaml:"involvedObject,omitempty"`
@@ -711,7 +711,7 @@ func (*Event) IsAnAPIObject() {}
// EventList is a list of events.
type EventList struct {
JSONBase `yaml:",inline" json:",inline"`
TypeMeta `yaml:",inline" json:",inline"`
Items []Event `yaml:"items,omitempty" json:"items,omitempty"`
}

View File

@@ -62,13 +62,13 @@ func init() {
// MinionList.Items had a wrong name in v1beta1
func(in *newer.MinionList, out *MinionList, s conversion.Scope) error {
s.Convert(&in.JSONBase, &out.JSONBase, 0)
s.Convert(&in.TypeMeta, &out.TypeMeta, 0)
s.Convert(&in.Items, &out.Items, 0)
out.Minions = out.Items
return nil
},
func(in *MinionList, out *newer.MinionList, s conversion.Scope) error {
s.Convert(&in.JSONBase, &out.JSONBase, 0)
s.Convert(&in.TypeMeta, &out.TypeMeta, 0)
if len(in.Items) == 0 {
s.Convert(&in.Minions, &out.Items, 0)
} else {

View File

@@ -65,7 +65,7 @@ type ContainerManifest struct {
// ContainerManifestList is used to communicate container manifests to kubelet.
type ContainerManifestList struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
Items []ContainerManifest `json:"items,omitempty" yaml:"items,omitempty"`
}
@@ -253,8 +253,8 @@ type Lifecycle struct {
// The below types are used by kube_client and api_server.
// JSONBase is shared by all objects sent to, or returned from the client.
type JSONBase struct {
// TypeMeta is shared by all objects sent to, or returned from the client.
type TypeMeta struct {
Kind string `json:"kind,omitempty" yaml:"kind,omitempty"`
ID string `json:"id,omitempty" yaml:"id,omitempty"`
CreationTimestamp util.Time `json:"creationTimestamp,omitempty" yaml:"creationTimestamp,omitempty"`
@@ -355,7 +355,7 @@ type PodState struct {
// PodList is a list of Pods.
type PodList struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
Items []Pod `json:"items" yaml:"items,omitempty"`
}
@@ -363,7 +363,7 @@ func (*PodList) IsAnAPIObject() {}
// Pod is a collection of containers, used as either input (create, update) or as output (list, get).
type Pod struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
DesiredState PodState `json:"desiredState,omitempty" yaml:"desiredState,omitempty"`
CurrentState PodState `json:"currentState,omitempty" yaml:"currentState,omitempty"`
@@ -380,7 +380,7 @@ type ReplicationControllerState struct {
// ReplicationControllerList is a collection of replication controllers.
type ReplicationControllerList struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
Items []ReplicationController `json:"items,omitempty" yaml:"items,omitempty"`
}
@@ -388,7 +388,7 @@ func (*ReplicationControllerList) IsAnAPIObject() {}
// ReplicationController represents the configuration of a replication controller.
type ReplicationController struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
DesiredState ReplicationControllerState `json:"desiredState,omitempty" yaml:"desiredState,omitempty"`
CurrentState ReplicationControllerState `json:"currentState,omitempty" yaml:"currentState,omitempty"`
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
@@ -404,7 +404,7 @@ type PodTemplate struct {
// ServiceList holds a list of services.
type ServiceList struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
Items []Service `json:"items" yaml:"items"`
}
@@ -414,7 +414,7 @@ func (*ServiceList) IsAnAPIObject() {}
// (for example 3306) that the proxy listens on, and the selector that determines which pods
// will answer requests sent through the proxy.
type Service struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
// Required.
Port int `json:"port" yaml:"port"`
@@ -438,7 +438,7 @@ func (*Service) IsAnAPIObject() {}
// Endpoints is a collection of endpoints that implement the actual service, for example:
// Name: "mysql", Endpoints: ["10.10.1.1:1909", "10.10.2.2:8834"]
type Endpoints struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
Endpoints []string `json:"endpoints,omitempty" yaml:"endpoints,omitempty"`
}
@@ -446,7 +446,7 @@ func (*Endpoints) IsAnAPIObject() {}
// EndpointsList is a list of endpoints.
type EndpointsList struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
Items []Endpoints `json:"items,omitempty" yaml:"items,omitempty"`
}
@@ -464,9 +464,9 @@ type ResourceName string
type ResourceList map[ResourceName]util.IntOrString
// Minion is a worker node in Kubernetenes.
// The name of the minion according to etcd is in JSONBase.ID.
// The name of the minion according to etcd is in TypeMeta.ID.
type Minion struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
// Queried from cloud provider, if available.
HostIP string `json:"hostIP,omitempty" yaml:"hostIP,omitempty"`
// Resources available on the node
@@ -477,7 +477,7 @@ func (*Minion) IsAnAPIObject() {}
// MinionList is a list of minions.
type MinionList struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
// DEPRECATED: the below Minions is due to a naming mistake and
// will be replaced with Items in the future.
Minions []Minion `json:"minions,omitempty" yaml:"minions,omitempty"`
@@ -488,7 +488,7 @@ func (*MinionList) IsAnAPIObject() {}
// Binding is written by a scheduler to cause a pod to be bound to a host.
type Binding struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
PodID string `json:"podID" yaml:"podID"`
Host string `json:"host" yaml:"host"`
}
@@ -499,7 +499,7 @@ func (*Binding) IsAnAPIObject() {}
// TODO: this could go in apiserver, but I'm including it here so clients needn't
// import both.
type Status struct {
JSONBase `json:",inline" yaml:",inline"`
TypeMeta `json:",inline" yaml:",inline"`
// One of: "Success", "Failure", "Working" (for operations not yet completed)
Status string `json:"status,omitempty" yaml:"status,omitempty"`
// A human-readable description of the status of this operation.
@@ -653,14 +653,14 @@ const (
// ServerOp is an operation delivered to API clients.
type ServerOp struct {
JSONBase `yaml:",inline" json:",inline"`
TypeMeta `yaml:",inline" json:",inline"`
}
func (*ServerOp) IsAnAPIObject() {}
// ServerOpList is a list of operations, as delivered to API clients.
type ServerOpList struct {
JSONBase `yaml:",inline" json:",inline"`
TypeMeta `yaml:",inline" json:",inline"`
Items []ServerOp `yaml:"items,omitempty" json:"items,omitempty"`
}
@@ -687,7 +687,7 @@ type ObjectReference struct {
// Event is a report of an event somewhere in the cluster.
// TODO: Decide whether to store these separately or with the object they apply to.
type Event struct {
JSONBase `yaml:",inline" json:",inline"`
TypeMeta `yaml:",inline" json:",inline"`
// Required. The object that this event is about.
InvolvedObject ObjectReference `json:"involvedObject,omitempty" yaml:"involvedObject,omitempty"`
@@ -720,7 +720,7 @@ func (*Event) IsAnAPIObject() {}
// EventList is a list of events.
type EventList struct {
JSONBase `yaml:",inline" json:",inline"`
TypeMeta `yaml:",inline" json:",inline"`
Items []Event `yaml:"items,omitempty" json:"items,omitempty"`
}

View File

@@ -580,7 +580,7 @@ type ResourceName string
type ResourceList map[ResourceName]util.IntOrString
// Node is a worker node in Kubernetenes.
// The name of the node according to etcd is in JSONBase.ID.
// The name of the node according to etcd is in TypeMeta.ID.
type Node struct {
TypeMeta `json:",inline" yaml:",inline"`
Metadata ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`

View File

@@ -366,7 +366,7 @@ func TestValidateManifest(t *testing.T) {
func TestValidatePod(t *testing.T) {
errs := ValidatePod(&api.Pod{
JSONBase: api.JSONBase{ID: "foo", Namespace: api.NamespaceDefault},
TypeMeta: api.TypeMeta{ID: "foo", Namespace: api.NamespaceDefault},
Labels: map[string]string{
"foo": "bar",
},
@@ -384,7 +384,7 @@ func TestValidatePod(t *testing.T) {
t.Errorf("Unexpected non-zero error list: %#v", errs)
}
errs = ValidatePod(&api.Pod{
JSONBase: api.JSONBase{ID: "foo", Namespace: api.NamespaceDefault},
TypeMeta: api.TypeMeta{ID: "foo", Namespace: api.NamespaceDefault},
Labels: map[string]string{
"foo": "bar",
},
@@ -397,7 +397,7 @@ func TestValidatePod(t *testing.T) {
}
errs = ValidatePod(&api.Pod{
JSONBase: api.JSONBase{ID: "foo", Namespace: api.NamespaceDefault},
TypeMeta: api.TypeMeta{ID: "foo", Namespace: api.NamespaceDefault},
Labels: map[string]string{
"foo": "bar",
},
@@ -424,7 +424,7 @@ func TestValidateService(t *testing.T) {
{
name: "missing id",
svc: api.Service{
JSONBase: api.JSONBase{Namespace: api.NamespaceDefault},
TypeMeta: api.TypeMeta{Namespace: api.NamespaceDefault},
Port: 8675,
Selector: map[string]string{"foo": "bar"},
},
@@ -434,7 +434,7 @@ func TestValidateService(t *testing.T) {
{
name: "missing namespace",
svc: api.Service{
JSONBase: api.JSONBase{ID: "foo"},
TypeMeta: api.TypeMeta{ID: "foo"},
Port: 8675,
Selector: map[string]string{"foo": "bar"},
},
@@ -444,7 +444,7 @@ func TestValidateService(t *testing.T) {
{
name: "invalid id",
svc: api.Service{
JSONBase: api.JSONBase{ID: "123abc", Namespace: api.NamespaceDefault},
TypeMeta: api.TypeMeta{ID: "123abc", Namespace: api.NamespaceDefault},
Port: 8675,
Selector: map[string]string{"foo": "bar"},
},
@@ -454,7 +454,7 @@ func TestValidateService(t *testing.T) {
{
name: "missing port",
svc: api.Service{
JSONBase: api.JSONBase{ID: "abc123", Namespace: api.NamespaceDefault},
TypeMeta: api.TypeMeta{ID: "abc123", Namespace: api.NamespaceDefault},
Selector: map[string]string{"foo": "bar"},
},
// Should fail because the port number is missing/invalid.
@@ -463,7 +463,7 @@ func TestValidateService(t *testing.T) {
{
name: "invalid port",
svc: api.Service{
JSONBase: api.JSONBase{ID: "abc123", Namespace: api.NamespaceDefault},
TypeMeta: api.TypeMeta{ID: "abc123", Namespace: api.NamespaceDefault},
Port: 65536,
Selector: map[string]string{"foo": "bar"},
},
@@ -473,7 +473,7 @@ func TestValidateService(t *testing.T) {
{
name: "invalid protocol",
svc: api.Service{
JSONBase: api.JSONBase{ID: "abc123", Namespace: api.NamespaceDefault},
TypeMeta: api.TypeMeta{ID: "abc123", Namespace: api.NamespaceDefault},
Port: 8675,
Protocol: "INVALID",
Selector: map[string]string{"foo": "bar"},
@@ -484,7 +484,7 @@ func TestValidateService(t *testing.T) {
{
name: "missing selector",
svc: api.Service{
JSONBase: api.JSONBase{ID: "foo", Namespace: api.NamespaceDefault},
TypeMeta: api.TypeMeta{ID: "foo", Namespace: api.NamespaceDefault},
Port: 8675,
},
// Should fail because the selector is missing.
@@ -493,7 +493,7 @@ func TestValidateService(t *testing.T) {
{
name: "valid 1",
svc: api.Service{
JSONBase: api.JSONBase{ID: "abc123", Namespace: api.NamespaceDefault},
TypeMeta: api.TypeMeta{ID: "abc123", Namespace: api.NamespaceDefault},
Port: 1,
Protocol: "TCP",
Selector: map[string]string{"foo": "bar"},
@@ -503,7 +503,7 @@ func TestValidateService(t *testing.T) {
{
name: "valid 2",
svc: api.Service{
JSONBase: api.JSONBase{ID: "abc123", Namespace: api.NamespaceDefault},
TypeMeta: api.TypeMeta{ID: "abc123", Namespace: api.NamespaceDefault},
Port: 65535,
Protocol: "UDP",
Selector: map[string]string{"foo": "bar"},
@@ -513,7 +513,7 @@ func TestValidateService(t *testing.T) {
{
name: "valid 3",
svc: api.Service{
JSONBase: api.JSONBase{ID: "abc123", Namespace: api.NamespaceDefault},
TypeMeta: api.TypeMeta{ID: "abc123", Namespace: api.NamespaceDefault},
Port: 80,
Selector: map[string]string{"foo": "bar"},
},
@@ -530,7 +530,7 @@ func TestValidateService(t *testing.T) {
svc := api.Service{
Port: 6502,
JSONBase: api.JSONBase{ID: "foo", Namespace: api.NamespaceDefault},
TypeMeta: api.TypeMeta{ID: "foo", Namespace: api.NamespaceDefault},
Selector: map[string]string{"foo": "bar"},
}
errs := ValidateService(&svc)
@@ -555,14 +555,14 @@ func TestValidateReplicationController(t *testing.T) {
successCases := []api.ReplicationController{
{
JSONBase: api.JSONBase{ID: "abc", Namespace: api.NamespaceDefault},
TypeMeta: api.TypeMeta{ID: "abc", Namespace: api.NamespaceDefault},
DesiredState: api.ReplicationControllerState{
ReplicaSelector: validSelector,
PodTemplate: validPodTemplate,
},
},
{
JSONBase: api.JSONBase{ID: "abc-123", Namespace: api.NamespaceDefault},
TypeMeta: api.TypeMeta{ID: "abc-123", Namespace: api.NamespaceDefault},
DesiredState: api.ReplicationControllerState{
ReplicaSelector: validSelector,
PodTemplate: validPodTemplate,
@@ -577,40 +577,40 @@ func TestValidateReplicationController(t *testing.T) {
errorCases := map[string]api.ReplicationController{
"zero-length ID": {
JSONBase: api.JSONBase{ID: "", Namespace: api.NamespaceDefault},
TypeMeta: api.TypeMeta{ID: "", Namespace: api.NamespaceDefault},
DesiredState: api.ReplicationControllerState{
ReplicaSelector: validSelector,
PodTemplate: validPodTemplate,
},
},
"missing-namespace": {
JSONBase: api.JSONBase{ID: "abc-123"},
TypeMeta: api.TypeMeta{ID: "abc-123"},
DesiredState: api.ReplicationControllerState{
ReplicaSelector: validSelector,
PodTemplate: validPodTemplate,
},
},
"empty selector": {
JSONBase: api.JSONBase{ID: "abc", Namespace: api.NamespaceDefault},
TypeMeta: api.TypeMeta{ID: "abc", Namespace: api.NamespaceDefault},
DesiredState: api.ReplicationControllerState{
PodTemplate: validPodTemplate,
},
},
"selector_doesnt_match": {
JSONBase: api.JSONBase{ID: "abc", Namespace: api.NamespaceDefault},
TypeMeta: api.TypeMeta{ID: "abc", Namespace: api.NamespaceDefault},
DesiredState: api.ReplicationControllerState{
ReplicaSelector: map[string]string{"foo": "bar"},
PodTemplate: validPodTemplate,
},
},
"invalid manifest": {
JSONBase: api.JSONBase{ID: "abc", Namespace: api.NamespaceDefault},
TypeMeta: api.TypeMeta{ID: "abc", Namespace: api.NamespaceDefault},
DesiredState: api.ReplicationControllerState{
ReplicaSelector: validSelector,
},
},
"negative_replicas": {
JSONBase: api.JSONBase{ID: "abc", Namespace: api.NamespaceDefault},
TypeMeta: api.TypeMeta{ID: "abc", Namespace: api.NamespaceDefault},
DesiredState: api.ReplicationControllerState{
Replicas: -1,
ReplicaSelector: validSelector,