Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit d3e51a0

Browse files
Rename JSONBase -> TypeMeta in preparation for v1beta3
Will make subsequent refactor much easier
1 parent e294cef commit d3e51a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+464
-464
lines changed

cmd/integration/integration.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func runAtomicPutTest(c *client.Client) {
244244
var svc api.Service
245245
err := c.Post().Path("services").Body(
246246
&api.Service{
247-
JSONBase: api.JSONBase{ID: "atomicservice", APIVersion: latest.Version},
247+
TypeMeta: api.TypeMeta{ID: "atomicservice", APIVersion: latest.Version},
248248
Port: 12345,
249249
Labels: map[string]string{
250250
"name": "atomicService",
@@ -318,7 +318,7 @@ func runAtomicPutTest(c *client.Client) {
318318
func runServiceTest(client *client.Client) {
319319
ctx := api.NewDefaultContext()
320320
pod := api.Pod{
321-
JSONBase: api.JSONBase{ID: "foo"},
321+
TypeMeta: api.TypeMeta{ID: "foo"},
322322
DesiredState: api.PodState{
323323
Manifest: api.ContainerManifest{
324324
Version: "v1beta1",
@@ -348,7 +348,7 @@ func runServiceTest(client *client.Client) {
348348
glog.Fatalf("FAILED: pod never started running %v", err)
349349
}
350350
svc := api.Service{
351-
JSONBase: api.JSONBase{ID: "service1"},
351+
TypeMeta: api.TypeMeta{ID: "service1"},
352352
Selector: map[string]string{
353353
"name": "thisisalonglabel",
354354
},

cmd/kubecfg/kubecfg.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ func executeAPIRequest(ctx api.Context, method string, c *client.Client) bool {
342342
if err != nil {
343343
glog.Fatalf("error obtaining resource version for update: %v", err)
344344
}
345-
jsonBase, err := runtime.FindJSONBase(obj)
345+
jsonBase, err := runtime.FindTypeMeta(obj)
346346
if err != nil {
347347
glog.Fatalf("error finding json base for update: %v", err)
348348
}
@@ -375,7 +375,7 @@ func executeAPIRequest(ctx api.Context, method string, c *client.Client) bool {
375375
if err != nil {
376376
glog.Fatalf("error setting resource version: %v", err)
377377
}
378-
jsonBase, err := runtime.FindJSONBase(obj)
378+
jsonBase, err := runtime.FindTypeMeta(obj)
379379
if err != nil {
380380
glog.Fatalf("error setting resource version: %v", err)
381381
}

examples/examples_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ func validateObject(obj runtime.Object) (errors []error) {
4141
errors = append(errors, validateObject(&t.Items[i])...)
4242
}
4343
case *api.Service:
44-
api.ValidNamespace(ctx, &t.JSONBase)
44+
api.ValidNamespace(ctx, &t.TypeMeta)
4545
errors = validation.ValidateService(t)
4646
case *api.ServiceList:
4747
for i := range t.Items {
4848
errors = append(errors, validateObject(&t.Items[i])...)
4949
}
5050
case *api.Pod:
51-
api.ValidNamespace(ctx, &t.JSONBase)
51+
api.ValidNamespace(ctx, &t.TypeMeta)
5252
errors = validation.ValidateManifest(&t.DesiredState.Manifest)
5353
case *api.PodList:
5454
for i := range t.Items {

pkg/api/context.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func NamespaceFrom(ctx Context) (string, bool) {
6464
}
6565

6666
// 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.
67-
func ValidNamespace(ctx Context, resource *JSONBase) bool {
67+
func ValidNamespace(ctx Context, resource *TypeMeta) bool {
6868
ns, ok := NamespaceFrom(ctx)
6969
if len(resource.Namespace) == 0 {
7070
resource.Namespace = ns

pkg/api/context_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@ func TestValidNamespace(t *testing.T) {
4545
ctx := api.NewDefaultContext()
4646
namespace, _ := api.NamespaceFrom(ctx)
4747
resource := api.ReplicationController{}
48-
if !api.ValidNamespace(ctx, &resource.JSONBase) {
48+
if !api.ValidNamespace(ctx, &resource.TypeMeta) {
4949
t.Errorf("expected success")
5050
}
5151
if namespace != resource.Namespace {
5252
t.Errorf("expected resource to have the default namespace assigned during validation")
5353
}
54-
resource = api.ReplicationController{JSONBase: api.JSONBase{Namespace: "other"}}
55-
if api.ValidNamespace(ctx, &resource.JSONBase) {
54+
resource = api.ReplicationController{TypeMeta: api.TypeMeta{Namespace: "other"}}
55+
if api.ValidNamespace(ctx, &resource.TypeMeta) {
5656
t.Errorf("Expected error that resource and context errors do not match because resource has different namespace")
5757
}
5858
ctx = api.NewContext()
59-
if api.ValidNamespace(ctx, &resource.JSONBase) {
59+
if api.ValidNamespace(ctx, &resource.TypeMeta) {
6060
t.Errorf("Expected error that resource and context errors do not match since context has no namespace")
6161
}
6262
}

pkg/api/latest/latest.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ var Codec = v1beta1.Codec
4747
// ResourceVersioner describes a default versioner that can handle all types
4848
// of versioning.
4949
// TODO: when versioning changes, make this part of each API definition.
50-
var ResourceVersioner = runtime.NewJSONBaseResourceVersioner()
50+
var ResourceVersioner = runtime.NewTypeMetaResourceVersioner()
5151

5252
// SelfLinker can set or get the SelfLink field of all API types.
5353
// TODO: when versioning changes, make this part of each API definition.
5454
// TODO(lavalamp): Combine SelfLinker & ResourceVersioner interfaces, force all uses
5555
// to go through the InterfacesFor method below.
56-
var SelfLinker = runtime.NewJSONBaseSelfLinker()
56+
var SelfLinker = runtime.NewTypeMetaSelfLinker()
5757

5858
// VersionInterfaces contains the interfaces one should use for dealing with types of a particular version.
5959
type VersionInterfaces struct {

pkg/api/latest/latest_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ import (
3232

3333
// apiObjectFuzzer can randomly populate api objects.
3434
var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
35-
func(j *internal.JSONBase, c fuzz.Continue) {
36-
// We have to customize the randomization of JSONBases because their
35+
func(j *internal.TypeMeta, c fuzz.Continue) {
36+
// We have to customize the randomization of TypeMetas because their
3737
// APIVersion and Kind must remain blank in memory.
3838
j.APIVersion = ""
3939
j.Kind = ""
@@ -120,7 +120,7 @@ func TestInternalRoundTrip(t *testing.T) {
120120
}
121121

122122
func TestResourceVersioner(t *testing.T) {
123-
pod := internal.Pod{JSONBase: internal.JSONBase{ResourceVersion: 10}}
123+
pod := internal.Pod{TypeMeta: internal.TypeMeta{ResourceVersion: 10}}
124124
version, err := ResourceVersioner.ResourceVersion(&pod)
125125
if err != nil {
126126
t.Fatalf("unexpected error: %v", err)

pkg/api/ref.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var versionFromSelfLink = regexp.MustCompile("/api/([^/]*)/")
2929
// object, or an error if the object doesn't follow the conventions
3030
// that would allow this.
3131
func GetReference(obj runtime.Object) (*ObjectReference, error) {
32-
jsonBase, err := runtime.FindJSONBase(obj)
32+
jsonBase, err := runtime.FindTypeMeta(obj)
3333
if err != nil {
3434
return nil, err
3535
}
@@ -44,7 +44,7 @@ func GetReference(obj runtime.Object) (*ObjectReference, error) {
4444
return &ObjectReference{
4545
Kind: kind,
4646
APIVersion: version[1],
47-
// TODO: correct Name and UID when JSONBase makes a distinction
47+
// TODO: correct Name and UID when TypeMeta makes a distinction
4848
Name: jsonBase.ID(),
4949
UID: jsonBase.ID(),
5050
ResourceVersion: jsonBase.ResourceVersion(),

pkg/api/ref_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestGetReference(t *testing.T) {
3535
}{
3636
"pod": {
3737
obj: &Pod{
38-
JSONBase: JSONBase{
38+
TypeMeta: TypeMeta{
3939
ID: "foo",
4040
ResourceVersion: 42,
4141
SelfLink: "/api/v1beta1/pods/foo",
@@ -51,7 +51,7 @@ func TestGetReference(t *testing.T) {
5151
},
5252
"serviceList": {
5353
obj: &ServiceList{
54-
JSONBase: JSONBase{
54+
TypeMeta: TypeMeta{
5555
ID: "foo",
5656
ResourceVersion: 42,
5757
SelfLink: "/api/v1beta2/services",
@@ -67,7 +67,7 @@ func TestGetReference(t *testing.T) {
6767
},
6868
"badSelfLink": {
6969
obj: &ServiceList{
70-
JSONBase: JSONBase{
70+
TypeMeta: TypeMeta{
7171
ID: "foo",
7272
ResourceVersion: 42,
7373
SelfLink: "v1beta2/services",

pkg/api/serialization_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
4040
func(j *runtime.PluginBase, c fuzz.Continue) {
4141
// Do nothing; this struct has only a Kind field and it must stay blank in memory.
4242
},
43-
func(j *runtime.JSONBase, c fuzz.Continue) {
44-
// We have to customize the randomization of JSONBases because their
43+
func(j *runtime.TypeMeta, c fuzz.Continue) {
44+
// We have to customize the randomization of TypeMetas because their
4545
// APIVersion and Kind must remain blank in memory.
4646
j.APIVersion = ""
4747
j.Kind = ""
@@ -57,8 +57,8 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
5757
c.Fuzz(&nsec)
5858
j.CreationTimestamp = util.Unix(sec, nsec).Rfc3339Copy()
5959
},
60-
func(j *api.JSONBase, c fuzz.Continue) {
61-
// We have to customize the randomization of JSONBases because their
60+
func(j *api.TypeMeta, c fuzz.Continue) {
61+
// We have to customize the randomization of TypeMetas because their
6262
// APIVersion and Kind must remain blank in memory.
6363
j.APIVersion = ""
6464
j.Kind = ""
@@ -110,7 +110,7 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
110110
func runTest(t *testing.T, codec runtime.Codec, source runtime.Object) {
111111
name := reflect.TypeOf(source).Elem().Name()
112112
apiObjectFuzzer.Fuzz(source)
113-
j, err := runtime.FindJSONBase(source)
113+
j, err := runtime.FindTypeMeta(source)
114114
if err != nil {
115115
t.Fatalf("Unexpected error %v for %#v", err, source)
116116
}

pkg/api/types.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type ContainerManifest struct {
6666

6767
// ContainerManifestList is used to communicate container manifests to kubelet.
6868
type ContainerManifestList struct {
69-
JSONBase `json:",inline" yaml:",inline"`
69+
TypeMeta `json:",inline" yaml:",inline"`
7070
Items []ContainerManifest `json:"items,omitempty" yaml:"items,omitempty"`
7171
}
7272

@@ -265,8 +265,8 @@ type Lifecycle struct {
265265

266266
// The below types are used by kube_client and api_server.
267267

268-
// JSONBase is shared by all objects sent to, or returned from the client.
269-
type JSONBase struct {
268+
// TypeMeta is shared by all objects sent to, or returned from the client.
269+
type TypeMeta struct {
270270
Kind string `json:"kind,omitempty" yaml:"kind,omitempty"`
271271
ID string `json:"id,omitempty" yaml:"id,omitempty"`
272272
CreationTimestamp util.Time `json:"creationTimestamp,omitempty" yaml:"creationTimestamp,omitempty"`
@@ -374,15 +374,15 @@ type PodState struct {
374374

375375
// PodList is a list of Pods.
376376
type PodList struct {
377-
JSONBase `json:",inline" yaml:",inline"`
377+
TypeMeta `json:",inline" yaml:",inline"`
378378
Items []Pod `json:"items" yaml:"items,omitempty"`
379379
}
380380

381381
func (*PodList) IsAnAPIObject() {}
382382

383383
// Pod is a collection of containers, used as either input (create, update) or as output (list, get).
384384
type Pod struct {
385-
JSONBase `json:",inline" yaml:",inline"`
385+
TypeMeta `json:",inline" yaml:",inline"`
386386
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
387387
DesiredState PodState `json:"desiredState,omitempty" yaml:"desiredState,omitempty"`
388388
CurrentState PodState `json:"currentState,omitempty" yaml:"currentState,omitempty"`
@@ -399,15 +399,15 @@ type ReplicationControllerState struct {
399399

400400
// ReplicationControllerList is a collection of replication controllers.
401401
type ReplicationControllerList struct {
402-
JSONBase `json:",inline" yaml:",inline"`
402+
TypeMeta `json:",inline" yaml:",inline"`
403403
Items []ReplicationController `json:"items,omitempty" yaml:"items,omitempty"`
404404
}
405405

406406
func (*ReplicationControllerList) IsAnAPIObject() {}
407407

408408
// ReplicationController represents the configuration of a replication controller.
409409
type ReplicationController struct {
410-
JSONBase `json:",inline" yaml:",inline"`
410+
TypeMeta `json:",inline" yaml:",inline"`
411411
DesiredState ReplicationControllerState `json:"desiredState,omitempty" yaml:"desiredState,omitempty"`
412412
CurrentState ReplicationControllerState `json:"currentState,omitempty" yaml:"currentState,omitempty"`
413413
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
@@ -423,7 +423,7 @@ type PodTemplate struct {
423423

424424
// ServiceList holds a list of services.
425425
type ServiceList struct {
426-
JSONBase `json:",inline" yaml:",inline"`
426+
TypeMeta `json:",inline" yaml:",inline"`
427427
Items []Service `json:"items" yaml:"items"`
428428
}
429429

@@ -433,7 +433,7 @@ func (*ServiceList) IsAnAPIObject() {}
433433
// (for example 3306) that the proxy listens on, and the selector that determines which pods
434434
// will answer requests sent through the proxy.
435435
type Service struct {
436-
JSONBase `json:",inline" yaml:",inline"`
436+
TypeMeta `json:",inline" yaml:",inline"`
437437

438438
// Required.
439439
Port int `json:"port" yaml:"port"`
@@ -457,15 +457,15 @@ func (*Service) IsAnAPIObject() {}
457457
// Endpoints is a collection of endpoints that implement the actual service, for example:
458458
// Name: "mysql", Endpoints: ["10.10.1.1:1909", "10.10.2.2:8834"]
459459
type Endpoints struct {
460-
JSONBase `json:",inline" yaml:",inline"`
460+
TypeMeta `json:",inline" yaml:",inline"`
461461
Endpoints []string `json:"endpoints,omitempty" yaml:"endpoints,omitempty"`
462462
}
463463

464464
func (*Endpoints) IsAnAPIObject() {}
465465

466466
// EndpointsList is a list of endpoints.
467467
type EndpointsList struct {
468-
JSONBase `json:",inline" yaml:",inline"`
468+
TypeMeta `json:",inline" yaml:",inline"`
469469
Items []Endpoints `json:"items,omitempty" yaml:"items,omitempty"`
470470
}
471471

@@ -484,9 +484,9 @@ type ResourceName string
484484
type ResourceList map[ResourceName]util.IntOrString
485485

486486
// Minion is a worker node in Kubernetenes.
487-
// The name of the minion according to etcd is in JSONBase.ID.
487+
// The name of the minion according to etcd is in TypeMeta.ID.
488488
type Minion struct {
489-
JSONBase `json:",inline" yaml:",inline"`
489+
TypeMeta `json:",inline" yaml:",inline"`
490490
// Queried from cloud provider, if available.
491491
HostIP string `json:"hostIP,omitempty" yaml:"hostIP,omitempty"`
492492
// Resources available on the node
@@ -497,15 +497,15 @@ func (*Minion) IsAnAPIObject() {}
497497

498498
// MinionList is a list of minions.
499499
type MinionList struct {
500-
JSONBase `json:",inline" yaml:",inline"`
500+
TypeMeta `json:",inline" yaml:",inline"`
501501
Items []Minion `json:"items,omitempty" yaml:"items,omitempty"`
502502
}
503503

504504
func (*MinionList) IsAnAPIObject() {}
505505

506506
// Binding is written by a scheduler to cause a pod to be bound to a host.
507507
type Binding struct {
508-
JSONBase `json:",inline" yaml:",inline"`
508+
TypeMeta `json:",inline" yaml:",inline"`
509509
PodID string `json:"podID" yaml:"podID"`
510510
Host string `json:"host" yaml:"host"`
511511
}
@@ -516,7 +516,7 @@ func (*Binding) IsAnAPIObject() {}
516516
// TODO: this could go in apiserver, but I'm including it here so clients needn't
517517
// import both.
518518
type Status struct {
519-
JSONBase `json:",inline" yaml:",inline"`
519+
TypeMeta `json:",inline" yaml:",inline"`
520520
// One of: "Success", "Failure", "Working" (for operations not yet completed)
521521
Status string `json:"status,omitempty" yaml:"status,omitempty"`
522522
// A human-readable description of the status of this operation.
@@ -670,14 +670,14 @@ const (
670670

671671
// ServerOp is an operation delivered to API clients.
672672
type ServerOp struct {
673-
JSONBase `yaml:",inline" json:",inline"`
673+
TypeMeta `yaml:",inline" json:",inline"`
674674
}
675675

676676
func (*ServerOp) IsAnAPIObject() {}
677677

678678
// ServerOpList is a list of operations, as delivered to API clients.
679679
type ServerOpList struct {
680-
JSONBase `yaml:",inline" json:",inline"`
680+
TypeMeta `yaml:",inline" json:",inline"`
681681
Items []ServerOp `yaml:"items,omitempty" json:"items,omitempty"`
682682
}
683683

@@ -704,7 +704,7 @@ type ObjectReference struct {
704704
// Event is a report of an event somewhere in the cluster.
705705
// TODO: Decide whether to store these separately or with the object they apply to.
706706
type Event struct {
707-
JSONBase `yaml:",inline" json:",inline"`
707+
TypeMeta `yaml:",inline" json:",inline"`
708708

709709
// Required. The object that this event is about.
710710
InvolvedObject ObjectReference `json:"involvedObject,omitempty" yaml:"involvedObject,omitempty"`
@@ -737,7 +737,7 @@ func (*Event) IsAnAPIObject() {}
737737

738738
// EventList is a list of events.
739739
type EventList struct {
740-
JSONBase `yaml:",inline" json:",inline"`
740+
TypeMeta `yaml:",inline" json:",inline"`
741741
Items []Event `yaml:"items,omitempty" json:"items,omitempty"`
742742
}
743743

pkg/api/v1beta1/conversion.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ func init() {
6262

6363
// MinionList.Items had a wrong name in v1beta1
6464
func(in *newer.MinionList, out *MinionList, s conversion.Scope) error {
65-
s.Convert(&in.JSONBase, &out.JSONBase, 0)
65+
s.Convert(&in.TypeMeta, &out.TypeMeta, 0)
6666
s.Convert(&in.Items, &out.Items, 0)
6767
out.Minions = out.Items
6868
return nil
6969
},
7070
func(in *MinionList, out *newer.MinionList, s conversion.Scope) error {
71-
s.Convert(&in.JSONBase, &out.JSONBase, 0)
71+
s.Convert(&in.TypeMeta, &out.TypeMeta, 0)
7272
if len(in.Items) == 0 {
7373
s.Convert(&in.Minions, &out.Items, 0)
7474
} else {

0 commit comments

Comments
 (0)