From 405964d75f4db9d70deed8d97b4d7c1f34eab618 Mon Sep 17 00:00:00 2001 From: Fabian Kramm Date: Fri, 13 May 2022 18:20:13 +0200 Subject: [PATCH] fix: fix init manifests panic --- pkg/controllers/manifests/init.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/controllers/manifests/init.go b/pkg/controllers/manifests/init.go index 87838091b..51921b767 100644 --- a/pkg/controllers/manifests/init.go +++ b/pkg/controllers/manifests/init.go @@ -52,11 +52,14 @@ func (r *InitManifestsConfigMapReconciler) Reconcile(ctx context.Context, req ct // make array stable or otherwise order is random sort.Strings(cmData) manifests := strings.Join(cmData, "\n---\n") - lastAppliedManifests := cm.ObjectMeta.Annotations[LastAppliedManifestKey] - if lastAppliedManifests != "" { - lastAppliedManifests, err = compress.Uncompress(lastAppliedManifests) - if err != nil { - r.Log.Errorf("error decompressing manifests: %v", err) + lastAppliedManifests := "" + if cm.ObjectMeta.Annotations != nil { + lastAppliedManifests = cm.ObjectMeta.Annotations[LastAppliedManifestKey] + if lastAppliedManifests != "" { + lastAppliedManifests, err = compress.Uncompress(lastAppliedManifests) + if err != nil { + r.Log.Errorf("error decompressing manifests: %v", err) + } } } @@ -80,6 +83,9 @@ func (r *InitManifestsConfigMapReconciler) Reconcile(ctx context.Context, req ct } // update annotation + if cm.ObjectMeta.Annotations == nil { + cm.ObjectMeta.Annotations = map[string]string{} + } cm.ObjectMeta.Annotations[LastAppliedManifestKey] = compressedManifests err = r.LocalClient.Update(ctx, cm, &client.UpdateOptions{}) if err != nil {