Skip to content

Commit c79916b

Browse files
committed
Add DeepCopy for ResourceMeta and ObjectMeta
1 parent 2ce1c7c commit c79916b

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

kyaml/yaml/types.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,53 @@ type MergeOptions struct {
247247
// source list to destination or append.
248248
ListIncreaseDirection MergeOptionsListIncreaseDirection
249249
}
250+
251+
// Since ObjectMeta and TypeMeta are stable, we manually create DeepCopy funcs for ResourceMeta and ObjectMeta.
252+
// For TypeMeta and NameMeta no DeepCopy funcs are required, as they only contain basic types.
253+
254+
// DeepCopyInto copies the receiver, writing into out. in must be non-nil.
255+
func (in *ObjectMeta) DeepCopyInto(out *ObjectMeta) {
256+
*out = *in
257+
out.NameMeta = in.NameMeta
258+
if in.Labels != nil {
259+
in, out := &in.Labels, &out.Labels
260+
*out = make(map[string]string, len(*in))
261+
for key, val := range *in {
262+
(*out)[key] = val
263+
}
264+
}
265+
if in.Annotations != nil {
266+
in, out := &in.Annotations, &out.Annotations
267+
*out = make(map[string]string, len(*in))
268+
for key, val := range *in {
269+
(*out)[key] = val
270+
}
271+
}
272+
}
273+
274+
// DeepCopy copies the receiver, creating a new ObjectMeta.
275+
func (in *ObjectMeta) DeepCopy() *ObjectMeta {
276+
if in == nil {
277+
return nil
278+
}
279+
out := new(ObjectMeta)
280+
in.DeepCopyInto(out)
281+
return out
282+
}
283+
284+
// DeepCopyInto copies the receiver, writing into out. in must be non-nil.
285+
func (in *ResourceMeta) DeepCopyInto(out *ResourceMeta) {
286+
*out = *in
287+
out.TypeMeta = in.TypeMeta
288+
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
289+
}
290+
291+
// DeepCopy copies the receiver, creating a new ResourceMeta.
292+
func (in *ResourceMeta) DeepCopy() *ResourceMeta {
293+
if in == nil {
294+
return nil
295+
}
296+
out := new(ResourceMeta)
297+
in.DeepCopyInto(out)
298+
return out
299+
}

0 commit comments

Comments
 (0)