Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename JSONBase -> TypeMeta in preparation for v1beta3 #1623

Merged
merged 2 commits into from
Oct 7, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func runAtomicPutTest(c *client.Client) {
var svc api.Service
err := c.Post().Path("services").Body(
&api.Service{
JSONBase: api.JSONBase{ID: "atomicservice", APIVersion: latest.Version},
TypeMeta: api.TypeMeta{ID: "atomicservice", APIVersion: latest.Version},
Port: 12345,
Labels: map[string]string{
"name": "atomicService",
Expand Down Expand Up @@ -318,7 +318,7 @@ func runAtomicPutTest(c *client.Client) {
func runServiceTest(client *client.Client) {
ctx := api.NewDefaultContext()
pod := api.Pod{
JSONBase: api.JSONBase{ID: "foo"},
TypeMeta: api.TypeMeta{ID: "foo"},
DesiredState: api.PodState{
Manifest: api.ContainerManifest{
Version: "v1beta1",
Expand Down Expand Up @@ -348,7 +348,7 @@ func runServiceTest(client *client.Client) {
glog.Fatalf("FAILED: pod never started running %v", err)
}
svc := api.Service{
JSONBase: api.JSONBase{ID: "service1"},
TypeMeta: api.TypeMeta{ID: "service1"},
Selector: map[string]string{
"name": "thisisalonglabel",
},
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubecfg/kubecfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func executeAPIRequest(ctx api.Context, method string, c *client.Client) bool {
if err != nil {
glog.Fatalf("error obtaining resource version for update: %v", err)
}
jsonBase, err := runtime.FindJSONBase(obj)
jsonBase, err := runtime.FindTypeMeta(obj)
if err != nil {
glog.Fatalf("error finding json base for update: %v", err)
}
Expand Down Expand Up @@ -375,7 +375,7 @@ func executeAPIRequest(ctx api.Context, method string, c *client.Client) bool {
if err != nil {
glog.Fatalf("error setting resource version: %v", err)
}
jsonBase, err := runtime.FindJSONBase(obj)
jsonBase, err := runtime.FindTypeMeta(obj)
if err != nil {
glog.Fatalf("error setting resource version: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions docs/namespaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ Introduce a new attribute *Namespace* for each resource that must be scoped in a
A *Namespace* is a DNS compatible subdomain.

```
// 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"`
Uid string `json:"uid,omitempty" yaml:"uid,omitempty"`
CreationTimestamp util.Time `json:"creationTimestamp,omitempty" yaml:"creationTimestamp,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions examples/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ func validateObject(obj runtime.Object) (errors []error) {
errors = append(errors, validateObject(&t.Items[i])...)
}
case *api.Service:
api.ValidNamespace(ctx, &t.JSONBase)
api.ValidNamespace(ctx, &t.TypeMeta)
errors = validation.ValidateService(t)
case *api.ServiceList:
for i := range t.Items {
errors = append(errors, validateObject(&t.Items[i])...)
}
case *api.Pod:
api.ValidNamespace(ctx, &t.JSONBase)
api.ValidNamespace(ctx, &t.TypeMeta)
errors = validation.ValidateManifest(&t.DesiredState.Manifest)
case *api.PodList:
for i := range t.Items {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
4 changes: 2 additions & 2 deletions pkg/api/latest/latest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/latest/latest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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(),
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/ref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -51,7 +51,7 @@ func TestGetReference(t *testing.T) {
},
"serviceList": {
obj: &ServiceList{
JSONBase: JSONBase{
TypeMeta: TypeMeta{
ID: "foo",
ResourceVersion: 42,
SelfLink: "/api/v1beta2/services",
Expand All @@ -67,7 +67,7 @@ func TestGetReference(t *testing.T) {
},
"badSelfLink": {
obj: &ServiceList{
JSONBase: JSONBase{
TypeMeta: TypeMeta{
ID: "foo",
ResourceVersion: 42,
SelfLink: "v1beta2/services",
Expand Down
10 changes: 5 additions & 5 deletions pkg/api/serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand All @@ -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 = ""
Expand Down Expand Up @@ -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)
}
Expand Down
40 changes: 20 additions & 20 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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"`
}

Expand Down Expand Up @@ -265,8 +265,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"`
Expand Down Expand Up @@ -374,15 +374,15 @@ 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"`
}

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"`
Expand All @@ -399,15 +399,15 @@ 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"`
}

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"`
Expand All @@ -423,7 +423,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"`
}

Expand All @@ -433,7 +433,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"`
Expand All @@ -457,15 +457,15 @@ 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"`
}

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"`
}

Expand All @@ -484,9 +484,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
Expand All @@ -497,15 +497,15 @@ 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"`
}

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"`
}
Expand All @@ -516,7 +516,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.
Expand Down Expand Up @@ -670,14 +670,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"`
}

Expand All @@ -704,7 +704,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"`
Expand Down Expand Up @@ -737,7 +737,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"`
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down