mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
Merge pull request #2786 from smarterclayton/load_opaque_objects
Allow runtime.Object to be encoded as runtime.RawExtension
This commit is contained in:
@@ -25,7 +25,9 @@ import (
|
||||
internal "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
|
||||
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta2"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
|
||||
docker "github.com/fsouza/go-dockerclient"
|
||||
fuzz "github.com/google/gofuzz"
|
||||
)
|
||||
@@ -83,6 +85,26 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
|
||||
// only replicas round trips
|
||||
j.Replicas = int(c.RandUint64())
|
||||
},
|
||||
func(j *internal.List, c fuzz.Continue) {
|
||||
c.Fuzz(&j.ListMeta)
|
||||
c.Fuzz(&j.Items)
|
||||
if j.Items == nil {
|
||||
j.Items = []runtime.Object{}
|
||||
}
|
||||
},
|
||||
func(j *runtime.Object, c fuzz.Continue) {
|
||||
if c.RandBool() {
|
||||
*j = &runtime.Unknown{
|
||||
TypeMeta: runtime.TypeMeta{Kind: "Something", APIVersion: "unknown"},
|
||||
RawJSON: []byte(`{"apiVersion":"unknown","kind":"Something","someKey":"someValue"}`),
|
||||
}
|
||||
} else {
|
||||
types := []runtime.Object{&internal.Pod{}, &internal.ReplicationController{}}
|
||||
t := types[c.Rand.Intn(len(types))]
|
||||
c.Fuzz(t)
|
||||
*j = t
|
||||
}
|
||||
},
|
||||
func(intstr *util.IntOrString, c fuzz.Continue) {
|
||||
// util.IntOrString will panic if its kind is set wrong.
|
||||
if c.RandBool() {
|
||||
|
||||
@@ -45,6 +45,7 @@ func init() {
|
||||
&ContainerManifestList{},
|
||||
&BoundPod{},
|
||||
&BoundPods{},
|
||||
&List{},
|
||||
)
|
||||
// Legacy names are supported
|
||||
Scheme.AddKnownTypeWithName("", "Minion", &Node{})
|
||||
@@ -71,3 +72,4 @@ func (*ContainerManifest) IsAnAPIObject() {}
|
||||
func (*ContainerManifestList) IsAnAPIObject() {}
|
||||
func (*BoundPod) IsAnAPIObject() {}
|
||||
func (*BoundPods) IsAnAPIObject() {}
|
||||
func (*List) IsAnAPIObject() {}
|
||||
|
||||
@@ -48,15 +48,6 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
|
||||
// APIVersion and Kind must remain blank in memory.
|
||||
j.APIVersion = ""
|
||||
j.Kind = ""
|
||||
|
||||
j.Name = c.RandString()
|
||||
j.ResourceVersion = strconv.FormatUint(c.RandUint64(), 10)
|
||||
j.SelfLink = c.RandString()
|
||||
|
||||
var sec, nsec int64
|
||||
c.Fuzz(&sec)
|
||||
c.Fuzz(&nsec)
|
||||
j.CreationTimestamp = util.Unix(sec, nsec).Rfc3339Copy()
|
||||
},
|
||||
func(j *api.TypeMeta, c fuzz.Continue) {
|
||||
// We have to customize the randomization of TypeMetas because their
|
||||
@@ -99,6 +90,26 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
|
||||
// only replicas round trips
|
||||
j.Replicas = int(c.RandUint64())
|
||||
},
|
||||
func(j *api.List, c fuzz.Continue) {
|
||||
c.Fuzz(&j.ListMeta)
|
||||
c.Fuzz(&j.Items)
|
||||
if j.Items == nil {
|
||||
j.Items = []runtime.Object{}
|
||||
}
|
||||
},
|
||||
func(j *runtime.Object, c fuzz.Continue) {
|
||||
if c.RandBool() {
|
||||
*j = &runtime.Unknown{
|
||||
TypeMeta: runtime.TypeMeta{Kind: "Something", APIVersion: "unknown"},
|
||||
RawJSON: []byte(`{"apiVersion":"unknown","kind":"Something","someKey":"someValue"}`),
|
||||
}
|
||||
} else {
|
||||
types := []runtime.Object{&api.Pod{}, &api.ReplicationController{}}
|
||||
t := types[c.Rand.Intn(len(types))]
|
||||
c.Fuzz(t)
|
||||
*j = t
|
||||
}
|
||||
},
|
||||
func(intstr *util.IntOrString, c fuzz.Continue) {
|
||||
// util.IntOrString will panic if its kind is set wrong.
|
||||
if c.RandBool() {
|
||||
@@ -154,7 +165,7 @@ func runTest(t *testing.T, codec runtime.Codec, source runtime.Object) {
|
||||
|
||||
obj2, err := codec.Decode(data)
|
||||
if err != nil {
|
||||
t.Errorf("%v: %v", name, err)
|
||||
t.Errorf("0: %v: %v\nCodec: %v\nData: %s\nSource: %#v", name, err, codec, string(data), source)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(source, obj2) {
|
||||
@@ -188,7 +199,21 @@ func TestSpecificKind(t *testing.T) {
|
||||
api.Scheme.Log(nil)
|
||||
}
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
api.Scheme.Log(t)
|
||||
kind := "List"
|
||||
item, err := api.Scheme.New("", kind)
|
||||
if err != nil {
|
||||
t.Errorf("Couldn't make a %v? %v", kind, err)
|
||||
return
|
||||
}
|
||||
runTest(t, v1beta1.Codec, item)
|
||||
runTest(t, v1beta2.Codec, item)
|
||||
api.Scheme.Log(nil)
|
||||
}
|
||||
|
||||
var nonRoundTrippableTypes = util.NewStringSet("ContainerManifest")
|
||||
var nonInternalRoundTrippableTypes = util.NewStringSet("List")
|
||||
|
||||
func TestRoundTripTypes(t *testing.T) {
|
||||
for kind := range api.Scheme.KnownTypes("") {
|
||||
@@ -206,7 +231,9 @@ func TestRoundTripTypes(t *testing.T) {
|
||||
}
|
||||
runTest(t, v1beta1.Codec, item)
|
||||
runTest(t, v1beta2.Codec, item)
|
||||
runTest(t, api.Codec, item)
|
||||
if !nonInternalRoundTrippableTypes.Has(kind) {
|
||||
runTest(t, api.Codec, item)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package api
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
)
|
||||
|
||||
@@ -1000,3 +1001,11 @@ type BoundPods struct {
|
||||
// Items is the list of all pods bound to a given host.
|
||||
Items []BoundPod `json:"items"`
|
||||
}
|
||||
|
||||
// List holds a list of objects, which may not be known by the server.
|
||||
type List struct {
|
||||
TypeMeta `json:",inline"`
|
||||
ListMeta `json:"metadata,omitempty"`
|
||||
|
||||
Items []runtime.Object `json:"items"`
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ func init() {
|
||||
&ContainerManifestList{},
|
||||
&BoundPod{},
|
||||
&BoundPods{},
|
||||
&List{},
|
||||
)
|
||||
// Future names are supported
|
||||
api.Scheme.AddKnownTypeWithName("v1beta1", "Node", &Minion{})
|
||||
@@ -76,3 +77,4 @@ func (*ContainerManifest) IsAnAPIObject() {}
|
||||
func (*ContainerManifestList) IsAnAPIObject() {}
|
||||
func (*BoundPod) IsAnAPIObject() {}
|
||||
func (*BoundPods) IsAnAPIObject() {}
|
||||
func (*List) IsAnAPIObject() {}
|
||||
|
||||
@@ -19,6 +19,7 @@ package v1beta1
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
)
|
||||
|
||||
@@ -782,3 +783,9 @@ type BoundPods struct {
|
||||
// Items is the list of all pods bound to a given host.
|
||||
Items []BoundPod `json:"items" description:"list of all pods bound to a given host"`
|
||||
}
|
||||
|
||||
// List holds a list of objects, which may not be known by the server.
|
||||
type List struct {
|
||||
TypeMeta `json:",inline"`
|
||||
Items []runtime.RawExtension `json:"items" description:"list of objects"`
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ func init() {
|
||||
&ContainerManifestList{},
|
||||
&BoundPod{},
|
||||
&BoundPods{},
|
||||
&List{},
|
||||
)
|
||||
// Future names are supported
|
||||
api.Scheme.AddKnownTypeWithName("v1beta2", "Node", &Minion{})
|
||||
@@ -76,3 +77,4 @@ func (*ContainerManifest) IsAnAPIObject() {}
|
||||
func (*ContainerManifestList) IsAnAPIObject() {}
|
||||
func (*BoundPod) IsAnAPIObject() {}
|
||||
func (*BoundPods) IsAnAPIObject() {}
|
||||
func (*List) IsAnAPIObject() {}
|
||||
|
||||
@@ -19,6 +19,7 @@ package v1beta2
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
)
|
||||
|
||||
@@ -783,3 +784,9 @@ type BoundPods struct {
|
||||
// Items is the list of all pods bound to a given host.
|
||||
Items []BoundPod `json:"items" description:"list of all pods bound to a given host"`
|
||||
}
|
||||
|
||||
// List holds a list of objects, which may not be known by the server.
|
||||
type List struct {
|
||||
TypeMeta `json:",inline"`
|
||||
Items []runtime.RawExtension `json:"items" description:"list of objects"`
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ func init() {
|
||||
&OperationList{},
|
||||
&Event{},
|
||||
&EventList{},
|
||||
&List{},
|
||||
)
|
||||
// Legacy names are supported
|
||||
api.Scheme.AddKnownTypeWithName("v1beta3", "Minion", &Node{})
|
||||
@@ -72,3 +73,4 @@ func (*Operation) IsAnAPIObject() {}
|
||||
func (*OperationList) IsAnAPIObject() {}
|
||||
func (*Event) IsAnAPIObject() {}
|
||||
func (*EventList) IsAnAPIObject() {}
|
||||
func (*List) IsAnAPIObject() {}
|
||||
|
||||
@@ -19,6 +19,7 @@ package v1beta3
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
)
|
||||
|
||||
@@ -556,9 +557,14 @@ type ReplicationControllerSpec struct {
|
||||
// Selector is a label query over pods that should match the Replicas count.
|
||||
Selector map[string]string `json:"selector,omitempty"`
|
||||
|
||||
// Template is a reference to an object that describes the pod that will be created if
|
||||
// TemplateRef is a reference to an object that describes the pod that will be created if
|
||||
// insufficient replicas are detected.
|
||||
Template ObjectReference `json:"template,omitempty"`
|
||||
TemplateRef *ObjectReference `json:"templateRef,omitempty"`
|
||||
|
||||
// Template is the object that describes the pod that will be created if
|
||||
// insufficient replicas are detected. This takes precedence over a
|
||||
// TemplateRef.
|
||||
Template *PodTemplateSpec `json:"template,omitempty"`
|
||||
}
|
||||
|
||||
// ReplicationControllerStatus represents the current status of a replication
|
||||
@@ -944,3 +950,11 @@ type EventList struct {
|
||||
|
||||
Items []Event `json:"items"`
|
||||
}
|
||||
|
||||
// List holds a list of objects, which may not be known by the server.
|
||||
type List struct {
|
||||
TypeMeta `json:",inline"`
|
||||
ListMeta `json:"metadata,omitempty"`
|
||||
|
||||
Items []runtime.RawExtension `json:"items" description:"list of objects"`
|
||||
}
|
||||
|
||||
@@ -49,15 +49,6 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
|
||||
// APIVersion and Kind must remain blank in memory.
|
||||
j.APIVersion = ""
|
||||
j.Kind = ""
|
||||
|
||||
j.Name = c.RandString()
|
||||
j.ResourceVersion = strconv.FormatUint(c.RandUint64(), 10)
|
||||
j.SelfLink = c.RandString()
|
||||
|
||||
var sec, nsec int64
|
||||
c.Fuzz(&sec)
|
||||
c.Fuzz(&nsec)
|
||||
j.CreationTimestamp = util.Unix(sec, nsec).Rfc3339Copy()
|
||||
},
|
||||
func(j *api.TypeMeta, c fuzz.Continue) {
|
||||
// We have to customize the randomization of TypeMetas because their
|
||||
|
||||
Reference in New Issue
Block a user