From 4b8ebdf41d138a3ae06f77ae4fa7f507bda00f20 Mon Sep 17 00:00:00 2001 From: shaofan-hs Date: Mon, 28 Aug 2023 14:43:13 +0800 Subject: [PATCH] fix, mutating when pod status chaged --- config/webhook/webhook.yaml | 1 + pkg/webhook/server/generic/generic_webhooks.go | 5 ++++- pkg/webhook/server/generic/pod/opslifecycle/webhook.go | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/config/webhook/webhook.yaml b/config/webhook/webhook.yaml index 72d9131a..24d5a2a5 100644 --- a/config/webhook/webhook.yaml +++ b/config/webhook/webhook.yaml @@ -23,6 +23,7 @@ webhooks: - DELETE resources: - pods + - pods/status scope: '*' objectSelector: matchExpressions: diff --git a/pkg/webhook/server/generic/generic_webhooks.go b/pkg/webhook/server/generic/generic_webhooks.go index fc105893..f1763a2f 100644 --- a/pkg/webhook/server/generic/generic_webhooks.go +++ b/pkg/webhook/server/generic/generic_webhooks.go @@ -36,7 +36,10 @@ var MutatingTypeHandlerMap = map[string]webhookdmission.DispatchHandler{} var ValidatingTypeHandlerMap = map[string]webhookdmission.DispatchHandler{} func init() { - MutatingTypeHandlerMap["Pod"] = pod.NewMutatingHandler() + podMutatingHandler := pod.NewMutatingHandler() + MutatingTypeHandlerMap["Pod"] = podMutatingHandler + MutatingTypeHandlerMap["Pod/status"] = podMutatingHandler + ValidatingTypeHandlerMap["Pod"] = pod.NewValidatingHandler() MutatingTypeHandlerMap["RuleSet"] = ruleset.NewMutatingHandler() diff --git a/pkg/webhook/server/generic/pod/opslifecycle/webhook.go b/pkg/webhook/server/generic/pod/opslifecycle/webhook.go index d7f5667c..675c810c 100644 --- a/pkg/webhook/server/generic/pod/opslifecycle/webhook.go +++ b/pkg/webhook/server/generic/pod/opslifecycle/webhook.go @@ -64,7 +64,7 @@ func New() *OpsLifecycle { readyToUpgrade: hasNoBlockingFinalizer, isPodReady: controllerutils.IsPodReady, timeLabelValue: func() string { - return strconv.FormatInt(time.Now().Unix(), 10) + return strconv.FormatInt(time.Now().UnixNano(), 10) }, } }