Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
e8fd8d50
Commit
e8fd8d50
authored
Oct 19, 2016
by
ymqytw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
address comments
parent
55c6116d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
14 deletions
+39
-14
drain_test.go
pkg/kubectl/cmd/drain_test.go
+39
-14
No files found.
pkg/kubectl/cmd/drain_test.go
View file @
e8fd8d50
...
@@ -22,7 +22,6 @@ import (
...
@@ -22,7 +22,6 @@ import (
"fmt"
"fmt"
"io"
"io"
"io/ioutil"
"io/ioutil"
"math/rand"
"net/http"
"net/http"
"net/url"
"net/url"
"os"
"os"
...
@@ -44,6 +43,7 @@ import (
...
@@ -44,6 +43,7 @@ import (
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util/wait"
)
)
var
node
*
api
.
Node
var
node
*
api
.
Node
...
@@ -556,12 +556,14 @@ func TestDrain(t *testing.T) {
...
@@ -556,12 +556,14 @@ func TestDrain(t *testing.T) {
}
}
func
TestDeletePods
(
t
*
testing
.
T
)
{
func
TestDeletePods
(
t
*
testing
.
T
)
{
ifHasBeenCalled
:=
map
[
string
]
bool
{}
tests
:=
[]
struct
{
tests
:=
[]
struct
{
description
string
description
string
interval
time
.
Duration
interval
time
.
Duration
timeout
time
.
Duration
timeout
time
.
Duration
expectPendingPods
bool
expectPendingPods
bool
expectError
bool
expectError
bool
expectedError
*
error
getPodFn
func
(
namespace
,
name
string
)
(
*
api
.
Pod
,
error
)
getPodFn
func
(
namespace
,
name
string
)
(
*
api
.
Pod
,
error
)
}{
}{
{
{
...
@@ -570,24 +572,24 @@ func TestDeletePods(t *testing.T) {
...
@@ -570,24 +572,24 @@ func TestDeletePods(t *testing.T) {
timeout
:
10
*
time
.
Second
,
timeout
:
10
*
time
.
Second
,
expectPendingPods
:
false
,
expectPendingPods
:
false
,
expectError
:
false
,
expectError
:
false
,
expectedError
:
nil
,
getPodFn
:
func
(
namespace
,
name
string
)
(
*
api
.
Pod
,
error
)
{
getPodFn
:
func
(
namespace
,
name
string
)
(
*
api
.
Pod
,
error
)
{
oldPodMap
,
_
:=
createPods
(
false
)
oldPodMap
,
_
:=
createPods
(
false
)
newPodMap
,
_
:=
createPods
(
true
)
newPodMap
,
_
:=
createPods
(
true
)
if
newPod
,
found
:=
newPodMap
[
name
];
found
{
if
oldPod
,
found
:=
oldPodMap
[
name
];
found
{
// randomly return old pod
if
_
,
ok
:=
ifHasBeenCalled
[
name
];
!
ok
{
if
rand
.
Float32
()
<
0.6
{
ifHasBeenCalled
[
name
]
=
true
oldPod
:=
oldPodMap
[
name
]
return
&
oldPod
,
nil
return
&
oldPod
,
nil
}
else
{
}
else
{
// randomly return a new pod or a NotFound error
if
oldPod
.
ObjectMeta
.
Generation
<
4
{
if
rand
.
Float32
()
<
0.5
{
newPod
:=
newPodMap
[
name
]
return
&
newPod
,
nil
return
&
newPod
,
nil
}
else
{
}
else
{
return
&
api
.
Pod
{}
,
apierrors
.
NewNotFound
(
unversioned
.
GroupResource
{
Resource
:
"pods"
},
name
)
return
nil
,
apierrors
.
NewNotFound
(
unversioned
.
GroupResource
{
Resource
:
"pods"
},
name
)
}
}
}
}
}
}
return
&
api
.
Pod
{}
,
apierrors
.
NewNotFound
(
unversioned
.
GroupResource
{
Resource
:
"pods"
},
name
)
return
nil
,
apierrors
.
NewNotFound
(
unversioned
.
GroupResource
{
Resource
:
"pods"
},
name
)
},
},
},
},
{
{
...
@@ -596,12 +598,24 @@ func TestDeletePods(t *testing.T) {
...
@@ -596,12 +598,24 @@ func TestDeletePods(t *testing.T) {
timeout
:
3
*
time
.
Second
,
timeout
:
3
*
time
.
Second
,
expectPendingPods
:
true
,
expectPendingPods
:
true
,
expectError
:
true
,
expectError
:
true
,
expectedError
:
&
wait
.
ErrWaitTimeout
,
getPodFn
:
func
(
namespace
,
name
string
)
(
*
api
.
Pod
,
error
)
{
getPodFn
:
func
(
namespace
,
name
string
)
(
*
api
.
Pod
,
error
)
{
oldPodMap
,
_
:=
createPods
(
false
)
oldPodMap
,
_
:=
createPods
(
false
)
if
oldPod
,
found
:=
oldPodMap
[
name
];
found
{
if
oldPod
,
found
:=
oldPodMap
[
name
];
found
{
return
&
oldPod
,
nil
return
&
oldPod
,
nil
}
}
return
&
api
.
Pod
{},
errors
.
New
(
fmt
.
Sprintf
(
"%q: not found"
,
name
))
return
nil
,
errors
.
New
(
fmt
.
Sprintf
(
"%q: not found"
,
name
))
},
},
{
description
:
"Client error could be passed out"
,
interval
:
200
*
time
.
Millisecond
,
timeout
:
5
*
time
.
Second
,
expectPendingPods
:
true
,
expectError
:
true
,
expectedError
:
nil
,
getPodFn
:
func
(
namespace
,
name
string
)
(
*
api
.
Pod
,
error
)
{
return
nil
,
errors
.
New
(
"This is a random error for testing"
)
},
},
},
},
}
}
...
@@ -612,15 +626,25 @@ func TestDeletePods(t *testing.T) {
...
@@ -612,15 +626,25 @@ func TestDeletePods(t *testing.T) {
_
,
pods
:=
createPods
(
false
)
_
,
pods
:=
createPods
(
false
)
pendingPods
,
err
:=
o
.
waitForDelete
(
pods
,
test
.
interval
,
test
.
timeout
,
test
.
getPodFn
)
pendingPods
,
err
:=
o
.
waitForDelete
(
pods
,
test
.
interval
,
test
.
timeout
,
test
.
getPodFn
)
if
test
.
expectError
&&
err
==
nil
&&
test
.
expectPendingPods
&&
len
(
pendingPods
)
>
0
{
if
test
.
expectError
{
if
err
==
nil
{
t
.
Fatalf
(
"%s: unexpected non-error"
,
test
.
description
)
t
.
Fatalf
(
"%s: unexpected non-error"
,
test
.
description
)
}
else
if
test
.
expectedError
!=
nil
{
if
*
test
.
expectedError
!=
err
{
t
.
Fatalf
(
"%s: the error does not match expected error"
,
test
.
description
)
}
}
}
if
!
test
.
expectError
&&
err
!=
nil
&&
!
test
.
expectPendingPods
&&
len
(
pendingPods
)
==
0
{
}
if
!
test
.
expectError
&&
err
!=
nil
{
t
.
Fatalf
(
"%s: unexpected error"
,
test
.
description
)
t
.
Fatalf
(
"%s: unexpected error"
,
test
.
description
)
}
}
if
test
.
expectPendingPods
&&
len
(
pendingPods
)
==
0
{
t
.
Fatalf
(
"%s: unexpected empty pods"
,
test
.
description
)
}
if
!
test
.
expectPendingPods
&&
len
(
pendingPods
)
>
0
{
t
.
Fatalf
(
"%s: unexpected pending pods"
,
test
.
description
)
}
}
}
}
}
func
createPods
(
ifCreateNewPods
bool
)
(
map
[
string
]
api
.
Pod
,
[]
api
.
Pod
)
{
func
createPods
(
ifCreateNewPods
bool
)
(
map
[
string
]
api
.
Pod
,
[]
api
.
Pod
)
{
...
@@ -638,6 +662,7 @@ func createPods(ifCreateNewPods bool) (map[string]api.Pod, []api.Pod) {
...
@@ -638,6 +662,7 @@ func createPods(ifCreateNewPods bool) (map[string]api.Pod, []api.Pod) {
Name
:
"pod"
+
string
(
i
),
Name
:
"pod"
+
string
(
i
),
Namespace
:
"default"
,
Namespace
:
"default"
,
UID
:
uid
,
UID
:
uid
,
Generation
:
int64
(
i
),
},
},
}
}
podMap
[
pod
.
Name
]
=
pod
podMap
[
pod
.
Name
]
=
pod
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment