From 37038c48773030c550637465b729f344c425da4b Mon Sep 17 00:00:00 2001 From: Federico Simoncelli Date: Sat, 25 Apr 2015 01:26:52 -0400 Subject: [PATCH] replica: serialize created-by reference Fixes #7322 Signed-off-by: Federico Simoncelli --- pkg/api/register.go | 2 ++ pkg/api/types.go | 5 +++++ pkg/api/v1/register.go | 2 ++ pkg/api/v1/types.go | 5 +++++ pkg/api/v1beta1/register.go | 2 ++ pkg/api/v1beta1/types.go | 5 +++++ pkg/api/v1beta2/register.go | 2 ++ pkg/api/v1beta2/types.go | 5 +++++ pkg/api/v1beta3/conversion.go | 22 ++++++++++++++++++++++ pkg/api/v1beta3/register.go | 2 ++ pkg/api/v1beta3/types.go | 5 +++++ pkg/controller/controller_utils.go | 7 ++++--- 12 files changed, 61 insertions(+), 3 deletions(-) diff --git a/pkg/api/register.go b/pkg/api/register.go index 2e22aa0eed4..cb816fc138e 100644 --- a/pkg/api/register.go +++ b/pkg/api/register.go @@ -64,6 +64,7 @@ func init() { &PodProxyOptions{}, &ComponentStatus{}, &ComponentStatusList{}, + &SerializedReference{}, ) // Legacy names are supported Scheme.AddKnownTypeWithName("", "Minion", &Node{}) @@ -109,3 +110,4 @@ func (*PodExecOptions) IsAnAPIObject() {} func (*PodProxyOptions) IsAnAPIObject() {} func (*ComponentStatus) IsAnAPIObject() {} func (*ComponentStatusList) IsAnAPIObject() {} +func (*SerializedReference) IsAnAPIObject() {} diff --git a/pkg/api/types.go b/pkg/api/types.go index 331181df362..683d5ba7d28 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -1593,6 +1593,11 @@ type ObjectReference struct { FieldPath string `json:"fieldPath,omitempty"` } +type SerializedReference struct { + TypeMeta `json:",inline"` + Reference ObjectReference `json:"reference,omitempty" description:"the reference to an object in the system"` +} + type EventSource struct { // Component from which the event is generated. Component string `json:"component,omitempty"` diff --git a/pkg/api/v1/register.go b/pkg/api/v1/register.go index 60abb799a48..e4219018187 100644 --- a/pkg/api/v1/register.go +++ b/pkg/api/v1/register.go @@ -63,6 +63,7 @@ func init() { &PodProxyOptions{}, &ComponentStatus{}, &ComponentStatusList{}, + &SerializedReference{}, ) // Legacy names are supported api.Scheme.AddKnownTypeWithName("v1", "Minion", &Node{}) @@ -106,3 +107,4 @@ func (*PodExecOptions) IsAnAPIObject() {} func (*PodProxyOptions) IsAnAPIObject() {} func (*ComponentStatus) IsAnAPIObject() {} func (*ComponentStatusList) IsAnAPIObject() {} +func (*SerializedReference) IsAnAPIObject() {} diff --git a/pkg/api/v1/types.go b/pkg/api/v1/types.go index dafa218d7d0..31d09e672e3 100644 --- a/pkg/api/v1/types.go +++ b/pkg/api/v1/types.go @@ -1525,6 +1525,11 @@ type ObjectReference struct { FieldPath string `json:"fieldPath,omitempty" description:"if referring to a piece of an object instead of an entire object, this string should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]"` } +type SerializedReference struct { + TypeMeta `json:",inline"` + Reference ObjectReference `json:"reference,omitempty" description:"the reference to an object in the system"` +} + type EventSource struct { // Component from which the event is generated. Component string `json:"component,omitempty" description:"component that generated the event"` diff --git a/pkg/api/v1beta1/register.go b/pkg/api/v1beta1/register.go index d5adc1220c3..dfae88c705e 100644 --- a/pkg/api/v1beta1/register.go +++ b/pkg/api/v1beta1/register.go @@ -70,6 +70,7 @@ func init() { &PodProxyOptions{}, &ComponentStatus{}, &ComponentStatusList{}, + &SerializedReference{}, ) // Future names are supported api.Scheme.AddKnownTypeWithName("v1beta1", "Node", &Minion{}) @@ -114,3 +115,4 @@ func (*PodExecOptions) IsAnAPIObject() {} func (*PodProxyOptions) IsAnAPIObject() {} func (*ComponentStatus) IsAnAPIObject() {} func (*ComponentStatusList) IsAnAPIObject() {} +func (*SerializedReference) IsAnAPIObject() {} diff --git a/pkg/api/v1beta1/types.go b/pkg/api/v1beta1/types.go index cec76c88b69..6aad89ec6b2 100644 --- a/pkg/api/v1beta1/types.go +++ b/pkg/api/v1beta1/types.go @@ -1380,6 +1380,11 @@ type ObjectReference struct { FieldPath string `json:"fieldPath,omitempty" description:"if referring to a piece of an object instead of an entire object, this string should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]"` } +type SerializedReference struct { + TypeMeta `json:",inline"` + Reference ObjectReference `json:"reference,omitempty" description:"the reference to an object in the system"` +} + // 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 { diff --git a/pkg/api/v1beta2/register.go b/pkg/api/v1beta2/register.go index 8028311468f..ab270fdbf7c 100644 --- a/pkg/api/v1beta2/register.go +++ b/pkg/api/v1beta2/register.go @@ -70,6 +70,7 @@ func init() { &PodProxyOptions{}, &ComponentStatus{}, &ComponentStatusList{}, + &SerializedReference{}, ) // Future names are supported api.Scheme.AddKnownTypeWithName("v1beta2", "Node", &Minion{}) @@ -114,3 +115,4 @@ func (*PodExecOptions) IsAnAPIObject() {} func (*PodProxyOptions) IsAnAPIObject() {} func (*ComponentStatus) IsAnAPIObject() {} func (*ComponentStatusList) IsAnAPIObject() {} +func (*SerializedReference) IsAnAPIObject() {} diff --git a/pkg/api/v1beta2/types.go b/pkg/api/v1beta2/types.go index 8d601d904ae..a45dc3fa70e 100644 --- a/pkg/api/v1beta2/types.go +++ b/pkg/api/v1beta2/types.go @@ -1413,6 +1413,11 @@ type ObjectReference struct { FieldPath string `json:"fieldPath,omitempty" description:"if referring to a piece of an object instead of an entire object, this string should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]"` } +type SerializedReference struct { + TypeMeta `json:",inline"` + Reference ObjectReference `json:"reference,omitempty" description:"the reference to an object in the system"` +} + // 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. // diff --git a/pkg/api/v1beta3/conversion.go b/pkg/api/v1beta3/conversion.go index c3ebf70fb15..524c28cef23 100644 --- a/pkg/api/v1beta3/conversion.go +++ b/pkg/api/v1beta3/conversion.go @@ -2581,6 +2581,26 @@ func convert_api_SecretVolumeSource_To_v1beta3_SecretVolumeSource(in *newer.Secr return nil } +func convert_v1beta3_SerializedReference_To_api_SerializedReference(in *SerializedReference, out *newer.SerializedReference, s conversion.Scope) error { + if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { + return err + } + if err := s.Convert(&in.Reference, &out.Reference, 0); err != nil { + return err + } + return nil +} + +func convert_api_SerializedReference_To_v1beta3_SerializedReference(in *newer.SerializedReference, out *SerializedReference, s conversion.Scope) error { + if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { + return err + } + if err := s.Convert(&in.Reference, &out.Reference, 0); err != nil { + return err + } + return nil +} + func convert_v1beta3_Service_To_api_Service(in *Service, out *newer.Service, s conversion.Scope) error { if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { return err @@ -3026,6 +3046,7 @@ func init() { convert_api_SecretList_To_v1beta3_SecretList, convert_api_SecretVolumeSource_To_v1beta3_SecretVolumeSource, convert_api_Secret_To_v1beta3_Secret, + convert_api_SerializedReference_To_v1beta3_SerializedReference, convert_api_ServiceList_To_v1beta3_ServiceList, convert_api_ServicePort_To_v1beta3_ServicePort, convert_api_ServiceSpec_To_v1beta3_ServiceSpec, @@ -3128,6 +3149,7 @@ func init() { convert_v1beta3_SecretList_To_api_SecretList, convert_v1beta3_SecretVolumeSource_To_api_SecretVolumeSource, convert_v1beta3_Secret_To_api_Secret, + convert_v1beta3_SerializedReference_To_api_SerializedReference, convert_v1beta3_ServiceList_To_api_ServiceList, convert_v1beta3_ServicePort_To_api_ServicePort, convert_v1beta3_ServiceSpec_To_api_ServiceSpec, diff --git a/pkg/api/v1beta3/register.go b/pkg/api/v1beta3/register.go index 8bff7838b00..781ae90f67c 100644 --- a/pkg/api/v1beta3/register.go +++ b/pkg/api/v1beta3/register.go @@ -63,6 +63,7 @@ func init() { &PodProxyOptions{}, &ComponentStatus{}, &ComponentStatusList{}, + &SerializedReference{}, ) // Legacy names are supported api.Scheme.AddKnownTypeWithName("v1beta3", "Minion", &Node{}) @@ -106,3 +107,4 @@ func (*PodExecOptions) IsAnAPIObject() {} func (*PodProxyOptions) IsAnAPIObject() {} func (*ComponentStatus) IsAnAPIObject() {} func (*ComponentStatusList) IsAnAPIObject() {} +func (*SerializedReference) IsAnAPIObject() {} diff --git a/pkg/api/v1beta3/types.go b/pkg/api/v1beta3/types.go index 4be4746ab73..6840bffa321 100644 --- a/pkg/api/v1beta3/types.go +++ b/pkg/api/v1beta3/types.go @@ -1525,6 +1525,11 @@ type ObjectReference struct { FieldPath string `json:"fieldPath,omitempty" description:"if referring to a piece of an object instead of an entire object, this string should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]"` } +type SerializedReference struct { + TypeMeta `json:",inline"` + Reference ObjectReference `json:"reference,omitempty" description:"the reference to an object in the system"` +} + type EventSource struct { // Component from which the event is generated. Component string `json:"component,omitempty" description:"component that generated the event"` diff --git a/pkg/controller/controller_utils.go b/pkg/controller/controller_utils.go index 2c97697167d..12f3fe11e52 100644 --- a/pkg/controller/controller_utils.go +++ b/pkg/controller/controller_utils.go @@ -17,10 +17,10 @@ limitations under the License. package controller import ( - "encoding/json" "fmt" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" + "github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation" "github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/client/cache" @@ -201,8 +201,9 @@ func (r RealPodControl) createReplica(namespace string, controller *api.Replicat if err != nil { return fmt.Errorf("unable to get controller reference: %v", err) } - // TODO: Version this serialization per #7322 - createdByRefJson, err := json.Marshal(createdByRef) + createdByRefJson, err := latest.Codec.Encode(&api.SerializedReference{ + Reference: *createdByRef, + }) if err != nil { return fmt.Errorf("unable to serialize controller reference: %v", err) }