Skip to content

Commit

Permalink
fix some bug
Browse files Browse the repository at this point in the history
  • Loading branch information
payall4u committed Nov 29, 2023
1 parent 85ed9fb commit f3c16c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 3 additions & 4 deletions pkg/webhooks/pod/mutating.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions pkg/webhooks/pod/mutating_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit f3c16c7

Please sign in to comment.