Skip to content

Commit

Permalink
Merge pull request #5145 from SimonTheLeg/deepcopy-for-meta-types
Browse files Browse the repository at this point in the history
Add DeepCopy for ResourceMeta and ObjectMeta
  • Loading branch information
k8s-ci-robot authored Apr 26, 2023
2 parents 0f244a4 + c79916b commit ee3f506
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions kyaml/yaml/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,53 @@ type MergeOptions struct {
// source list to destination or append.
ListIncreaseDirection MergeOptionsListIncreaseDirection
}

// Since ObjectMeta and TypeMeta are stable, we manually create DeepCopy funcs for ResourceMeta and ObjectMeta.
// For TypeMeta and NameMeta no DeepCopy funcs are required, as they only contain basic types.

// DeepCopyInto copies the receiver, writing into out. in must be non-nil.
func (in *ObjectMeta) DeepCopyInto(out *ObjectMeta) {
*out = *in
out.NameMeta = in.NameMeta
if in.Labels != nil {
in, out := &in.Labels, &out.Labels
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
if in.Annotations != nil {
in, out := &in.Annotations, &out.Annotations
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
}

// DeepCopy copies the receiver, creating a new ObjectMeta.
func (in *ObjectMeta) DeepCopy() *ObjectMeta {
if in == nil {
return nil
}
out := new(ObjectMeta)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto copies the receiver, writing into out. in must be non-nil.
func (in *ResourceMeta) DeepCopyInto(out *ResourceMeta) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
}

// DeepCopy copies the receiver, creating a new ResourceMeta.
func (in *ResourceMeta) DeepCopy() *ResourceMeta {
if in == nil {
return nil
}
out := new(ResourceMeta)
in.DeepCopyInto(out)
return out
}

0 comments on commit ee3f506

Please sign in to comment.