mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 12:07:47 +00:00
Merge pull request #114095 from aimuz/fix-114083
scheduler: Fix field apiVersion is missing from events reported from taint manager
This commit is contained in:
commit
6cbc5dfac6
@ -514,9 +514,10 @@ func (tc *NoExecuteTaintManager) emitPodDeletionEvent(nsName types.NamespacedNam
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
ref := &v1.ObjectReference{
|
ref := &v1.ObjectReference{
|
||||||
Kind: "Pod",
|
APIVersion: "v1",
|
||||||
Name: nsName.Name,
|
Kind: "Pod",
|
||||||
Namespace: nsName.Namespace,
|
Name: nsName.Name,
|
||||||
|
Namespace: nsName.Namespace,
|
||||||
}
|
}
|
||||||
tc.recorder.Eventf(ref, v1.EventTypeNormal, "TaintManagerEviction", "Marking for deletion Pod %s", nsName.String())
|
tc.recorder.Eventf(ref, v1.EventTypeNormal, "TaintManagerEviction", "Marking for deletion Pod %s", nsName.String())
|
||||||
}
|
}
|
||||||
@ -526,9 +527,10 @@ func (tc *NoExecuteTaintManager) emitCancelPodDeletionEvent(nsName types.Namespa
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
ref := &v1.ObjectReference{
|
ref := &v1.ObjectReference{
|
||||||
Kind: "Pod",
|
APIVersion: "v1",
|
||||||
Name: nsName.Name,
|
Kind: "Pod",
|
||||||
Namespace: nsName.Namespace,
|
Name: nsName.Name,
|
||||||
|
Namespace: nsName.Namespace,
|
||||||
}
|
}
|
||||||
tc.recorder.Eventf(ref, v1.EventTypeNormal, "TaintManagerEviction", "Cancelling deletion of Pod %s", nsName.String())
|
tc.recorder.Eventf(ref, v1.EventTypeNormal, "TaintManagerEviction", "Cancelling deletion of Pod %s", nsName.String())
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,10 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/fields"
|
"k8s.io/apimachinery/pkg/fields"
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
@ -36,8 +39,6 @@ import (
|
|||||||
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
||||||
"k8s.io/kubernetes/pkg/controller/testutil"
|
"k8s.io/kubernetes/pkg/controller/testutil"
|
||||||
"k8s.io/kubernetes/pkg/features"
|
"k8s.io/kubernetes/pkg/features"
|
||||||
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var timeForControllerToProgressForSanityCheck = 20 * time.Millisecond
|
var timeForControllerToProgressForSanityCheck = 20 * time.Millisecond
|
||||||
@ -885,3 +886,77 @@ func verifyPodActions(t *testing.T, description string, fakeClientset *fake.Clie
|
|||||||
t.Errorf("[%v]Unexpected test result. Expected delete %v, got %v", description, expectDelete, podDeleted)
|
t.Errorf("[%v]Unexpected test result. Expected delete %v, got %v", description, expectDelete, podDeleted)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestPodDeletionEvent Verify that the output events are as expected
|
||||||
|
func TestPodDeletionEvent(t *testing.T) {
|
||||||
|
f := func(path cmp.Path) bool {
|
||||||
|
switch path.String() {
|
||||||
|
// These fields change at runtime, so ignore it
|
||||||
|
case "LastTimestamp", "FirstTimestamp", "ObjectMeta.Name":
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("emitPodDeletionEvent", func(t *testing.T) {
|
||||||
|
controller := &NoExecuteTaintManager{}
|
||||||
|
recorder := testutil.NewFakeRecorder()
|
||||||
|
controller.recorder = recorder
|
||||||
|
controller.emitPodDeletionEvent(types.NamespacedName{
|
||||||
|
Name: "test",
|
||||||
|
Namespace: "test",
|
||||||
|
})
|
||||||
|
want := []*v1.Event{
|
||||||
|
{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Namespace: "test",
|
||||||
|
},
|
||||||
|
InvolvedObject: v1.ObjectReference{
|
||||||
|
Kind: "Pod",
|
||||||
|
APIVersion: "v1",
|
||||||
|
Namespace: "test",
|
||||||
|
Name: "test",
|
||||||
|
},
|
||||||
|
Reason: "TaintManagerEviction",
|
||||||
|
Type: "Normal",
|
||||||
|
Count: 1,
|
||||||
|
Message: "Marking for deletion Pod test/test",
|
||||||
|
Source: v1.EventSource{Component: "nodeControllerTest"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if diff := cmp.Diff(want, recorder.Events, cmp.FilterPath(f, cmp.Ignore())); len(diff) > 0 {
|
||||||
|
t.Errorf("emitPodDeletionEvent() returned data (-want,+got):\n%s", diff)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("emitCancelPodDeletionEvent", func(t *testing.T) {
|
||||||
|
controller := &NoExecuteTaintManager{}
|
||||||
|
recorder := testutil.NewFakeRecorder()
|
||||||
|
controller.recorder = recorder
|
||||||
|
controller.emitCancelPodDeletionEvent(types.NamespacedName{
|
||||||
|
Name: "test",
|
||||||
|
Namespace: "test",
|
||||||
|
})
|
||||||
|
want := []*v1.Event{
|
||||||
|
{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Namespace: "test",
|
||||||
|
},
|
||||||
|
InvolvedObject: v1.ObjectReference{
|
||||||
|
Kind: "Pod",
|
||||||
|
APIVersion: "v1",
|
||||||
|
Namespace: "test",
|
||||||
|
Name: "test",
|
||||||
|
},
|
||||||
|
Reason: "TaintManagerEviction",
|
||||||
|
Type: "Normal",
|
||||||
|
Count: 1,
|
||||||
|
Message: "Cancelling deletion of Pod test/test",
|
||||||
|
Source: v1.EventSource{Component: "nodeControllerTest"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if diff := cmp.Diff(want, recorder.Events, cmp.FilterPath(f, cmp.Ignore())); len(diff) > 0 {
|
||||||
|
t.Errorf("emitPodDeletionEvent() returned data (-want,+got):\n%s", diff)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user