From 9d65e09494401fa1a341217ba3c69ec0de306a68 Mon Sep 17 00:00:00 2001 From: f41gh7 Date: Thu, 21 Sep 2023 11:59:58 +0200 Subject: [PATCH] api: suppress json parse error for lastApplied spec parsing https://github.com/VictoriaMetrics/operator/issues/753 --- api/v1beta1/vmcluster_types.go | 3 +++ api/victoriametrics/v1beta1/vmcluster_types.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/api/v1beta1/vmcluster_types.go b/api/v1beta1/vmcluster_types.go index 3275d70d..633d7372 100644 --- a/api/v1beta1/vmcluster_types.go +++ b/api/v1beta1/vmcluster_types.go @@ -947,6 +947,9 @@ func (cr *VMCluster) LastAppliedSpecAsPatch() (client.Patch, error) { func (cr *VMCluster) HasSpecChanges() (bool, error) { var prevClusterSpec VMClusterSpec lastAppliedClusterJSON := cr.Annotations["operator.victoriametrics/last-applied-spec"] + if len(lastAppliedClusterJSON) == 0 { + return true, nil + } if err := json.Unmarshal([]byte(lastAppliedClusterJSON), &prevClusterSpec); err != nil { return true, fmt.Errorf("cannot parse last applied cluster spec value: %s : %w", lastAppliedClusterJSON, err) } diff --git a/api/victoriametrics/v1beta1/vmcluster_types.go b/api/victoriametrics/v1beta1/vmcluster_types.go index 3275d70d..633d7372 100644 --- a/api/victoriametrics/v1beta1/vmcluster_types.go +++ b/api/victoriametrics/v1beta1/vmcluster_types.go @@ -947,6 +947,9 @@ func (cr *VMCluster) LastAppliedSpecAsPatch() (client.Patch, error) { func (cr *VMCluster) HasSpecChanges() (bool, error) { var prevClusterSpec VMClusterSpec lastAppliedClusterJSON := cr.Annotations["operator.victoriametrics/last-applied-spec"] + if len(lastAppliedClusterJSON) == 0 { + return true, nil + } if err := json.Unmarshal([]byte(lastAppliedClusterJSON), &prevClusterSpec); err != nil { return true, fmt.Errorf("cannot parse last applied cluster spec value: %s : %w", lastAppliedClusterJSON, err) }