From 47a565d00d0bde2f49b1a615defd1089a2bae9c2 Mon Sep 17 00:00:00 2001 From: Tianxin Dong Date: Mon, 22 Nov 2021 10:58:23 +0800 Subject: [PATCH] Fix: controllerrevision can not be updated (#2764) --- pkg/workflow/recorder/recorder.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/workflow/recorder/recorder.go b/pkg/workflow/recorder/recorder.go index 0cc0f1c37..a2ea343cf 100644 --- a/pkg/workflow/recorder/recorder.go +++ b/pkg/workflow/recorder/recorder.go @@ -66,7 +66,9 @@ func (r *recorder) Save(version string, data []byte) Store { if version == "" { wfStatus := r.source.Status.Workflow if wfStatus != nil { - version = strings.ReplaceAll(wfStatus.AppRevision, ":", "-") + if !strings.Contains(wfStatus.AppRevision, ":") { + version = wfStatus.AppRevision + } } } @@ -89,7 +91,16 @@ func (r *recorder) Save(version string, data []byte) Store { } if err := r.cli.Create(context.Background(), rv); err != nil { if kerrors.IsAlreadyExists(err) { - r.err = r.cli.Update(context.Background(), rv) + // ControllerRevision implements an immutable snapshot of state data + // Once a ControllerRevision has been successfully created, it can not be updated. + // So we need to delete the old one and create a new one. + r.err = r.cli.Delete(context.Background(), &apps.ControllerRevision{ + ObjectMeta: metav1.ObjectMeta{ + Name: rv.Name, + Namespace: rv.Namespace, + }, + }) + r.err = r.cli.Create(context.Background(), rv) } else { r.err = errors.WithMessagef(err, "save record %s/%s", rv.Namespace, rv.Name) }