From 66ccffc44bd11a7a6b5a4d9883188841e1d7c1ef Mon Sep 17 00:00:00 2001 From: Lennart Espe Date: Tue, 25 Feb 2020 00:13:35 +0100 Subject: [PATCH] Do fixup on empty annotations --- pkg/controller/controller.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index e136f6d..0cf4e34 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -55,7 +55,10 @@ const ( ) func (c *Controller) hasValidAnnotation(pod *v1.Pod) bool { - podAnnotations := pod.GetObjectMeta().GetAnnotations() + podAnnotations := pod.ObjectMeta.Annotations + if podAnnotations == nil { + podAnnotations = make(map[string]string) + } if podAnnotations[annotationEnableMattermost] == annotationEnableMattermostInform { return true } @@ -65,7 +68,10 @@ func (c *Controller) hasValidAnnotation(pod *v1.Pod) bool { klog.Infof("Failed to get replicaset: %v", err) return false } - rsAnnotations := rs.GetObjectMeta().GetAnnotations() + rsAnnotations := rs.ObjectMeta.Annotations + if rsAnnotations == nil { + rsAnnotations = make(map[string]string) + } podAnnotations[annotationMattermostBackoff] = rsAnnotations[annotationMattermostBackoff] if rsAnnotations[annotationEnableMattermost] == annotationEnableMattermostInform { return true @@ -75,7 +81,10 @@ func (c *Controller) hasValidAnnotation(pod *v1.Pod) bool { klog.Infof("Failed to get deployment: %v", err) return false } - depAnnotations := dep.GetObjectMeta().GetAnnotations() + depAnnotations := dep.ObjectMeta.Annotations + if depAnnotations == nil { + depAnnotations = make(map[string]string) + } podAnnotations[annotationMattermostBackoff] = depAnnotations[annotationMattermostBackoff] return depAnnotations[annotationEnableMattermost] == annotationEnableMattermostInform }