From 5024270232ef08d3c7459abc0bf2352131428af7 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 26 Mar 2019 17:20:24 +0000 Subject: [PATCH] Avoid panic on nil map It can be set to nil after a failed update; check rather than crashing. --- prog/kube-utils/annotations.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/prog/kube-utils/annotations.go b/prog/kube-utils/annotations.go index 195273a2..f83b676a 100644 --- a/prog/kube-utils/annotations.go +++ b/prog/kube-utils/annotations.go @@ -96,7 +96,7 @@ func (cml *configMapAnnotations) GetAnnotation(key string) (string, bool) { } func (cml *configMapAnnotations) UpdateAnnotation(key, value string) (err error) { - if cml.cm == nil { + if cml.cm == nil || cml.cm.Annotations == nil { return errors.New("endpoint not initialized, call Init first") } // speculatively change the state, then replace with whatever comes back @@ -107,7 +107,7 @@ func (cml *configMapAnnotations) UpdateAnnotation(key, value string) (err error) } func (cml *configMapAnnotations) RemoveAnnotation(key string) (err error) { - if cml.cm == nil { + if cml.cm == nil || cml.cm.Annotations == nil { return errors.New("endpoint not initialized, call Init first") } // speculatively change the state, then replace with whatever comes back @@ -118,7 +118,7 @@ func (cml *configMapAnnotations) RemoveAnnotation(key string) (err error) { } func (cml *configMapAnnotations) RemoveAnnotationsWithValue(valueToRemove string) (err error) { - if cml.cm == nil { + if cml.cm == nil || cml.cm.Annotations == nil { return errors.New("endpoint not initialized, call Init first") } // speculatively change the state, then replace with whatever comes back