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
5ec7109f
Commit
5ec7109f
authored
Jul 24, 2015
by
Marcin Wielgus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
E2E tests for kubectl commands (api-versions, cluster-info, describe)
parent
5c014062
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
169 additions
and
28 deletions
+169
-28
kubectl.go
test/e2e/kubectl.go
+169
-28
No files found.
test/e2e/kubectl.go
View file @
5ec7109f
...
@@ -29,6 +29,8 @@ import (
...
@@ -29,6 +29,8 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
.
"github.com/onsi/gomega"
...
@@ -202,39 +204,123 @@ var _ = Describe("Kubectl client", func() {
...
@@ -202,39 +204,123 @@ var _ = Describe("Kubectl client", func() {
})
})
})
})
Describe
(
"Kubectl label"
,
func
()
{
Describe
(
"Kubectl api-versions"
,
func
()
{
var
podPath
string
It
(
"should check if v1 is in available api versions"
,
func
()
{
var
nsFlag
string
By
(
"validating api verions"
)
BeforeEach
(
func
()
{
output
:=
runKubectl
(
"api-versions"
)
podPath
=
filepath
.
Join
(
testContext
.
RepoRoot
,
"docs/user-guide/pod.yaml"
)
if
!
strings
.
Contains
(
output
,
"Available Server Api Versions:"
)
{
By
(
"creating the pod"
)
Failf
(
"Missing caption in kubectl api-versions"
)
nsFlag
=
fmt
.
Sprintf
(
"--namespace=%v"
,
ns
)
}
runKubectl
(
"create"
,
"-f"
,
podPath
,
nsFlag
)
if
!
strings
.
Contains
(
output
,
"v1"
)
{
checkPodsRunningReady
(
c
,
ns
,
[]
string
{
simplePodName
},
podStartTimeout
)
Failf
(
"No v1 in kubectl api-versions"
)
})
}
AfterEach
(
func
()
{
cleanup
(
podPath
,
ns
,
simplePodSelector
)
})
})
})
It
(
"should update the label on a resource"
,
func
()
{
Describe
(
"Kubectl cluster-info"
,
func
()
{
labelName
:=
"testing-label"
It
(
"should check if Kubernetes master services is included in cluster-info"
,
func
()
{
labelValue
:=
"testing-label-value"
By
(
"validating cluster-info"
)
output
:=
runKubectl
(
"cluster-info"
)
By
(
"adding the label "
+
labelName
+
" with value "
+
labelValue
+
" to a pod"
)
// Can't check exact strings due to terminal controll commands (colors)
runKubectl
(
"label"
,
"pods"
,
simplePodName
,
labelName
+
"="
+
labelValue
,
nsFlag
)
requiredItems
:=
[]
string
{
"Kubernetes master"
,
"is running at"
}
By
(
"verifying the pod has the label "
+
labelName
+
" with the value "
+
labelValue
)
if
providerIs
(
"gce"
,
"gke"
)
{
output
:=
runKubectl
(
"get"
,
"pod"
,
simplePodName
,
"-L"
,
labelName
,
nsFlag
)
requiredItems
=
append
(
requiredItems
,
"KubeDNS"
,
"Heapster"
)
if
!
strings
.
Contains
(
output
,
labelValue
)
{
}
Failf
(
"Failed updating label "
+
labelName
+
" to the pod "
+
simplePodName
)
for
_
,
item
:=
range
requiredItems
{
if
!
strings
.
Contains
(
output
,
item
)
{
Failf
(
"Missing %s in kubectl cluster-info"
,
item
)
}
}
}
})
})
By
(
"removing the label "
+
labelName
+
" of a pod"
)
Describe
(
"Kubectl describe"
,
func
()
{
runKubectl
(
"label"
,
"pods"
,
simplePodName
,
labelName
+
"-"
,
nsFlag
)
It
(
"should check if kubectl describe prints relevant information for rc and pods"
,
func
()
{
By
(
"verifying the pod doesn't have the label "
+
labelName
)
mkpath
:=
func
(
file
string
)
string
{
output
=
runKubectl
(
"get"
,
"pod"
,
simplePodName
,
"-L"
,
labelName
,
nsFlag
)
return
filepath
.
Join
(
testContext
.
RepoRoot
,
"examples/guestbook-go"
,
file
)
if
strings
.
Contains
(
output
,
labelValue
)
{
Failf
(
"Failed removing label "
+
labelName
+
" of the pod "
+
simplePodName
)
}
}
controllerJson
:=
mkpath
(
"redis-master-controller.json"
)
serviceJson
:=
mkpath
(
"redis-master-service.json"
)
nsFlag
:=
fmt
.
Sprintf
(
"--namespace=%v"
,
ns
)
runKubectl
(
"create"
,
"-f"
,
controllerJson
,
nsFlag
)
runKubectl
(
"create"
,
"-f"
,
serviceJson
,
nsFlag
)
// Pod
forEachPod
(
c
,
ns
,
"app"
,
"redis"
,
func
(
pod
api
.
Pod
)
{
output
:=
runKubectl
(
"describe"
,
"pod"
,
pod
.
Name
,
nsFlag
)
requiredStrings
:=
[][]
string
{
{
"Name:"
,
"redis-master-"
},
{
"Namespace:"
,
ns
},
{
"Image(s):"
,
"redis"
},
{
"Node:"
},
{
"Labels:"
,
"app=redis"
,
"role=master"
},
{
"Status:"
,
"Running"
},
{
"Reason:"
},
{
"Message:"
},
{
"IP:"
},
{
"Replication Controllers:"
,
"redis-master"
}}
checkOutput
(
output
,
requiredStrings
)
})
// Rc
output
:=
runKubectl
(
"describe"
,
"rc"
,
"redis-master"
,
nsFlag
)
requiredStrings
:=
[][]
string
{
{
"Name:"
,
"redis-master"
},
{
"Namespace:"
,
ns
},
{
"Image(s):"
,
"redis"
},
{
"Selector:"
,
"app=redis,role=master"
},
{
"Labels:"
,
"app=redis,role=master"
},
{
"Replicas:"
,
"1 current"
,
"1 desired"
},
{
"Pods Status:"
,
"1 Running"
,
"0 Waiting"
,
"0 Succeeded"
,
"0 Failed"
},
{
"Events:"
}}
checkOutput
(
output
,
requiredStrings
)
// Service
output
=
runKubectl
(
"describe"
,
"service"
,
"redis-master"
,
nsFlag
)
requiredStrings
=
[][]
string
{
{
"Name:"
,
"redis-master"
},
{
"Namespace:"
,
ns
},
{
"Labels:"
,
"app=redis"
,
"role=master"
},
{
"Selector:"
,
"app=redis"
,
"role=master"
},
{
"Type:"
,
"ClusterIP"
},
{
"IP:"
},
{
"Port:"
,
"<unnamed>"
,
"6379/TCP"
},
{
"Endpoints:"
},
{
"Session Affinity:"
,
"None"
}}
checkOutput
(
output
,
requiredStrings
)
// Node
minions
,
err
:=
c
.
Nodes
()
.
List
(
labels
.
Everything
(),
fields
.
Everything
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
node
:=
minions
.
Items
[
0
]
output
=
runKubectl
(
"describe"
,
"node"
,
node
.
Name
)
requiredStrings
=
[][]
string
{
{
"Name:"
,
node
.
Name
},
{
"Labels:"
},
{
"CreationTimestamp:"
},
{
"Conditions:"
},
{
"Type"
,
"Status"
,
"LastHeartbeatTime"
,
"LastTransitionTime"
,
"Reason"
,
"Message"
},
{
"Addresses:"
},
{
"Capacity:"
},
{
"Version:"
},
{
"Kernel Version:"
},
{
"OS Image:"
},
{
"Container Runtime Version:"
},
{
"Kubelet Version:"
},
{
"Kube-Proxy Version:"
},
{
"Pods:"
}}
checkOutput
(
output
,
requiredStrings
)
// Namespace
output
=
runKubectl
(
"describe"
,
"namespace"
,
ns
)
requiredStrings
=
[][]
string
{
{
"Name:"
,
ns
},
{
"Labels:"
},
{
"Status:"
,
"Active"
}}
checkOutput
(
output
,
requiredStrings
)
// Quota and limitrange are skipped for now.
})
})
})
})
...
@@ -303,6 +389,42 @@ var _ = Describe("Kubectl client", func() {
...
@@ -303,6 +389,42 @@ var _ = Describe("Kubectl client", func() {
})
})
})
})
Describe
(
"Kubectl label"
,
func
()
{
var
podPath
string
var
nsFlag
string
BeforeEach
(
func
()
{
podPath
=
filepath
.
Join
(
testContext
.
RepoRoot
,
"docs/user-guide/pod.yaml"
)
By
(
"creating the pod"
)
nsFlag
=
fmt
.
Sprintf
(
"--namespace=%v"
,
ns
)
runKubectl
(
"create"
,
"-f"
,
podPath
,
nsFlag
)
checkPodsRunningReady
(
c
,
ns
,
[]
string
{
simplePodName
},
podStartTimeout
)
})
AfterEach
(
func
()
{
cleanup
(
podPath
,
ns
,
simplePodSelector
)
})
It
(
"should update the label on a resource"
,
func
()
{
labelName
:=
"testing-label"
labelValue
:=
"testing-label-value"
By
(
"adding the label "
+
labelName
+
" with value "
+
labelValue
+
" to a pod"
)
runKubectl
(
"label"
,
"pods"
,
simplePodName
,
labelName
+
"="
+
labelValue
,
nsFlag
)
By
(
"verifying the pod has the label "
+
labelName
+
" with the value "
+
labelValue
)
output
:=
runKubectl
(
"get"
,
"pod"
,
simplePodName
,
"-L"
,
labelName
,
nsFlag
)
if
!
strings
.
Contains
(
output
,
labelValue
)
{
Failf
(
"Failed updating label "
+
labelName
+
" to the pod "
+
simplePodName
)
}
By
(
"removing the label "
+
labelName
+
" of a pod"
)
runKubectl
(
"label"
,
"pods"
,
simplePodName
,
labelName
+
"-"
,
nsFlag
)
By
(
"verifying the pod doesn't have the label "
+
labelName
)
output
=
runKubectl
(
"get"
,
"pod"
,
simplePodName
,
"-L"
,
labelName
,
nsFlag
)
if
strings
.
Contains
(
output
,
labelValue
)
{
Failf
(
"Failed removing label "
+
labelName
+
" of the pod "
+
simplePodName
)
}
})
})
Describe
(
"Kubectl logs"
,
func
()
{
Describe
(
"Kubectl logs"
,
func
()
{
It
(
"should find a string in pod logs"
,
func
()
{
It
(
"should find a string in pod logs"
,
func
()
{
mkpath
:=
func
(
file
string
)
string
{
mkpath
:=
func
(
file
string
)
string
{
...
@@ -362,6 +484,25 @@ var _ = Describe("Kubectl client", func() {
...
@@ -362,6 +484,25 @@ var _ = Describe("Kubectl client", func() {
})
})
})
})
// Checks whether the output split by line contains the required elements.
func
checkOutput
(
output
string
,
required
[][]
string
)
{
outputLines
:=
strings
.
Split
(
output
,
"
\n
"
)
currentLine
:=
0
for
_
,
requirement
:=
range
required
{
for
currentLine
<
len
(
outputLines
)
&&
!
strings
.
Contains
(
outputLines
[
currentLine
],
requirement
[
0
])
{
currentLine
++
}
if
currentLine
==
len
(
outputLines
)
{
Failf
(
"Failed to find %s in %s"
,
requirement
[
0
],
output
)
}
for
_
,
item
:=
range
requirement
[
1
:
]
{
if
!
strings
.
Contains
(
outputLines
[
currentLine
],
item
)
{
Failf
(
"Failed to find %s in %s"
,
item
,
outputLines
[
currentLine
])
}
}
}
}
func
curl
(
addr
string
)
(
string
,
error
)
{
func
curl
(
addr
string
)
(
string
,
error
)
{
resp
,
err
:=
http
.
Get
(
addr
)
resp
,
err
:=
http
.
Get
(
addr
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
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