From a6dd89d7975cddec251b3c920f186818c6a8622d Mon Sep 17 00:00:00 2001 From: gmarek Date: Wed, 11 May 2016 13:42:17 +0200 Subject: [PATCH 1/2] Add Controller field to OwnerReference --- api/swagger-spec/apps_v1alpha1.json | 6 +- api/swagger-spec/autoscaling_v1.json | 6 +- api/swagger-spec/batch_v1.json | 6 +- api/swagger-spec/extensions_v1beta1.json | 6 +- api/swagger-spec/policy_v1alpha1.json | 6 +- api/swagger-spec/v1.json | 6 +- .../autoscaling/v1/definitions.html | 11 +- docs/api-reference/batch/v1/definitions.html | 11 +- .../extensions/v1beta1/definitions.html | 11 +- docs/api-reference/v1/definitions.html | 11 +- pkg/api/deep_copy_generated.go | 7 + pkg/api/types.generated.go | 146 ++++++++++++++---- pkg/api/types.go | 6 +- pkg/api/v1/conversion_generated.go | 14 ++ pkg/api/v1/deep_copy_generated.go | 7 + pkg/api/v1/generated.pb.go | 34 ++++ pkg/api/v1/generated.proto | 7 +- pkg/api/v1/types.generated.go | 146 ++++++++++++++---- pkg/api/v1/types.go | 6 +- pkg/api/v1/types_swagger_doc_generated.go | 3 +- pkg/api/validation/validation.go | 9 ++ pkg/api/validation/validation_test.go | 97 ++++++++++-- 22 files changed, 465 insertions(+), 97 deletions(-) diff --git a/api/swagger-spec/apps_v1alpha1.json b/api/swagger-spec/apps_v1alpha1.json index 3d7b59baefb..d842bffb111 100644 --- a/api/swagger-spec/apps_v1alpha1.json +++ b/api/swagger-spec/apps_v1alpha1.json @@ -1100,7 +1100,7 @@ "items": { "$ref": "v1.OwnerReference" }, - "description": "List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected." + "description": "List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected. If this object is managed by a controller, then an entry in this list will point to this controller, with the controller field set to true. There cannot be more than one managing controller." }, "finalizers": { "type": "array", @@ -1136,6 +1136,10 @@ "uid": { "type": "string", "description": "UID of the referent. More info: http://releases.k8s.io/HEAD/docs/user-guide/identifiers.md#uids" + }, + "controller": { + "type": "boolean", + "description": "If true, this reference points to the managing controller." } } }, diff --git a/api/swagger-spec/autoscaling_v1.json b/api/swagger-spec/autoscaling_v1.json index ffedf2692fa..12d1dbbac0b 100644 --- a/api/swagger-spec/autoscaling_v1.json +++ b/api/swagger-spec/autoscaling_v1.json @@ -1103,7 +1103,7 @@ "items": { "$ref": "v1.OwnerReference" }, - "description": "List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected." + "description": "List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected. If this object is managed by a controller, then an entry in this list will point to this controller, with the controller field set to true. There cannot be more than one managing controller." }, "finalizers": { "type": "array", @@ -1139,6 +1139,10 @@ "uid": { "type": "string", "description": "UID of the referent. More info: http://releases.k8s.io/HEAD/docs/user-guide/identifiers.md#uids" + }, + "controller": { + "type": "boolean", + "description": "If true, this reference points to the managing controller." } } }, diff --git a/api/swagger-spec/batch_v1.json b/api/swagger-spec/batch_v1.json index 87e3c426f62..a8824a1a220 100644 --- a/api/swagger-spec/batch_v1.json +++ b/api/swagger-spec/batch_v1.json @@ -1103,7 +1103,7 @@ "items": { "$ref": "v1.OwnerReference" }, - "description": "List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected." + "description": "List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected. If this object is managed by a controller, then an entry in this list will point to this controller, with the controller field set to true. There cannot be more than one managing controller." }, "finalizers": { "type": "array", @@ -1139,6 +1139,10 @@ "uid": { "type": "string", "description": "UID of the referent. More info: http://releases.k8s.io/HEAD/docs/user-guide/identifiers.md#uids" + }, + "controller": { + "type": "boolean", + "description": "If true, this reference points to the managing controller." } } }, diff --git a/api/swagger-spec/extensions_v1beta1.json b/api/swagger-spec/extensions_v1beta1.json index db44f2d56f2..623a1a8ca5d 100644 --- a/api/swagger-spec/extensions_v1beta1.json +++ b/api/swagger-spec/extensions_v1beta1.json @@ -6949,7 +6949,7 @@ "items": { "$ref": "v1.OwnerReference" }, - "description": "List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected." + "description": "List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected. If this object is managed by a controller, then an entry in this list will point to this controller, with the controller field set to true. There cannot be more than one managing controller." }, "finalizers": { "type": "array", @@ -6985,6 +6985,10 @@ "uid": { "type": "string", "description": "UID of the referent. More info: http://releases.k8s.io/HEAD/docs/user-guide/identifiers.md#uids" + }, + "controller": { + "type": "boolean", + "description": "If true, this reference points to the managing controller." } } }, diff --git a/api/swagger-spec/policy_v1alpha1.json b/api/swagger-spec/policy_v1alpha1.json index bdb64e0ac0a..3d10d7dc9cf 100644 --- a/api/swagger-spec/policy_v1alpha1.json +++ b/api/swagger-spec/policy_v1alpha1.json @@ -1100,7 +1100,7 @@ "items": { "$ref": "v1.OwnerReference" }, - "description": "List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected." + "description": "List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected. If this object is managed by a controller, then an entry in this list will point to this controller, with the controller field set to true. There cannot be more than one managing controller." }, "finalizers": { "type": "array", @@ -1136,6 +1136,10 @@ "uid": { "type": "string", "description": "UID of the referent. More info: http://releases.k8s.io/HEAD/docs/user-guide/identifiers.md#uids" + }, + "controller": { + "type": "boolean", + "description": "If true, this reference points to the managing controller." } } }, diff --git a/api/swagger-spec/v1.json b/api/swagger-spec/v1.json index 711b5ae7c1c..52f755ec4ce 100644 --- a/api/swagger-spec/v1.json +++ b/api/swagger-spec/v1.json @@ -15884,7 +15884,7 @@ "items": { "$ref": "v1.OwnerReference" }, - "description": "List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected." + "description": "List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected. If this object is managed by a controller, then an entry in this list will point to this controller, with the controller field set to true. There cannot be more than one managing controller." }, "finalizers": { "type": "array", @@ -15920,6 +15920,10 @@ "uid": { "type": "string", "description": "UID of the referent. More info: http://releases.k8s.io/HEAD/docs/user-guide/identifiers.md#uids" + }, + "controller": { + "type": "boolean", + "description": "If true, this reference points to the managing controller." } } }, diff --git a/docs/api-reference/autoscaling/v1/definitions.html b/docs/api-reference/autoscaling/v1/definitions.html index 68336b212bb..a916e3749a8 100755 --- a/docs/api-reference/autoscaling/v1/definitions.html +++ b/docs/api-reference/autoscaling/v1/definitions.html @@ -1182,7 +1182,7 @@ Populated by the system when a graceful deletion is requested. Read-only. More i

ownerReferences

-

List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected.

+

List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected. If this object is managed by a controller, then an entry in this list will point to this controller, with the controller field set to true. There cannot be more than one managing controller.

false

v1.OwnerReference array

@@ -1249,6 +1249,13 @@ Populated by the system when a graceful deletion is requested. Read-only. More i

string

+ +

controller

+

If true, this reference points to the managing controller.

+

false

+

boolean

+

false

+ @@ -1324,4 +1331,4 @@ Last updated 2016-05-23 07:07:20 UTC - \ No newline at end of file + diff --git a/docs/api-reference/batch/v1/definitions.html b/docs/api-reference/batch/v1/definitions.html index ae27256e332..d3f902cd8f0 100755 --- a/docs/api-reference/batch/v1/definitions.html +++ b/docs/api-reference/batch/v1/definitions.html @@ -1737,7 +1737,7 @@ Populated by the system when a graceful deletion is requested. Read-only. More i

ownerReferences

-

List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected.

+

List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected. If this object is managed by a controller, then an entry in this list will point to this controller, with the controller field set to true. There cannot be more than one managing controller.

false

v1.OwnerReference array

@@ -1804,6 +1804,13 @@ Populated by the system when a graceful deletion is requested. Read-only. More i

string

+ +

controller

+

If true, this reference points to the managing controller.

+

false

+

boolean

+

false

+ @@ -4100,4 +4107,4 @@ Last updated 2016-05-24 11:53:33 UTC - \ No newline at end of file + diff --git a/docs/api-reference/extensions/v1beta1/definitions.html b/docs/api-reference/extensions/v1beta1/definitions.html index 28b4cd3e876..3117e055a62 100755 --- a/docs/api-reference/extensions/v1beta1/definitions.html +++ b/docs/api-reference/extensions/v1beta1/definitions.html @@ -1644,7 +1644,7 @@ Populated by the system when a graceful deletion is requested. Read-only. More i

ownerReferences

-

List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected.

+

List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected. If this object is managed by a controller, then an entry in this list will point to this controller, with the controller field set to true. There cannot be more than one managing controller.

false

v1.OwnerReference array

@@ -5010,6 +5010,13 @@ Both these may change in the future. Incoming requests are matched against the h

string

+ +

controller

+

If true, this reference points to the managing controller.

+

false

+

boolean

+

false

+ @@ -6090,4 +6097,4 @@ Last updated 2016-05-24 11:53:27 UTC - \ No newline at end of file + diff --git a/docs/api-reference/v1/definitions.html b/docs/api-reference/v1/definitions.html index 24be9495605..bb04e148819 100755 --- a/docs/api-reference/v1/definitions.html +++ b/docs/api-reference/v1/definitions.html @@ -1993,7 +1993,7 @@ Populated by the system when a graceful deletion is requested. Read-only. More i

ownerReferences

-

List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected.

+

List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected. If this object is managed by a controller, then an entry in this list will point to this controller, with the controller field set to true. There cannot be more than one managing controller.

false

v1.OwnerReference array

@@ -6066,6 +6066,13 @@ The resulting set of endpoints can be viewed as:

string

+ +

controller

+

If true, this reference points to the managing controller.

+

false

+

boolean

+

false

+ @@ -7995,4 +8002,4 @@ Last updated 2016-05-26 18:58:49 UTC - \ No newline at end of file + diff --git a/pkg/api/deep_copy_generated.go b/pkg/api/deep_copy_generated.go index ec1cd7ce7dd..35ded191b98 100644 --- a/pkg/api/deep_copy_generated.go +++ b/pkg/api/deep_copy_generated.go @@ -1706,6 +1706,13 @@ func DeepCopy_api_OwnerReference(in OwnerReference, out *OwnerReference, c *conv out.Kind = in.Kind out.Name = in.Name out.UID = in.UID + if in.Controller != nil { + in, out := in.Controller, &out.Controller + *out = new(bool) + **out = *in + } else { + out.Controller = nil + } return nil } diff --git a/pkg/api/types.generated.go b/pkg/api/types.generated.go index 37a3bcea03b..4d5a34fcf8b 100644 --- a/pkg/api/types.generated.go +++ b/pkg/api/types.generated.go @@ -44018,12 +44018,13 @@ func (x *OwnerReference) CodecEncodeSelf(e *codec1978.Encoder) { } else { yysep2 := !z.EncBinary() yy2arr2 := z.EncBasicHandle().StructToArray - var yyq2 [4]bool + var yyq2 [5]bool _, _, _ = yysep2, yyq2, yy2arr2 const yyr2 bool = false + yyq2[4] = x.Controller != nil var yynn2 int if yyr2 || yy2arr2 { - r.EncodeArrayStart(4) + r.EncodeArrayStart(5) } else { yynn2 = 4 for _, b := range yyq2 { @@ -44112,6 +44113,41 @@ func (x *OwnerReference) CodecEncodeSelf(e *codec1978.Encoder) { r.EncodeString(codecSelferC_UTF81234, string(x.UID)) } } + if yyr2 || yy2arr2 { + z.EncSendContainerState(codecSelfer_containerArrayElem1234) + if yyq2[4] { + if x.Controller == nil { + r.EncodeNil() + } else { + yy16 := *x.Controller + yym17 := z.EncBinary() + _ = yym17 + if false { + } else { + r.EncodeBool(bool(yy16)) + } + } + } else { + r.EncodeNil() + } + } else { + if yyq2[4] { + z.EncSendContainerState(codecSelfer_containerMapKey1234) + r.EncodeString(codecSelferC_UTF81234, string("controller")) + z.EncSendContainerState(codecSelfer_containerMapValue1234) + if x.Controller == nil { + r.EncodeNil() + } else { + yy18 := *x.Controller + yym19 := z.EncBinary() + _ = yym19 + if false { + } else { + r.EncodeBool(bool(yy18)) + } + } + } + } if yyr2 || yy2arr2 { z.EncSendContainerState(codecSelfer_containerArrayEnd1234) } else { @@ -44197,6 +44233,22 @@ func (x *OwnerReference) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { } else { x.UID = pkg1_types.UID(r.DecodeString()) } + case "controller": + if r.TryDecodeAsNil() { + if x.Controller != nil { + x.Controller = nil + } + } else { + if x.Controller == nil { + x.Controller = new(bool) + } + yym9 := z.DecBinary() + _ = yym9 + if false { + } else { + *((*bool)(x.Controller)) = r.DecodeBool() + } + } default: z.DecStructFieldNotFound(-1, yys3) } // end switch yys3 @@ -44208,16 +44260,16 @@ func (x *OwnerReference) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { var h codecSelfer1234 z, r := codec1978.GenHelperDecoder(d) _, _, _ = h, z, r - var yyj8 int - var yyb8 bool - var yyhl8 bool = l >= 0 - yyj8++ - if yyhl8 { - yyb8 = yyj8 > l + var yyj10 int + var yyb10 bool + var yyhl10 bool = l >= 0 + yyj10++ + if yyhl10 { + yyb10 = yyj10 > l } else { - yyb8 = r.CheckBreak() + yyb10 = r.CheckBreak() } - if yyb8 { + if yyb10 { z.DecSendContainerState(codecSelfer_containerArrayEnd1234) return } @@ -44227,13 +44279,13 @@ func (x *OwnerReference) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { } else { x.APIVersion = string(r.DecodeString()) } - yyj8++ - if yyhl8 { - yyb8 = yyj8 > l + yyj10++ + if yyhl10 { + yyb10 = yyj10 > l } else { - yyb8 = r.CheckBreak() + yyb10 = r.CheckBreak() } - if yyb8 { + if yyb10 { z.DecSendContainerState(codecSelfer_containerArrayEnd1234) return } @@ -44243,13 +44295,13 @@ func (x *OwnerReference) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { } else { x.Kind = string(r.DecodeString()) } - yyj8++ - if yyhl8 { - yyb8 = yyj8 > l + yyj10++ + if yyhl10 { + yyb10 = yyj10 > l } else { - yyb8 = r.CheckBreak() + yyb10 = r.CheckBreak() } - if yyb8 { + if yyb10 { z.DecSendContainerState(codecSelfer_containerArrayEnd1234) return } @@ -44259,13 +44311,13 @@ func (x *OwnerReference) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { } else { x.Name = string(r.DecodeString()) } - yyj8++ - if yyhl8 { - yyb8 = yyj8 > l + yyj10++ + if yyhl10 { + yyb10 = yyj10 > l } else { - yyb8 = r.CheckBreak() + yyb10 = r.CheckBreak() } - if yyb8 { + if yyb10 { z.DecSendContainerState(codecSelfer_containerArrayEnd1234) return } @@ -44275,18 +44327,44 @@ func (x *OwnerReference) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { } else { x.UID = pkg1_types.UID(r.DecodeString()) } - for { - yyj8++ - if yyhl8 { - yyb8 = yyj8 > l - } else { - yyb8 = r.CheckBreak() + yyj10++ + if yyhl10 { + yyb10 = yyj10 > l + } else { + yyb10 = r.CheckBreak() + } + if yyb10 { + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) + return + } + z.DecSendContainerState(codecSelfer_containerArrayElem1234) + if r.TryDecodeAsNil() { + if x.Controller != nil { + x.Controller = nil } - if yyb8 { + } else { + if x.Controller == nil { + x.Controller = new(bool) + } + yym16 := z.DecBinary() + _ = yym16 + if false { + } else { + *((*bool)(x.Controller)) = r.DecodeBool() + } + } + for { + yyj10++ + if yyhl10 { + yyb10 = yyj10 > l + } else { + yyb10 = r.CheckBreak() + } + if yyb10 { break } z.DecSendContainerState(codecSelfer_containerArrayElem1234) - z.DecStructFieldNotFound(yyj8-1, "") + z.DecStructFieldNotFound(yyj10-1, "") } z.DecSendContainerState(codecSelfer_containerArrayEnd1234) } @@ -52860,7 +52938,7 @@ func (x codecSelfer1234) decSliceOwnerReference(v *[]OwnerReference, d *codec197 yyrg1 := len(yyv1) > 0 yyv21 := yyv1 - yyrl1, yyrt1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 64) + yyrl1, yyrt1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 72) if yyrt1 { if yyrl1 <= cap(yyv1) { yyv1 = yyv1[:yyrl1] diff --git a/pkg/api/types.go b/pkg/api/types.go index 4847ba434c5..ff651936ee7 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -140,7 +140,9 @@ type ObjectMeta struct { Annotations map[string]string `json:"annotations,omitempty"` // List of objects depended by this object. If ALL objects in the list have - // been deleted, this object will be garbage collected. + // been deleted, this object will be garbage collected. If this object is managed by a controller, + // then an entry in this list will point to this controller, with the controller field set to true. + // There cannot be more than one managing controller. OwnerReferences []OwnerReference `json:"ownerReferences,omitempty"` // Must be empty before the object is deleted from the registry. Each entry @@ -2328,6 +2330,8 @@ type OwnerReference struct { // UID of the referent. // More info: http://releases.k8s.io/HEAD/docs/user-guide/identifiers.md#uids UID types.UID `json:"uid"` + // If true, this reference points to the managing controller. + Controller *bool `json:"controller,omitempty"` } // ObjectReference contains enough information to let you inspect or modify the referred object. diff --git a/pkg/api/v1/conversion_generated.go b/pkg/api/v1/conversion_generated.go index 3d1ce27a92c..6299f97eef3 100644 --- a/pkg/api/v1/conversion_generated.go +++ b/pkg/api/v1/conversion_generated.go @@ -3629,6 +3629,13 @@ func autoConvert_v1_OwnerReference_To_api_OwnerReference(in *OwnerReference, out out.Kind = in.Kind out.Name = in.Name out.UID = in.UID + if in.Controller != nil { + in, out := &in.Controller, &out.Controller + *out = new(bool) + **out = **in + } else { + out.Controller = nil + } return nil } @@ -3641,6 +3648,13 @@ func autoConvert_api_OwnerReference_To_v1_OwnerReference(in *api.OwnerReference, out.Kind = in.Kind out.Name = in.Name out.UID = in.UID + if in.Controller != nil { + in, out := &in.Controller, &out.Controller + *out = new(bool) + **out = **in + } else { + out.Controller = nil + } return nil } diff --git a/pkg/api/v1/deep_copy_generated.go b/pkg/api/v1/deep_copy_generated.go index 6f2b1e15331..8e759583d6a 100644 --- a/pkg/api/v1/deep_copy_generated.go +++ b/pkg/api/v1/deep_copy_generated.go @@ -1653,6 +1653,13 @@ func DeepCopy_v1_OwnerReference(in OwnerReference, out *OwnerReference, c *conve out.Kind = in.Kind out.Name = in.Name out.UID = in.UID + if in.Controller != nil { + in, out := in.Controller, &out.Controller + *out = new(bool) + **out = *in + } else { + out.Controller = nil + } return nil } diff --git a/pkg/api/v1/generated.pb.go b/pkg/api/v1/generated.pb.go index c78a2c03504..c933e40b56d 100644 --- a/pkg/api/v1/generated.pb.go +++ b/pkg/api/v1/generated.pb.go @@ -4452,6 +4452,16 @@ func (m *OwnerReference) MarshalTo(data []byte) (int, error) { i++ i = encodeVarintGenerated(data, i, uint64(len(m.APIVersion))) i += copy(data[i:], m.APIVersion) + if m.Controller != nil { + data[i] = 0x30 + i++ + if *m.Controller { + data[i] = 1 + } else { + data[i] = 0 + } + i++ + } return i, nil } @@ -8972,6 +8982,9 @@ func (m *OwnerReference) Size() (n int) { n += 1 + l + sovGenerated(uint64(l)) l = len(m.APIVersion) n += 1 + l + sovGenerated(uint64(l)) + if m.Controller != nil { + n += 2 + } return n } @@ -23033,6 +23046,27 @@ func (m *OwnerReference) Unmarshal(data []byte) error { } m.APIVersion = string(data[iNdEx:postIndex]) iNdEx = postIndex + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Controller", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + v |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + b := bool(v != 0) + m.Controller = &b default: iNdEx = preIndex skippy, err := skipGenerated(data[iNdEx:]) diff --git a/pkg/api/v1/generated.proto b/pkg/api/v1/generated.proto index bd4dbe7ab7b..4e22e2fa498 100644 --- a/pkg/api/v1/generated.proto +++ b/pkg/api/v1/generated.proto @@ -1461,7 +1461,9 @@ message ObjectMeta { map annotations = 12; // List of objects depended by this object. If ALL objects in the list have - // been deleted, this object will be garbage collected. + // been deleted, this object will be garbage collected. If this object is managed by a controller, + // then an entry in this list will point to this controller, with the controller field set to true. + // There cannot be more than one managing controller. repeated OwnerReference ownerReferences = 13; // Must be empty before the object is deleted from the registry. Each entry @@ -1525,6 +1527,9 @@ message OwnerReference { // UID of the referent. // More info: http://releases.k8s.io/HEAD/docs/user-guide/identifiers.md#uids optional string uid = 4; + + // If true, this reference points to the managing controller. + optional bool controller = 6; } // PersistentVolume (PV) is a storage resource provisioned by an administrator. diff --git a/pkg/api/v1/types.generated.go b/pkg/api/v1/types.generated.go index 4e66fdb43c2..dc0a9b011c1 100644 --- a/pkg/api/v1/types.generated.go +++ b/pkg/api/v1/types.generated.go @@ -43760,12 +43760,13 @@ func (x *OwnerReference) CodecEncodeSelf(e *codec1978.Encoder) { } else { yysep2 := !z.EncBinary() yy2arr2 := z.EncBasicHandle().StructToArray - var yyq2 [4]bool + var yyq2 [5]bool _, _, _ = yysep2, yyq2, yy2arr2 const yyr2 bool = false + yyq2[4] = x.Controller != nil var yynn2 int if yyr2 || yy2arr2 { - r.EncodeArrayStart(4) + r.EncodeArrayStart(5) } else { yynn2 = 4 for _, b := range yyq2 { @@ -43854,6 +43855,41 @@ func (x *OwnerReference) CodecEncodeSelf(e *codec1978.Encoder) { r.EncodeString(codecSelferC_UTF81234, string(x.UID)) } } + if yyr2 || yy2arr2 { + z.EncSendContainerState(codecSelfer_containerArrayElem1234) + if yyq2[4] { + if x.Controller == nil { + r.EncodeNil() + } else { + yy16 := *x.Controller + yym17 := z.EncBinary() + _ = yym17 + if false { + } else { + r.EncodeBool(bool(yy16)) + } + } + } else { + r.EncodeNil() + } + } else { + if yyq2[4] { + z.EncSendContainerState(codecSelfer_containerMapKey1234) + r.EncodeString(codecSelferC_UTF81234, string("controller")) + z.EncSendContainerState(codecSelfer_containerMapValue1234) + if x.Controller == nil { + r.EncodeNil() + } else { + yy18 := *x.Controller + yym19 := z.EncBinary() + _ = yym19 + if false { + } else { + r.EncodeBool(bool(yy18)) + } + } + } + } if yyr2 || yy2arr2 { z.EncSendContainerState(codecSelfer_containerArrayEnd1234) } else { @@ -43939,6 +43975,22 @@ func (x *OwnerReference) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { } else { x.UID = pkg1_types.UID(r.DecodeString()) } + case "controller": + if r.TryDecodeAsNil() { + if x.Controller != nil { + x.Controller = nil + } + } else { + if x.Controller == nil { + x.Controller = new(bool) + } + yym9 := z.DecBinary() + _ = yym9 + if false { + } else { + *((*bool)(x.Controller)) = r.DecodeBool() + } + } default: z.DecStructFieldNotFound(-1, yys3) } // end switch yys3 @@ -43950,16 +44002,16 @@ func (x *OwnerReference) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { var h codecSelfer1234 z, r := codec1978.GenHelperDecoder(d) _, _, _ = h, z, r - var yyj8 int - var yyb8 bool - var yyhl8 bool = l >= 0 - yyj8++ - if yyhl8 { - yyb8 = yyj8 > l + var yyj10 int + var yyb10 bool + var yyhl10 bool = l >= 0 + yyj10++ + if yyhl10 { + yyb10 = yyj10 > l } else { - yyb8 = r.CheckBreak() + yyb10 = r.CheckBreak() } - if yyb8 { + if yyb10 { z.DecSendContainerState(codecSelfer_containerArrayEnd1234) return } @@ -43969,13 +44021,13 @@ func (x *OwnerReference) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { } else { x.APIVersion = string(r.DecodeString()) } - yyj8++ - if yyhl8 { - yyb8 = yyj8 > l + yyj10++ + if yyhl10 { + yyb10 = yyj10 > l } else { - yyb8 = r.CheckBreak() + yyb10 = r.CheckBreak() } - if yyb8 { + if yyb10 { z.DecSendContainerState(codecSelfer_containerArrayEnd1234) return } @@ -43985,13 +44037,13 @@ func (x *OwnerReference) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { } else { x.Kind = string(r.DecodeString()) } - yyj8++ - if yyhl8 { - yyb8 = yyj8 > l + yyj10++ + if yyhl10 { + yyb10 = yyj10 > l } else { - yyb8 = r.CheckBreak() + yyb10 = r.CheckBreak() } - if yyb8 { + if yyb10 { z.DecSendContainerState(codecSelfer_containerArrayEnd1234) return } @@ -44001,13 +44053,13 @@ func (x *OwnerReference) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { } else { x.Name = string(r.DecodeString()) } - yyj8++ - if yyhl8 { - yyb8 = yyj8 > l + yyj10++ + if yyhl10 { + yyb10 = yyj10 > l } else { - yyb8 = r.CheckBreak() + yyb10 = r.CheckBreak() } - if yyb8 { + if yyb10 { z.DecSendContainerState(codecSelfer_containerArrayEnd1234) return } @@ -44017,18 +44069,44 @@ func (x *OwnerReference) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { } else { x.UID = pkg1_types.UID(r.DecodeString()) } - for { - yyj8++ - if yyhl8 { - yyb8 = yyj8 > l - } else { - yyb8 = r.CheckBreak() + yyj10++ + if yyhl10 { + yyb10 = yyj10 > l + } else { + yyb10 = r.CheckBreak() + } + if yyb10 { + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) + return + } + z.DecSendContainerState(codecSelfer_containerArrayElem1234) + if r.TryDecodeAsNil() { + if x.Controller != nil { + x.Controller = nil } - if yyb8 { + } else { + if x.Controller == nil { + x.Controller = new(bool) + } + yym16 := z.DecBinary() + _ = yym16 + if false { + } else { + *((*bool)(x.Controller)) = r.DecodeBool() + } + } + for { + yyj10++ + if yyhl10 { + yyb10 = yyj10 > l + } else { + yyb10 = r.CheckBreak() + } + if yyb10 { break } z.DecSendContainerState(codecSelfer_containerArrayElem1234) - z.DecStructFieldNotFound(yyj8-1, "") + z.DecStructFieldNotFound(yyj10-1, "") } z.DecSendContainerState(codecSelfer_containerArrayEnd1234) } @@ -53032,7 +53110,7 @@ func (x codecSelfer1234) decSliceOwnerReference(v *[]OwnerReference, d *codec197 yyrg1 := len(yyv1) > 0 yyv21 := yyv1 - yyrl1, yyrt1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 64) + yyrl1, yyrt1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 72) if yyrt1 { if yyrl1 <= cap(yyv1) { yyv1 = yyv1[:yyrl1] diff --git a/pkg/api/v1/types.go b/pkg/api/v1/types.go index 382c5513fbe..400646c3566 100644 --- a/pkg/api/v1/types.go +++ b/pkg/api/v1/types.go @@ -177,7 +177,9 @@ type ObjectMeta struct { Annotations map[string]string `json:"annotations,omitempty" protobuf:"bytes,12,rep,name=annotations"` // List of objects depended by this object. If ALL objects in the list have - // been deleted, this object will be garbage collected. + // been deleted, this object will be garbage collected. If this object is managed by a controller, + // then an entry in this list will point to this controller, with the controller field set to true. + // There cannot be more than one managing controller. OwnerReferences []OwnerReference `json:"ownerReferences,omitempty" patchStrategy:"merge" patchMergeKey:"uid" protobuf:"bytes,13,rep,name=ownerReferences"` // Must be empty before the object is deleted from the registry. Each entry @@ -2775,6 +2777,8 @@ type OwnerReference struct { // UID of the referent. // More info: http://releases.k8s.io/HEAD/docs/user-guide/identifiers.md#uids UID types.UID `json:"uid" protobuf:"bytes,4,opt,name=uid,casttype=k8s.io/kubernetes/pkg/types.UID"` + // If true, this reference points to the managing controller. + Controller *bool `json:"controller,omitempty" protobuf:"varint,6,opt,name=controller"` } // ObjectReference contains enough information to let you inspect or modify the referred object. diff --git a/pkg/api/v1/types_swagger_doc_generated.go b/pkg/api/v1/types_swagger_doc_generated.go index c18b5e7e4b2..93a714586f1 100644 --- a/pkg/api/v1/types_swagger_doc_generated.go +++ b/pkg/api/v1/types_swagger_doc_generated.go @@ -928,7 +928,7 @@ var map_ObjectMeta = map[string]string{ "deletionGracePeriodSeconds": "Number of seconds allowed for this object to gracefully terminate before it will be removed from the system. Only set when deletionTimestamp is also set. May only be shortened. Read-only.", "labels": "Map of string keys and values that can be used to organize and categorize (scope and select) objects. May match selectors of replication controllers and services. More info: http://releases.k8s.io/HEAD/docs/user-guide/labels.md", "annotations": "Annotations is an unstructured key value map stored with a resource that may be set by external tools to store and retrieve arbitrary metadata. They are not queryable and should be preserved when modifying objects. More info: http://releases.k8s.io/HEAD/docs/user-guide/annotations.md", - "ownerReferences": "List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected.", + "ownerReferences": "List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected. If this object is managed by a controller, then an entry in this list will point to this controller, with the controller field set to true. There cannot be more than one managing controller.", "finalizers": "Must be empty before the object is deleted from the registry. Each entry is an identifier for the responsible component that will remove the entry from the list. If the deletionTimestamp of the object is non-nil, entries in this list can only be removed.", } @@ -957,6 +957,7 @@ var map_OwnerReference = map[string]string{ "kind": "Kind of the referent. More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds", "name": "Name of the referent. More info: http://releases.k8s.io/HEAD/docs/user-guide/identifiers.md#names", "uid": "UID of the referent. More info: http://releases.k8s.io/HEAD/docs/user-guide/identifiers.md#uids", + "controller": "If true, this reference points to the managing controller.", } func (OwnerReference) SwaggerDoc() map[string]string { diff --git a/pkg/api/validation/validation.go b/pkg/api/validation/validation.go index 1144cefb249..822a35735c7 100644 --- a/pkg/api/validation/validation.go +++ b/pkg/api/validation/validation.go @@ -160,8 +160,17 @@ func validateOwnerReference(ownerReference api.OwnerReference, fldPath *field.Pa func ValidateOwnerReferences(ownerReferences []api.OwnerReference, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} + controllerName := "" for _, ref := range ownerReferences { allErrs = append(allErrs, validateOwnerReference(ref, fldPath)...) + if ref.Controller != nil && *ref.Controller { + if controllerName != "" { + allErrs = append(allErrs, field.Invalid(fldPath, ownerReferences, + fmt.Sprintf("Only one reference can have Controller set to true. Found \"true\" in references for %v and %v", controllerName, ref.Name))) + } else { + controllerName = ref.Name + } + } } return allErrs } diff --git a/pkg/api/validation/validation_test.go b/pkg/api/validation/validation_test.go index 9e7bbdb23de..4ef74488e72 100644 --- a/pkg/api/validation/validation_test.go +++ b/pkg/api/validation/validation_test.go @@ -99,12 +99,17 @@ func TestValidateObjectMetaNamespaces(t *testing.T) { } func TestValidateObjectMetaOwnerReferences(t *testing.T) { + trueVar := true + falseVar := false testCases := []struct { - ownerReferences []api.OwnerReference - expectError bool + description string + ownerReferences []api.OwnerReference + expectError bool + expectedErrorMessage string }{ { - []api.OwnerReference{ + description: "simple success - third party extension.", + ownerReferences: []api.OwnerReference{ { APIVersion: "thirdpartyVersion", Kind: "thirdpartyKind", @@ -112,11 +117,12 @@ func TestValidateObjectMetaOwnerReferences(t *testing.T) { UID: "1", }, }, - false, + expectError: false, + expectedErrorMessage: "", }, { - // event shouldn't be set as an owner - []api.OwnerReference{ + description: "simple failures - event shouldn't be set as an owner", + ownerReferences: []api.OwnerReference{ { APIVersion: "v1", Kind: "Event", @@ -124,7 +130,76 @@ func TestValidateObjectMetaOwnerReferences(t *testing.T) { UID: "1", }, }, - true, + expectError: true, + expectedErrorMessage: "is disallowed from being an owner", + }, + { + description: "simple controller ref success - one reference with Controller set", + ownerReferences: []api.OwnerReference{ + { + APIVersion: "thirdpartyVersion", + Kind: "thirdpartyKind", + Name: "name", + UID: "1", + Controller: &falseVar, + }, + { + APIVersion: "thirdpartyVersion", + Kind: "thirdpartyKind", + Name: "name", + UID: "2", + Controller: &trueVar, + }, + { + APIVersion: "thirdpartyVersion", + Kind: "thirdpartyKind", + Name: "name", + UID: "3", + Controller: &falseVar, + }, + { + APIVersion: "thirdpartyVersion", + Kind: "thirdpartyKind", + Name: "name", + UID: "4", + }, + }, + expectError: false, + expectedErrorMessage: "", + }, + { + description: "simple controller ref failure - two references with Controller set", + ownerReferences: []api.OwnerReference{ + { + APIVersion: "thirdpartyVersion", + Kind: "thirdpartyKind", + Name: "name", + UID: "1", + Controller: &falseVar, + }, + { + APIVersion: "thirdpartyVersion", + Kind: "thirdpartyKind", + Name: "name", + UID: "2", + Controller: &trueVar, + }, + { + APIVersion: "thirdpartyVersion", + Kind: "thirdpartyKind", + Name: "name", + UID: "3", + Controller: &trueVar, + }, + { + APIVersion: "thirdpartyVersion", + Kind: "thirdpartyKind", + Name: "name", + UID: "4", + }, + }, + expectError: true, + expectedErrorMessage: "Only one reference can have Controller set to true", }, } @@ -137,13 +212,13 @@ func TestValidateObjectMetaOwnerReferences(t *testing.T) { }, field.NewPath("field")) if len(errs) != 0 && !tc.expectError { - t.Errorf("unexpected error: %v", errs) + t.Errorf("unexpected error: %v in test case %v", errs, tc.description) } if len(errs) == 0 && tc.expectError { - t.Errorf("expect error") + t.Errorf("expect error in test case %v", tc.description) } - if len(errs) != 0 && !strings.Contains(errs[0].Error(), "is disallowed from being an owner") { - t.Errorf("unexpected error message: %v", errs) + if len(errs) != 0 && !strings.Contains(errs[0].Error(), tc.expectedErrorMessage) { + t.Errorf("unexpected error message: %v in test case %v", errs, tc.description) } } } From 778b1df717215f0e0a03a83b467be7f7d0e02367 Mon Sep 17 00:00:00 2001 From: gmarek Date: Fri, 20 May 2016 14:38:19 +0200 Subject: [PATCH 2/2] Add Controller to api/meta --- .../rbac.authorization.k8s.io_v1alpha1.json | 6 +++++- .../autoscaling/v1/definitions.html | 2 +- docs/api-reference/batch/v1/definitions.html | 2 +- .../extensions/v1beta1/definitions.html | 2 +- docs/api-reference/v1/definitions.html | 2 +- pkg/api/meta.go | 8 ++++++++ pkg/api/meta/meta.go | 14 ++++++++++++++ pkg/api/meta/meta_test.go | 1 + pkg/api/meta/metatypes/deep_copy_generated.go | 4 ++++ pkg/api/meta/metatypes/types.go | 1 + pkg/api/meta_test.go | 1 + pkg/api/v1/conversion_generated.go | 16 ++-------------- pkg/runtime/types.go | 16 ++++++++++++++++ pkg/runtime/unstructured_test.go | 4 ++++ 14 files changed, 60 insertions(+), 19 deletions(-) diff --git a/api/swagger-spec/rbac.authorization.k8s.io_v1alpha1.json b/api/swagger-spec/rbac.authorization.k8s.io_v1alpha1.json index 3d1aeea5582..efe783ae4a0 100644 --- a/api/swagger-spec/rbac.authorization.k8s.io_v1alpha1.json +++ b/api/swagger-spec/rbac.authorization.k8s.io_v1alpha1.json @@ -2773,7 +2773,7 @@ "items": { "$ref": "v1.OwnerReference" }, - "description": "List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected." + "description": "List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected. If this object is managed by a controller, then an entry in this list will point to this controller, with the controller field set to true. There cannot be more than one managing controller." }, "finalizers": { "type": "array", @@ -2809,6 +2809,10 @@ "uid": { "type": "string", "description": "UID of the referent. More info: http://releases.k8s.io/HEAD/docs/user-guide/identifiers.md#uids" + }, + "controller": { + "type": "boolean", + "description": "If true, this reference points to the managing controller." } } }, diff --git a/docs/api-reference/autoscaling/v1/definitions.html b/docs/api-reference/autoscaling/v1/definitions.html index a916e3749a8..733b1bc67d6 100755 --- a/docs/api-reference/autoscaling/v1/definitions.html +++ b/docs/api-reference/autoscaling/v1/definitions.html @@ -1331,4 +1331,4 @@ Last updated 2016-05-23 07:07:20 UTC - + \ No newline at end of file diff --git a/docs/api-reference/batch/v1/definitions.html b/docs/api-reference/batch/v1/definitions.html index d3f902cd8f0..18754573de4 100755 --- a/docs/api-reference/batch/v1/definitions.html +++ b/docs/api-reference/batch/v1/definitions.html @@ -4107,4 +4107,4 @@ Last updated 2016-05-24 11:53:33 UTC - + \ No newline at end of file diff --git a/docs/api-reference/extensions/v1beta1/definitions.html b/docs/api-reference/extensions/v1beta1/definitions.html index 3117e055a62..a38cf74d7ea 100755 --- a/docs/api-reference/extensions/v1beta1/definitions.html +++ b/docs/api-reference/extensions/v1beta1/definitions.html @@ -6097,4 +6097,4 @@ Last updated 2016-05-24 11:53:27 UTC - + \ No newline at end of file diff --git a/docs/api-reference/v1/definitions.html b/docs/api-reference/v1/definitions.html index bb04e148819..0974c68f55f 100755 --- a/docs/api-reference/v1/definitions.html +++ b/docs/api-reference/v1/definitions.html @@ -8002,4 +8002,4 @@ Last updated 2016-05-26 18:58:49 UTC - + \ No newline at end of file diff --git a/pkg/api/meta.go b/pkg/api/meta.go index f3f84063dd8..d715d58a116 100644 --- a/pkg/api/meta.go +++ b/pkg/api/meta.go @@ -100,6 +100,10 @@ func (meta *ObjectMeta) GetOwnerReferences() []metatypes.OwnerReference { ret[i].Name = meta.OwnerReferences[i].Name ret[i].UID = meta.OwnerReferences[i].UID ret[i].APIVersion = meta.OwnerReferences[i].APIVersion + if meta.OwnerReferences[i].Controller != nil { + value := *meta.OwnerReferences[i].Controller + ret[i].Controller = &value + } } return ret } @@ -111,6 +115,10 @@ func (meta *ObjectMeta) SetOwnerReferences(references []metatypes.OwnerReference newReferences[i].Name = references[i].Name newReferences[i].UID = references[i].UID newReferences[i].APIVersion = references[i].APIVersion + if references[i].Controller != nil { + value := *references[i].Controller + newReferences[i].Controller = &value + } } meta.OwnerReferences = newReferences } diff --git a/pkg/api/meta/meta.go b/pkg/api/meta/meta.go index b9c8d69d02c..3a3d1fc73d8 100644 --- a/pkg/api/meta/meta.go +++ b/pkg/api/meta/meta.go @@ -359,6 +359,14 @@ func extractFromOwnerReference(v reflect.Value, o *metatypes.OwnerReference) err if err := runtime.Field(v, "UID", &o.UID); err != nil { return err } + var controllerPtr *bool + if err := runtime.Field(v, "Controller", &controllerPtr); err != nil { + return err + } + if controllerPtr != nil { + controller := *controllerPtr + o.Controller = &controller + } return nil } @@ -376,6 +384,12 @@ func setOwnerReference(v reflect.Value, o *metatypes.OwnerReference) error { if err := runtime.SetField(o.UID, v, "UID"); err != nil { return err } + if o.Controller != nil { + controller := *(o.Controller) + if err := runtime.SetField(&controller, v, "Controller"); err != nil { + return err + } + } return nil } diff --git a/pkg/api/meta/meta_test.go b/pkg/api/meta/meta_test.go index 73eeffb98e2..cfcd724107f 100644 --- a/pkg/api/meta/meta_test.go +++ b/pkg/api/meta/meta_test.go @@ -781,6 +781,7 @@ func getObjectMetaAndOwnerRefereneces() (myAPIObject2 MyAPIObject2, metaOwnerRef Name: references[i].Name, UID: references[i].UID, APIVersion: references[i].APIVersion, + Controller: references[i].Controller, }) } if len(references) == 0 { diff --git a/pkg/api/meta/metatypes/deep_copy_generated.go b/pkg/api/meta/metatypes/deep_copy_generated.go index f06a194e54a..5033d2494cc 100644 --- a/pkg/api/meta/metatypes/deep_copy_generated.go +++ b/pkg/api/meta/metatypes/deep_copy_generated.go @@ -29,5 +29,9 @@ func DeepCopy_metatypes_OwnerReference(in OwnerReference, out *OwnerReference, c out.Kind = in.Kind out.UID = in.UID out.Name = in.Name + if in.Controller != nil { + value := *in.Controller + out.Controller = &value + } return nil } diff --git a/pkg/api/meta/metatypes/types.go b/pkg/api/meta/metatypes/types.go index ca4edf72e28..e7ac3e08d7f 100644 --- a/pkg/api/meta/metatypes/types.go +++ b/pkg/api/meta/metatypes/types.go @@ -26,4 +26,5 @@ type OwnerReference struct { Kind string UID types.UID Name string + Controller *bool } diff --git a/pkg/api/meta_test.go b/pkg/api/meta_test.go index cbac57e88ce..689e760e536 100644 --- a/pkg/api/meta_test.go +++ b/pkg/api/meta_test.go @@ -64,6 +64,7 @@ func getObjectMetaAndOwnerReferences() (objectMeta api.ObjectMeta, metaOwnerRefe Name: references[i].Name, UID: references[i].UID, APIVersion: references[i].APIVersion, + Controller: references[i].Controller, }) } if len(references) == 0 { diff --git a/pkg/api/v1/conversion_generated.go b/pkg/api/v1/conversion_generated.go index 6299f97eef3..9640a5edc39 100644 --- a/pkg/api/v1/conversion_generated.go +++ b/pkg/api/v1/conversion_generated.go @@ -3629,13 +3629,7 @@ func autoConvert_v1_OwnerReference_To_api_OwnerReference(in *OwnerReference, out out.Kind = in.Kind out.Name = in.Name out.UID = in.UID - if in.Controller != nil { - in, out := &in.Controller, &out.Controller - *out = new(bool) - **out = **in - } else { - out.Controller = nil - } + out.Controller = in.Controller return nil } @@ -3648,13 +3642,7 @@ func autoConvert_api_OwnerReference_To_v1_OwnerReference(in *api.OwnerReference, out.Kind = in.Kind out.Name = in.Name out.UID = in.UID - if in.Controller != nil { - in, out := &in.Controller, &out.Controller - *out = new(bool) - **out = **in - } else { - out.Controller = nil - } + out.Controller = in.Controller return nil } diff --git a/pkg/runtime/types.go b/pkg/runtime/types.go index 0c6d48afc4a..33f7c3630fa 100644 --- a/pkg/runtime/types.go +++ b/pkg/runtime/types.go @@ -231,20 +231,36 @@ func (u *Unstructured) setNestedMap(value map[string]string, fields ...string) { func extractOwnerReference(src interface{}) metatypes.OwnerReference { v := src.(map[string]interface{}) + controllerPtr, ok := (getNestedField(v, "controller")).(*bool) + if !ok { + controllerPtr = nil + } else { + if controllerPtr != nil { + controller := *controllerPtr + controllerPtr = &controller + } + } return metatypes.OwnerReference{ Kind: getNestedString(v, "kind"), Name: getNestedString(v, "name"), APIVersion: getNestedString(v, "apiVersion"), UID: (types.UID)(getNestedString(v, "uid")), + Controller: controllerPtr, } } func setOwnerReference(src metatypes.OwnerReference) map[string]interface{} { ret := make(map[string]interface{}) + controllerPtr := src.Controller + if controllerPtr != nil { + controller := *controllerPtr + controllerPtr = &controller + } setNestedField(ret, src.Kind, "kind") setNestedField(ret, src.Name, "name") setNestedField(ret, src.APIVersion, "apiVersion") setNestedField(ret, string(src.UID), "uid") + setNestedField(ret, controllerPtr, "controller") return ret } diff --git a/pkg/runtime/unstructured_test.go b/pkg/runtime/unstructured_test.go index db87f78420b..cf808185c63 100644 --- a/pkg/runtime/unstructured_test.go +++ b/pkg/runtime/unstructured_test.go @@ -236,6 +236,7 @@ func TestUnstructuredGetters(t *testing.T) { func TestUnstructuredSetters(t *testing.T) { unstruct := runtime.Unstructured{} + trueVar := true want := runtime.Unstructured{ Object: map[string]interface{}{ @@ -262,12 +263,14 @@ func TestUnstructuredSetters(t *testing.T) { "name": "poda", "apiVersion": "v1", "uid": "1", + "controller": (*bool)(nil), }, { "kind": "Pod", "name": "podb", "apiVersion": "v1", "uid": "2", + "controller": &trueVar, }, }, "finalizers": []interface{}{ @@ -303,6 +306,7 @@ func TestUnstructuredSetters(t *testing.T) { Name: "podb", APIVersion: "v1", UID: "2", + Controller: &trueVar, }, } unstruct.SetOwnerReferences(newOwnerReferences)