mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 10:43:56 +00:00
Add integration tests for all bind plugins skipped in TestBindPlugin
Signed-off-by: kerthcet <kerthcet@gmail.com>
This commit is contained in:
parent
2a5fd3076a
commit
c29234d3e1
@ -475,7 +475,7 @@ func (bp *BindPlugin) Bind(ctx context.Context, state *framework.CycleState, p *
|
|||||||
bp.pluginInvokeEventChan <- pluginInvokeEvent{pluginName: bp.Name(), val: bp.numBindCalled}
|
bp.pluginInvokeEventChan <- pluginInvokeEvent{pluginName: bp.Name(), val: bp.numBindCalled}
|
||||||
}
|
}
|
||||||
if bp.bindStatus.IsSuccess() {
|
if bp.bindStatus.IsSuccess() {
|
||||||
if err := bp.client.CoreV1().Pods(p.Namespace).Bind(context.TODO(), &v1.Binding{
|
if err := bp.client.CoreV1().Pods(p.Namespace).Bind(ctx, &v1.Binding{
|
||||||
ObjectMeta: metav1.ObjectMeta{Namespace: p.Namespace, Name: p.Name, UID: p.UID, Annotations: map[string]string{bindPluginAnnotation: bp.Name()}},
|
ObjectMeta: metav1.ObjectMeta{Namespace: p.Namespace, Name: p.Name, UID: p.UID, Annotations: map[string]string{bindPluginAnnotation: bp.Name()}},
|
||||||
Target: v1.ObjectReference{
|
Target: v1.ObjectReference{
|
||||||
Kind: "Node",
|
Kind: "Node",
|
||||||
@ -1559,20 +1559,24 @@ func TestBindPlugin(t *testing.T) {
|
|||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
enabledBindPlugins []configv1.Plugin
|
||||||
bindPluginStatuses []*framework.Status
|
bindPluginStatuses []*framework.Status
|
||||||
expectBoundByScheduler bool // true means this test case expecting scheduler would bind pods
|
expectBoundByScheduler bool // true means this test case expecting scheduler would bind pods
|
||||||
expectBoundByPlugin bool // true means this test case expecting a plugin would bind pods
|
expectBoundByPlugin bool // true means this test case expecting a plugin would bind pods
|
||||||
|
expectBindFailed bool // true means this test case expecting a plugin binding pods with error
|
||||||
expectBindPluginName string // expecting plugin name to bind pods
|
expectBindPluginName string // expecting plugin name to bind pods
|
||||||
expectInvokeEvents []pluginInvokeEvent
|
expectInvokeEvents []pluginInvokeEvent
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "bind plugins skipped to bind the pod and scheduler bond the pod",
|
name: "bind plugins skipped to bind the pod and scheduler bond the pod",
|
||||||
|
enabledBindPlugins: []configv1.Plugin{{Name: bindPlugin1Name}, {Name: bindPlugin2Name}, {Name: defaultbinder.Name}},
|
||||||
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Skip, ""), framework.NewStatus(framework.Skip, "")},
|
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Skip, ""), framework.NewStatus(framework.Skip, "")},
|
||||||
expectBoundByScheduler: true,
|
expectBoundByScheduler: true,
|
||||||
expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1Name, val: 1}, {pluginName: bindPlugin2Name, val: 1}, {pluginName: postBindPluginName, val: 1}},
|
expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1Name, val: 1}, {pluginName: bindPlugin2Name, val: 1}, {pluginName: postBindPluginName, val: 1}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bindplugin2 succeeded to bind the pod",
|
name: "bindplugin2 succeeded to bind the pod",
|
||||||
|
enabledBindPlugins: []configv1.Plugin{{Name: bindPlugin1Name}, {Name: bindPlugin2Name}, {Name: defaultbinder.Name}},
|
||||||
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Skip, ""), framework.NewStatus(framework.Success, "")},
|
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Skip, ""), framework.NewStatus(framework.Success, "")},
|
||||||
expectBoundByPlugin: true,
|
expectBoundByPlugin: true,
|
||||||
expectBindPluginName: bindPlugin2Name,
|
expectBindPluginName: bindPlugin2Name,
|
||||||
@ -1580,6 +1584,7 @@ func TestBindPlugin(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bindplugin1 succeeded to bind the pod",
|
name: "bindplugin1 succeeded to bind the pod",
|
||||||
|
enabledBindPlugins: []configv1.Plugin{{Name: bindPlugin1Name}, {Name: bindPlugin2Name}, {Name: defaultbinder.Name}},
|
||||||
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Success, ""), framework.NewStatus(framework.Success, "")},
|
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Success, ""), framework.NewStatus(framework.Success, "")},
|
||||||
expectBoundByPlugin: true,
|
expectBoundByPlugin: true,
|
||||||
expectBindPluginName: bindPlugin1Name,
|
expectBindPluginName: bindPlugin1Name,
|
||||||
@ -1587,9 +1592,17 @@ func TestBindPlugin(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bind plugin fails to bind the pod",
|
name: "bind plugin fails to bind the pod",
|
||||||
|
enabledBindPlugins: []configv1.Plugin{{Name: bindPlugin1Name}, {Name: bindPlugin2Name}, {Name: defaultbinder.Name}},
|
||||||
|
expectBindFailed: true,
|
||||||
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Error, "failed to bind"), framework.NewStatus(framework.Success, "")},
|
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Error, "failed to bind"), framework.NewStatus(framework.Success, "")},
|
||||||
expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1Name, val: 1}, {pluginName: reservePluginName, val: 1}},
|
expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1Name, val: 1}, {pluginName: reservePluginName, val: 1}},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "all bind plugins will be skipped(this should not happen for most of the cases)",
|
||||||
|
enabledBindPlugins: []configv1.Plugin{{Name: bindPlugin1Name}, {Name: bindPlugin2Name}},
|
||||||
|
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Skip, ""), framework.NewStatus(framework.Skip, "")},
|
||||||
|
expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1Name, val: 1}, {pluginName: bindPlugin2Name, val: 1}},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var pluginInvokeEventChan chan pluginInvokeEvent
|
var pluginInvokeEventChan chan pluginInvokeEvent
|
||||||
@ -1624,7 +1637,7 @@ func TestBindPlugin(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Bind: configv1.PluginSet{
|
Bind: configv1.PluginSet{
|
||||||
// Put DefaultBinder last.
|
// Put DefaultBinder last.
|
||||||
Enabled: []configv1.Plugin{{Name: bindPlugin1.Name()}, {Name: bindPlugin2.Name()}, {Name: defaultbinder.Name}},
|
Enabled: test.enabledBindPlugins,
|
||||||
Disabled: []configv1.Plugin{{Name: defaultbinder.Name}},
|
Disabled: []configv1.Plugin{{Name: defaultbinder.Name}},
|
||||||
},
|
},
|
||||||
PostBind: configv1.PluginSet{
|
PostBind: configv1.PluginSet{
|
||||||
@ -1696,7 +1709,7 @@ func TestBindPlugin(t *testing.T) {
|
|||||||
if reservePlugin.numUnreserveCalled != 0 {
|
if reservePlugin.numUnreserveCalled != 0 {
|
||||||
t.Errorf("Expected unreserve to not be called, was called %d times.", reservePlugin.numUnreserveCalled)
|
t.Errorf("Expected unreserve to not be called, was called %d times.", reservePlugin.numUnreserveCalled)
|
||||||
}
|
}
|
||||||
} else {
|
} else if test.expectBindFailed {
|
||||||
// bind plugin fails to bind the pod
|
// bind plugin fails to bind the pod
|
||||||
if err = wait.PollUntilContextTimeout(testCtx.Ctx, 10*time.Millisecond, 30*time.Second, false,
|
if err = wait.PollUntilContextTimeout(testCtx.Ctx, 10*time.Millisecond, 30*time.Second, false,
|
||||||
testutils.PodSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
|
testutils.PodSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
|
||||||
@ -1706,7 +1719,11 @@ func TestBindPlugin(t *testing.T) {
|
|||||||
if p.numPostBindCalled > 0 {
|
if p.numPostBindCalled > 0 {
|
||||||
t.Errorf("Didn't expect the postbind plugin to be called %d times.", p.numPostBindCalled)
|
t.Errorf("Didn't expect the postbind plugin to be called %d times.", p.numPostBindCalled)
|
||||||
}
|
}
|
||||||
|
} else if postBindPlugin.numPostBindCalled > 0 {
|
||||||
|
// all bind plugins are skipped
|
||||||
|
t.Errorf("Didn't expect the postbind plugin to be called %d times.", postBindPlugin.numPostBindCalled)
|
||||||
}
|
}
|
||||||
|
|
||||||
for j := range test.expectInvokeEvents {
|
for j := range test.expectInvokeEvents {
|
||||||
expectEvent := test.expectInvokeEvents[j]
|
expectEvent := test.expectInvokeEvents[j]
|
||||||
select {
|
select {
|
||||||
|
Loading…
Reference in New Issue
Block a user