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
b15e2e73
Commit
b15e2e73
authored
Apr 30, 2015
by
CJ Cullen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7544 from jayunit100/kubectl-ns
E2E: Update kubectl.go - remove default NS and use idiomatic namepsace l...
parents
58ede77a
864c668a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
29 deletions
+41
-29
kubectl.go
test/e2e/kubectl.go
+37
-25
util.go
test/e2e/util.go
+4
-4
No files found.
test/e2e/kubectl.go
View file @
b15e2e73
...
@@ -28,6 +28,7 @@ import (
...
@@ -28,6 +28,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
)
)
const
(
const
(
...
@@ -45,11 +46,22 @@ const (
...
@@ -45,11 +46,22 @@ const (
var
_
=
Describe
(
"kubectl"
,
func
()
{
var
_
=
Describe
(
"kubectl"
,
func
()
{
var
c
*
client
.
Client
var
c
*
client
.
Client
var
ns
string
var
testingNs
*
api
.
Namespace
BeforeEach
(
func
()
{
BeforeEach
(
func
()
{
var
err
error
var
err
error
c
,
err
=
loadClient
()
c
,
err
=
loadClient
()
expectNoError
(
err
)
expectNoError
(
err
)
testingNs
,
err
=
createTestingNS
(
"kubectl"
,
c
)
ns
=
testingNs
.
Name
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
})
AfterEach
(
func
()
{
By
(
fmt
.
Sprintf
(
"Destroying namespace for this suite %v"
,
ns
))
if
err
:=
c
.
Namespaces
()
.
Delete
(
ns
);
err
!=
nil
{
Failf
(
"Couldn't delete ns %s"
,
err
)
}
})
})
Describe
(
"update-demo"
,
func
()
{
Describe
(
"update-demo"
,
func
()
{
...
@@ -63,22 +75,22 @@ var _ = Describe("kubectl", func() {
...
@@ -63,22 +75,22 @@ var _ = Describe("kubectl", func() {
defer
cleanup
(
nautilusPath
,
updateDemoSelector
)
defer
cleanup
(
nautilusPath
,
updateDemoSelector
)
By
(
"creating a replication controller"
)
By
(
"creating a replication controller"
)
runKubectl
(
"create"
,
"-f"
,
nautilusPath
)
runKubectl
(
"create"
,
"-f"
,
nautilusPath
,
fmt
.
Sprintf
(
"--namespace=%v"
,
ns
)
)
validateController
(
c
,
nautilusImage
,
2
,
"update-demo"
,
updateDemoSelector
,
getUDData
(
"nautilus.jpg"
)
)
validateController
(
c
,
nautilusImage
,
2
,
"update-demo"
,
updateDemoSelector
,
getUDData
(
"nautilus.jpg"
,
ns
),
ns
)
})
})
It
(
"should scale a replication controller"
,
func
()
{
It
(
"should scale a replication controller"
,
func
()
{
defer
cleanup
(
nautilusPath
,
updateDemoSelector
)
defer
cleanup
(
nautilusPath
,
updateDemoSelector
)
By
(
"creating a replication controller"
)
By
(
"creating a replication controller"
)
runKubectl
(
"create"
,
"-f"
,
nautilusPath
)
runKubectl
(
"create"
,
"-f"
,
nautilusPath
,
fmt
.
Sprintf
(
"--namespace=%v"
,
ns
)
)
validateController
(
c
,
nautilusImage
,
2
,
"update-demo"
,
updateDemoSelector
,
getUDData
(
"nautilus.jpg"
)
)
validateController
(
c
,
nautilusImage
,
2
,
"update-demo"
,
updateDemoSelector
,
getUDData
(
"nautilus.jpg"
,
ns
),
ns
)
By
(
"scaling down the replication controller"
)
By
(
"scaling down the replication controller"
)
runKubectl
(
"resize"
,
"rc"
,
"update-demo-nautilus"
,
"--replicas=1"
)
runKubectl
(
"resize"
,
"rc"
,
"update-demo-nautilus"
,
"--replicas=1"
,
fmt
.
Sprintf
(
"--namespace=%v"
,
ns
)
)
validateController
(
c
,
nautilusImage
,
1
,
"update-demo"
,
updateDemoSelector
,
getUDData
(
"nautilus.jpg"
)
)
validateController
(
c
,
nautilusImage
,
1
,
"update-demo"
,
updateDemoSelector
,
getUDData
(
"nautilus.jpg"
,
ns
),
ns
)
By
(
"scaling up the replication controller"
)
By
(
"scaling up the replication controller"
)
runKubectl
(
"resize"
,
"rc"
,
"update-demo-nautilus"
,
"--replicas=2"
)
runKubectl
(
"resize"
,
"rc"
,
"update-demo-nautilus"
,
"--replicas=2"
,
fmt
.
Sprintf
(
"--namespace=%v"
,
ns
)
)
validateController
(
c
,
nautilusImage
,
2
,
"update-demo"
,
updateDemoSelector
,
getUDData
(
"nautilus.jpg"
)
)
validateController
(
c
,
nautilusImage
,
2
,
"update-demo"
,
updateDemoSelector
,
getUDData
(
"nautilus.jpg"
,
ns
),
ns
)
})
})
It
(
"should do a rolling update of a replication controller"
,
func
()
{
It
(
"should do a rolling update of a replication controller"
,
func
()
{
...
@@ -86,11 +98,11 @@ var _ = Describe("kubectl", func() {
...
@@ -86,11 +98,11 @@ var _ = Describe("kubectl", func() {
defer
cleanup
(
updateDemoRoot
,
updateDemoSelector
)
defer
cleanup
(
updateDemoRoot
,
updateDemoSelector
)
By
(
"creating the initial replication controller"
)
By
(
"creating the initial replication controller"
)
runKubectl
(
"create"
,
"-f"
,
nautilusPath
)
runKubectl
(
"create"
,
"-f"
,
nautilusPath
,
fmt
.
Sprintf
(
"--namespace=%v"
,
ns
)
)
validateController
(
c
,
nautilusImage
,
2
,
"update-demo"
,
updateDemoSelector
,
getUDData
(
"nautilus.jpg"
)
)
validateController
(
c
,
nautilusImage
,
2
,
"update-demo"
,
updateDemoSelector
,
getUDData
(
"nautilus.jpg"
,
ns
),
ns
)
By
(
"rolling-update to new replication controller"
)
By
(
"rolling-update to new replication controller"
)
runKubectl
(
"rolling-update"
,
"update-demo-nautilus"
,
"--update-period=1s"
,
"-f"
,
kittenPath
)
runKubectl
(
"rolling-update"
,
"update-demo-nautilus"
,
"--update-period=1s"
,
"-f"
,
kittenPath
,
fmt
.
Sprintf
(
"--namespace=%v"
,
ns
)
)
validateController
(
c
,
kittenImage
,
2
,
"update-demo"
,
updateDemoSelector
,
getUDData
(
"kitten.jpg"
)
)
validateController
(
c
,
kittenImage
,
2
,
"update-demo"
,
updateDemoSelector
,
getUDData
(
"kitten.jpg"
,
ns
),
ns
)
})
})
})
})
...
@@ -106,36 +118,36 @@ var _ = Describe("kubectl", func() {
...
@@ -106,36 +118,36 @@ var _ = Describe("kubectl", func() {
defer
cleanup
(
guestbookPath
,
frontendSelector
,
redisMasterSelector
,
redisSlaveSelector
)
defer
cleanup
(
guestbookPath
,
frontendSelector
,
redisMasterSelector
,
redisSlaveSelector
)
By
(
"creating all guestbook components"
)
By
(
"creating all guestbook components"
)
runKubectl
(
"create"
,
"-f"
,
guestbookPath
)
runKubectl
(
"create"
,
"-f"
,
guestbookPath
,
fmt
.
Sprintf
(
"--namespace=%v"
,
ns
)
)
By
(
"validating guestbook app"
)
By
(
"validating guestbook app"
)
validateGuestbookApp
(
c
)
validateGuestbookApp
(
c
,
ns
)
})
})
})
})
})
})
func
validateGuestbookApp
(
c
*
client
.
Client
)
{
func
validateGuestbookApp
(
c
*
client
.
Client
,
ns
string
)
{
Logf
(
"Waiting for frontend to serve content."
)
Logf
(
"Waiting for frontend to serve content."
)
if
!
waitForGuestbookResponse
(
c
,
"get"
,
""
,
`{"data": ""}`
,
guestbookStartupTimeout
)
{
if
!
waitForGuestbookResponse
(
c
,
"get"
,
""
,
`{"data": ""}`
,
guestbookStartupTimeout
,
ns
)
{
Failf
(
"Frontend service did not start serving content in %v seconds."
,
guestbookStartupTimeout
.
Seconds
())
Failf
(
"Frontend service did not start serving content in %v seconds."
,
guestbookStartupTimeout
.
Seconds
())
}
}
Logf
(
"Trying to add a new entry to the guestbook."
)
Logf
(
"Trying to add a new entry to the guestbook."
)
if
!
waitForGuestbookResponse
(
c
,
"set"
,
"TestEntry"
,
`{"message": "Updated"}`
,
guestbookResponseTimeout
)
{
if
!
waitForGuestbookResponse
(
c
,
"set"
,
"TestEntry"
,
`{"message": "Updated"}`
,
guestbookResponseTimeout
,
ns
)
{
Failf
(
"Cannot added new entry in %v seconds."
,
guestbookResponseTimeout
.
Seconds
())
Failf
(
"Cannot added new entry in %v seconds."
,
guestbookResponseTimeout
.
Seconds
())
}
}
Logf
(
"Verifying that added entry can be retrieved."
)
Logf
(
"Verifying that added entry can be retrieved."
)
if
!
waitForGuestbookResponse
(
c
,
"get"
,
""
,
`{"data": "TestEntry"}`
,
guestbookResponseTimeout
)
{
if
!
waitForGuestbookResponse
(
c
,
"get"
,
""
,
`{"data": "TestEntry"}`
,
guestbookResponseTimeout
,
ns
)
{
Failf
(
"Entry to guestbook wasn't correctly added in %v seconds."
,
guestbookResponseTimeout
.
Seconds
())
Failf
(
"Entry to guestbook wasn't correctly added in %v seconds."
,
guestbookResponseTimeout
.
Seconds
())
}
}
}
}
// Returns whether received expected response from guestbook on time.
// Returns whether received expected response from guestbook on time.
func
waitForGuestbookResponse
(
c
*
client
.
Client
,
cmd
,
arg
,
expectedResponse
string
,
timeout
time
.
Duration
)
bool
{
func
waitForGuestbookResponse
(
c
*
client
.
Client
,
cmd
,
arg
,
expectedResponse
string
,
timeout
time
.
Duration
,
ns
string
)
bool
{
for
start
:=
time
.
Now
();
time
.
Since
(
start
)
<
timeout
;
time
.
Sleep
(
5
*
time
.
Second
)
{
for
start
:=
time
.
Now
();
time
.
Since
(
start
)
<
timeout
;
time
.
Sleep
(
5
*
time
.
Second
)
{
res
,
err
:=
makeRequestToGuestbook
(
c
,
cmd
,
arg
)
res
,
err
:=
makeRequestToGuestbook
(
c
,
cmd
,
arg
,
ns
)
if
err
==
nil
&&
res
==
expectedResponse
{
if
err
==
nil
&&
res
==
expectedResponse
{
return
true
return
true
}
}
...
@@ -143,10 +155,10 @@ func waitForGuestbookResponse(c *client.Client, cmd, arg, expectedResponse strin
...
@@ -143,10 +155,10 @@ func waitForGuestbookResponse(c *client.Client, cmd, arg, expectedResponse strin
return
false
return
false
}
}
func
makeRequestToGuestbook
(
c
*
client
.
Client
,
cmd
,
value
string
)
(
string
,
error
)
{
func
makeRequestToGuestbook
(
c
*
client
.
Client
,
cmd
,
value
string
,
ns
string
)
(
string
,
error
)
{
result
,
err
:=
c
.
Get
()
.
result
,
err
:=
c
.
Get
()
.
Prefix
(
"proxy"
)
.
Prefix
(
"proxy"
)
.
Namespace
(
api
.
NamespaceDefault
)
.
Namespace
(
ns
)
.
Resource
(
"services"
)
.
Resource
(
"services"
)
.
Name
(
"frontend"
)
.
Name
(
"frontend"
)
.
Suffix
(
"/index.php"
)
.
Suffix
(
"/index.php"
)
.
...
@@ -165,14 +177,14 @@ type updateDemoData struct {
...
@@ -165,14 +177,14 @@ type updateDemoData struct {
// getUDData creates a validator function based on the input string (i.e. kitten.jpg).
// getUDData creates a validator function based on the input string (i.e. kitten.jpg).
// For example, if you send "kitten.jpg", this function veridies that the image jpg = kitten.jpg
// For example, if you send "kitten.jpg", this function veridies that the image jpg = kitten.jpg
// in the container's json field.
// in the container's json field.
func
getUDData
(
jpgExpected
string
)
func
(
*
client
.
Client
,
string
)
error
{
func
getUDData
(
jpgExpected
string
,
ns
string
)
func
(
*
client
.
Client
,
string
)
error
{
// getUDData validates data.json in the update-demo (returns nil if data is ok).
// getUDData validates data.json in the update-demo (returns nil if data is ok).
return
func
(
c
*
client
.
Client
,
podID
string
)
error
{
return
func
(
c
*
client
.
Client
,
podID
string
)
error
{
Logf
(
"validating pod %s"
,
podID
)
Logf
(
"validating pod %s"
,
podID
)
body
,
err
:=
c
.
Get
()
.
body
,
err
:=
c
.
Get
()
.
Prefix
(
"proxy"
)
.
Prefix
(
"proxy"
)
.
Namespace
(
api
.
NamespaceDefault
)
.
Namespace
(
ns
)
.
Resource
(
"pods"
)
.
Resource
(
"pods"
)
.
Name
(
podID
)
.
Name
(
podID
)
.
Suffix
(
"data.json"
)
.
Suffix
(
"data.json"
)
.
...
...
test/e2e/util.go
View file @
b15e2e73
...
@@ -249,7 +249,7 @@ type validatorFn func(c *client.Client, podID string) error
...
@@ -249,7 +249,7 @@ type validatorFn func(c *client.Client, podID string) error
// "containerImage" : this is the name of the image we expect to be launched. Not to confuse w/ images (kitten.jpg) which are validated.
// "containerImage" : this is the name of the image we expect to be launched. Not to confuse w/ images (kitten.jpg) which are validated.
// "testname": which gets bubbled up to the logging/failure messages if errors happen.
// "testname": which gets bubbled up to the logging/failure messages if errors happen.
// "validator" function: This function is given a podID and a client, and it can do some specific validations that way.
// "validator" function: This function is given a podID and a client, and it can do some specific validations that way.
func
validateController
(
c
*
client
.
Client
,
containerImage
string
,
replicas
int
,
containername
string
,
testname
string
,
validator
validatorFn
)
{
func
validateController
(
c
*
client
.
Client
,
containerImage
string
,
replicas
int
,
containername
string
,
testname
string
,
validator
validatorFn
,
ns
string
)
{
getPodsTemplate
:=
"--template={{range.items}}{{.metadata.name}} {{end}}"
getPodsTemplate
:=
"--template={{range.items}}{{.metadata.name}} {{end}}"
// NB: kubectl adds the "exists" function to the standard template functions.
// NB: kubectl adds the "exists" function to the standard template functions.
// This lets us check to see if the "running" entry exists for each of the containers
// This lets us check to see if the "running" entry exists for each of the containers
...
@@ -265,7 +265,7 @@ func validateController(c *client.Client, containerImage string, replicas int, c
...
@@ -265,7 +265,7 @@ func validateController(c *client.Client, containerImage string, replicas int, c
By
(
fmt
.
Sprintf
(
"waiting for all containers in %s pods to come up."
,
testname
))
//testname should be selector
By
(
fmt
.
Sprintf
(
"waiting for all containers in %s pods to come up."
,
testname
))
//testname should be selector
for
start
:=
time
.
Now
();
time
.
Since
(
start
)
<
podStartTimeout
;
time
.
Sleep
(
5
*
time
.
Second
)
{
for
start
:=
time
.
Now
();
time
.
Since
(
start
)
<
podStartTimeout
;
time
.
Sleep
(
5
*
time
.
Second
)
{
getPodsOutput
:=
runKubectl
(
"get"
,
"pods"
,
"-o"
,
"template"
,
getPodsTemplate
,
"--api-version=v1beta3"
,
"-l"
,
testname
)
getPodsOutput
:=
runKubectl
(
"get"
,
"pods"
,
"-o"
,
"template"
,
getPodsTemplate
,
"--api-version=v1beta3"
,
"-l"
,
testname
,
fmt
.
Sprintf
(
"--namespace=%v"
,
ns
)
)
pods
:=
strings
.
Fields
(
getPodsOutput
)
pods
:=
strings
.
Fields
(
getPodsOutput
)
if
numPods
:=
len
(
pods
);
numPods
!=
replicas
{
if
numPods
:=
len
(
pods
);
numPods
!=
replicas
{
By
(
fmt
.
Sprintf
(
"Replicas for %s: expected=%d actual=%d"
,
testname
,
replicas
,
numPods
))
By
(
fmt
.
Sprintf
(
"Replicas for %s: expected=%d actual=%d"
,
testname
,
replicas
,
numPods
))
...
@@ -273,13 +273,13 @@ func validateController(c *client.Client, containerImage string, replicas int, c
...
@@ -273,13 +273,13 @@ func validateController(c *client.Client, containerImage string, replicas int, c
}
}
var
runningPods
[]
string
var
runningPods
[]
string
for
_
,
podID
:=
range
pods
{
for
_
,
podID
:=
range
pods
{
running
:=
runKubectl
(
"get"
,
"pods"
,
podID
,
"-o"
,
"template"
,
getContainerStateTemplate
,
"--api-version=v1beta3"
)
running
:=
runKubectl
(
"get"
,
"pods"
,
podID
,
"-o"
,
"template"
,
getContainerStateTemplate
,
"--api-version=v1beta3"
,
fmt
.
Sprintf
(
"--namespace=%v"
,
ns
)
)
if
running
!=
"true"
{
if
running
!=
"true"
{
Logf
(
"%s is created but not running"
,
podID
)
Logf
(
"%s is created but not running"
,
podID
)
continue
continue
}
}
currentImage
:=
runKubectl
(
"get"
,
"pods"
,
podID
,
"-o"
,
"template"
,
getImageTemplate
,
"--api-version=v1beta3"
)
currentImage
:=
runKubectl
(
"get"
,
"pods"
,
podID
,
"-o"
,
"template"
,
getImageTemplate
,
"--api-version=v1beta3"
,
fmt
.
Sprintf
(
"--namespace=%v"
,
ns
)
)
if
currentImage
!=
containerImage
{
if
currentImage
!=
containerImage
{
Logf
(
"%s is created but running wrong image; expected: %s, actual: %s"
,
podID
,
containerImage
,
currentImage
)
Logf
(
"%s is created but running wrong image; expected: %s, actual: %s"
,
podID
,
containerImage
,
currentImage
)
continue
continue
...
...
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