From bd24dd7dae237e71519196fb591a983ff5a299f9 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 26 Mar 2019 17:19:22 +0000 Subject: [PATCH] Make test harness and comments match Kubernetes behaviour on conflict error Kubernetes always returns nil on error; somehow I had the wrong idea here. --- prog/kube-utils/annotations.go | 6 +++--- testing/kubernetes/testing/fixture.go | 4 ---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/prog/kube-utils/annotations.go b/prog/kube-utils/annotations.go index 1b079365..195273a2 100644 --- a/prog/kube-utils/annotations.go +++ b/prog/kube-utils/annotations.go @@ -100,7 +100,7 @@ func (cml *configMapAnnotations) UpdateAnnotation(key, value string) (err error) return errors.New("endpoint not initialized, call Init first") } // speculatively change the state, then replace with whatever comes back - // from Update(), which will be the latest on the server whatever happened + // from Update(), which will be the latest on the server, or nil if error cml.cm.Annotations[cleanKey(key)] = value cml.cm, err = cml.Client.ConfigMaps(cml.Namespace).Update(cml.cm) return err @@ -111,7 +111,7 @@ func (cml *configMapAnnotations) RemoveAnnotation(key string) (err error) { return errors.New("endpoint not initialized, call Init first") } // speculatively change the state, then replace with whatever comes back - // from Update(), which will be the latest on the server whatever happened + // from Update(), which will be the latest on the server, or nil if error delete(cml.cm.Annotations, cleanKey(key)) cml.cm, err = cml.Client.ConfigMaps(cml.Namespace).Update(cml.cm) return err @@ -122,7 +122,7 @@ func (cml *configMapAnnotations) RemoveAnnotationsWithValue(valueToRemove string return errors.New("endpoint not initialized, call Init first") } // speculatively change the state, then replace with whatever comes back - // from Update(), which will be the latest on the server whatever happened + // from Update(), which will be the latest on the server, or nil if error for key, value := range cml.cm.Annotations { if value == valueToRemove { delete(cml.cm.Annotations, key) // don't need to clean this key as it came from the map diff --git a/testing/kubernetes/testing/fixture.go b/testing/kubernetes/testing/fixture.go index 60965d79..3df53523 100644 --- a/testing/kubernetes/testing/fixture.go +++ b/testing/kubernetes/testing/fixture.go @@ -110,10 +110,6 @@ func ObjectReaction(tracker ObjectTracker) testing.ReactionFunc { } err = tracker.Update(gvr, action.GetObject(), ns) if err != nil { - if errors.IsConflict(err) { // return the currently-stored version of the object - obj, _ := tracker.Get(gvr, ns, objMeta.GetName()) - return true, obj, err - } return true, nil, err } obj, err := tracker.Get(gvr, ns, objMeta.GetName())