From f3c16c729a1a29550749a153052e7ac94c8731cd Mon Sep 17 00:00:00 2001 From: payall4u Date: Wed, 29 Nov 2023 15:05:55 +0800 Subject: [PATCH] fix some bug --- pkg/webhooks/pod/mutating.go | 7 +++---- pkg/webhooks/pod/mutating_test.go | 6 ++++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/webhooks/pod/mutating.go b/pkg/webhooks/pod/mutating.go index 53c9de9e8..c1dbd6ec6 100644 --- a/pkg/webhooks/pod/mutating.go +++ b/pkg/webhooks/pod/mutating.go @@ -50,10 +50,9 @@ func (m *MutatingAdmission) Default(ctx context.Context, obj runtime.Object) err return err } - if ls.Matches(labels.Set(pod.Labels)) { - if m.Config.QOSInitializer.InitContainerTemplate != nil { - pod.Spec.InitContainers = append(pod.Spec.InitContainers, *m.Config.QOSInitializer.InitContainerTemplate) - } + if !ls.Matches(labels.Set(pod.Labels)) { + klog.Infof("injection skipped: webhook is not interested in the pod") + return nil } qosSlice, err := m.listPodQOS() diff --git a/pkg/webhooks/pod/mutating_test.go b/pkg/webhooks/pod/mutating_test.go index 3c7ea9a0e..cec3e68b3 100644 --- a/pkg/webhooks/pod/mutating_test.go +++ b/pkg/webhooks/pod/mutating_test.go @@ -33,8 +33,10 @@ func TestDefaultingPodQOSInitializer(t *testing.T) { } for _, tc := range []Case{ - {Pod: MockPod("offline", "offline", "enable"), Inject: true}, - {Pod: MockPod("online", "offline", "disable"), Inject: false}, + {Pod: MockPod("offline", "offline", "enable", "app", "nginx"), Inject: true}, + {Pod: MockPod("offline-not-interested", "offline", "enable"), Inject: false}, + {Pod: MockPod("online", "offline", "disable", "app", "nginx"), Inject: false}, + {Pod: MockPod("online-not-interested", "offline", "disable"), Inject: false}, {Pod: MockPod("default"), Inject: false}, } { assert.NoError(t, m.Default(context.Background(), tc.Pod))