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 0243d6fe161..c172ca4e8fc 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -1591,6 +1591,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 697c6b01dcc..ae1c424449f 100644 --- a/pkg/api/v1/types.go +++ b/pkg/api/v1/types.go @@ -1527,6 +1527,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 8a63544218c..951a2f92d73 100644 --- a/pkg/api/v1beta1/types.go +++ b/pkg/api/v1beta1/types.go @@ -1382,6 +1382,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 c844818025f..a1b3d0d31aa 100644 --- a/pkg/api/v1beta2/types.go +++ b/pkg/api/v1beta2/types.go @@ -1415,6 +1415,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 35073f6bfd4..6953b1dd4cb 100644 --- a/pkg/api/v1beta3/conversion.go +++ b/pkg/api/v1beta3/conversion.go @@ -2098,6 +2098,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 @@ -2531,6 +2551,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, @@ -2621,6 +2642,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 54370cbf938..b0ff3fd8647 100644 --- a/pkg/api/v1beta3/types.go +++ b/pkg/api/v1beta3/types.go @@ -1527,6 +1527,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) }