Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-4.9] Bug 2040240: Make OriginImageMutators aware of origin objects #269

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

kapiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
kapi "k8s.io/kubernetes/pkg/apis/core"
Expand Down Expand Up @@ -66,3 +67,43 @@ func (o OriginImageMutators) GetImageReferenceMutator(obj, old runtime.Object) (
}
return o.KubeImageMutators.GetImageReferenceMutator(obj, old)
}

type annotationsAccessor struct {
object metav1.Object
template metav1.Object
}

func (a annotationsAccessor) Annotations() map[string]string {
return a.object.GetAnnotations()
}

func (a annotationsAccessor) TemplateAnnotations() (map[string]string, bool) {
if a.template == nil {
return nil, false
}
return a.template.GetAnnotations(), true
}

func (a annotationsAccessor) SetAnnotations(annotations map[string]string) {
a.object.SetAnnotations(annotations)
}

func (a annotationsAccessor) SetTemplateAnnotations(annotations map[string]string) bool {
if a.template == nil {
return false
}
a.template.SetAnnotations(annotations)
return true
}

// GetAnnotationAccessor returns an accessor for the provided object or false if the object
// does not support accessing annotations.
func (o OriginImageMutators) GetAnnotationAccessor(obj runtime.Object) (imagereferencemutators.AnnotationAccessor, bool) {
switch t := obj.(type) {
case metav1.Object:
templateObject, _ := getTemplateMetaObject(obj)
return annotationsAccessor{object: t, template: templateObject}, true
default:
return o.KubeImageMutators.GetAnnotationAccessor(obj)
}
}