From 4dda2f20cf31981066141ccd9fea88293febba90 Mon Sep 17 00:00:00 2001 From: Liu Zhenwei Date: Fri, 25 Mar 2022 19:54:04 +0800 Subject: [PATCH] remove comment and handle the error of Unmarshal Signed-off-by: Liu Zhenwei --- apis/apps/pub/inplace_update.go | 2 +- pkg/util/inplaceupdate/inplace_update.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apis/apps/pub/inplace_update.go b/apis/apps/pub/inplace_update.go index 768ae4bcf5..e08efd4675 100644 --- a/apis/apps/pub/inplace_update.go +++ b/apis/apps/pub/inplace_update.go @@ -114,7 +114,7 @@ type InPlaceUpdateContainerRestartCount struct { // RestartCount is the container restart count RestartCount int `json:"restartCount,omitempty"` // Timestamp is the time for this update - Timestamp metav1.Time `json:"timestamp"` + Timestamp metav1.Time `json:"timestamp,omitempty"` } func GetInPlaceUpdateState(obj metav1.Object) (string, bool) { diff --git a/pkg/util/inplaceupdate/inplace_update.go b/pkg/util/inplaceupdate/inplace_update.go index 12c43a57d5..f3e7fd0c84 100644 --- a/pkg/util/inplaceupdate/inplace_update.go +++ b/pkg/util/inplaceupdate/inplace_update.go @@ -90,7 +90,6 @@ type UpdateSpec struct { OldTemplate *v1.PodTemplateSpec `json:"oldTemplate,omitempty"` NewTemplate *v1.PodTemplateSpec `json:"newTemplate,omitempty"` } - type realControl struct { podAdapter podadapter.Adapter revisionAdapter revisionadapter.Interface @@ -429,14 +428,15 @@ func recordPodAndContainersRestartCount(pod *v1.Pod, spec *UpdateSpec, revision } var currentPodRestartCount int64 containersRestartCount := make(map[string]appspub.InPlaceUpdateContainerRestartCount) - //revision := pod.GetLabels()["controller-revision-hash"] if v, ok := pod.Annotations[appspub.InPlaceUpdatePodRestartKey]; ok { currentPodRestartCount, _ = strconv.ParseInt(v, 10, 64) } if v, ok := pod.Annotations[appspub.InPlaceUpdateContainersRestartKey]; ok { - _ = json.Unmarshal([]byte(v), &containersRestartCount) + if err := json.Unmarshal([]byte(v), &containersRestartCount); err != nil { + return + } } calculateRestartCountFunc := func(cname string) { containerRestartCount, ok := containersRestartCount[cname]