deep copy

bugfix/cache_copy
Karolis Rusenas 2018-04-30 11:26:49 +01:00
parent 5530126229
commit 1ef5c89e2c
1 changed files with 25 additions and 15 deletions

View File

@ -59,6 +59,28 @@ func (r *GenericResource) String() string {
return fmt.Sprintf("%s/%s/%s images: %s", r.Kind(), r.Namespace, r.Name, strings.Join(r.GetImages(), ", ")) return fmt.Sprintf("%s/%s/%s images: %s", r.Kind(), r.Namespace, r.Name, strings.Join(r.GetImages(), ", "))
} }
// DeepCopy uses an autogenerated deepcopy functions, copying the receiver, creating a new GenericResource
func (r *GenericResource) DeepCopy() *GenericResource {
gr := new(GenericResource)
if r.obj == nil {
return gr
}
gr.Identifier = r.Identifier
gr.Namespace = r.Namespace
gr.Name = r.Name
switch obj := r.obj.(type) {
case *apps_v1.Deployment:
gr.obj = obj.DeepCopy()
case *apps_v1.StatefulSet:
gr.obj = obj.DeepCopy()
case *apps_v1.DaemonSet:
gr.obj = obj.DeepCopy()
}
return gr
}
// GetIdentifier returns resource identifier // GetIdentifier returns resource identifier
func (r *GenericResource) GetIdentifier() string { func (r *GenericResource) GetIdentifier() string {
switch obj := r.obj.(type) { switch obj := r.obj.(type) {
@ -146,23 +168,11 @@ func (r *GenericResource) SetLabels(labels map[string]string) {
func (r *GenericResource) GetSpecAnnotations() (annotations map[string]string) { func (r *GenericResource) GetSpecAnnotations() (annotations map[string]string) {
switch obj := r.obj.(type) { switch obj := r.obj.(type) {
case *apps_v1.Deployment: case *apps_v1.Deployment:
a := obj.Spec.Template.GetAnnotations() return getOrInitialise(obj.Spec.Template.GetAnnotations())
if a == nil {
return make(map[string]string)
}
return a
case *apps_v1.StatefulSet: case *apps_v1.StatefulSet:
a := obj.Spec.Template.GetAnnotations() return getOrInitialise(obj.Spec.Template.GetAnnotations())
if a == nil {
return make(map[string]string)
}
return a
case *apps_v1.DaemonSet: case *apps_v1.DaemonSet:
a := obj.Spec.Template.GetAnnotations() return getOrInitialise(obj.Spec.Template.GetAnnotations())
if a == nil {
return make(map[string]string)
}
return a
} }
return return
} }