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
81c5cfc1
Commit
81c5cfc1
authored
Jun 03, 2016
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #26773 from mwielgus/gke-autoscaling
Automatic merge from submit-queue Setup for cluster autoscaling tests in GKE cc: @piosz @jszczepkowski @fgrzadkowski
parents
8d57a441
ab56306b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
94 additions
and
1 deletion
+94
-1
cluster_size_autoscaling.go
test/e2e/cluster_size_autoscaling.go
+94
-1
No files found.
test/e2e/cluster_size_autoscaling.go
View file @
81c5cfc1
...
...
@@ -17,7 +17,11 @@ limitations under the License.
package
e2e
import
(
"bytes"
"fmt"
"io/ioutil"
"net/http"
"os/exec"
"strings"
"time"
...
...
@@ -36,6 +40,10 @@ const (
resizeTimeout
=
5
*
time
.
Minute
scaleUpTimeout
=
5
*
time
.
Minute
scaleDownTimeout
=
15
*
time
.
Minute
gkeEndpoint
=
"https://test-container.sandbox.googleapis.com"
zone
=
"us-central1-b"
gkeUpdateTimeout
=
10
*
time
.
Minute
)
var
_
=
framework
.
KubeDescribe
(
"Cluster size autoscaling [Slow]"
,
func
()
{
...
...
@@ -46,7 +54,15 @@ var _ = framework.KubeDescribe("Cluster size autoscaling [Slow]", func() {
var
originalSizes
map
[
string
]
int
BeforeEach
(
func
()
{
framework
.
SkipUnlessProviderIs
(
"gce"
)
framework
.
SkipUnlessProviderIs
(
"gce"
,
"gke"
)
if
framework
.
ProviderIs
(
"gke"
)
{
val
,
err
:=
isAutoscalerEnabled
()
framework
.
ExpectNoError
(
err
)
if
!
val
{
err
=
enableAutoscaler
()
framework
.
ExpectNoError
(
err
)
}
}
nodes
:=
framework
.
GetReadySchedulableNodesOrDie
(
f
.
Client
)
nodeCount
=
len
(
nodes
.
Items
)
...
...
@@ -114,6 +130,83 @@ var _ = framework.KubeDescribe("Cluster size autoscaling [Slow]", func() {
})
})
func
getGKEClusterUrl
()
string
{
out
,
err
:=
exec
.
Command
(
"gcloud"
,
"auth"
,
"print-access-token"
)
.
Output
()
framework
.
ExpectNoError
(
err
)
token
:=
strings
.
Replace
(
string
(
out
),
"
\n
"
,
""
,
-
1
)
return
fmt
.
Sprintf
(
"%s/v1/projects/%s/zones/%s/clusters/%s?access_token=%s"
,
gkeEndpoint
,
framework
.
TestContext
.
CloudConfig
.
ProjectID
,
framework
.
TestContext
.
CloudConfig
.
Zone
,
framework
.
TestContext
.
CloudConfig
.
Cluster
,
token
)
}
func
isAutoscalerEnabled
()
(
bool
,
error
)
{
resp
,
err
:=
http
.
Get
(
getGKEClusterUrl
())
if
err
!=
nil
{
return
false
,
err
}
defer
resp
.
Body
.
Close
()
body
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
return
false
,
err
}
strBody
:=
string
(
body
)
glog
.
Infof
(
"Cluster config %s"
,
strBody
)
if
strings
.
Contains
(
strBody
,
"minNodeCount"
)
{
return
true
,
nil
}
return
false
,
nil
}
func
enableAutoscaler
()
error
{
updateRequest
:=
"{"
+
"
\"
update
\"
: {"
+
"
\"
desiredNodePoolId
\"
:
\"
default-pool
\"
,"
+
"
\"
desiredNodePoolAutoscaling
\"
: {"
+
"
\"
enabled
\"
:
\"
true
\"
,"
+
"
\"
minNodeCount
\"
:
\"
3
\"
,"
+
"
\"
maxNodeCount
\"
:
\"
5
\"
"
+
" }"
+
" }"
+
"}"
url
:=
getGKEClusterUrl
()
glog
.
Infof
(
"Using gke api url %s"
,
url
)
putResult
,
err
:=
doPut
(
url
,
updateRequest
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to put %s: %v"
,
url
,
err
)
}
glog
.
Infof
(
"Config update result: %s"
,
putResult
)
for
startTime
:=
time
.
Now
();
startTime
.
Add
(
gkeUpdateTimeout
)
.
After
(
time
.
Now
());
time
.
Sleep
(
30
*
time
.
Second
)
{
if
val
,
err
:=
isAutoscalerEnabled
();
err
==
nil
&&
val
{
return
nil
}
}
return
fmt
.
Errorf
(
"autoscaler not enabled"
)
}
func
doPut
(
url
,
content
string
)
(
string
,
error
)
{
req
,
err
:=
http
.
NewRequest
(
"PUT"
,
url
,
bytes
.
NewBuffer
([]
byte
(
content
)))
req
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
client
:=
&
http
.
Client
{}
resp
,
err
:=
client
.
Do
(
req
)
if
err
!=
nil
{
return
""
,
err
}
defer
resp
.
Body
.
Close
()
body
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
return
""
,
err
}
strBody
:=
string
(
body
)
return
strBody
,
nil
}
func
CreateHostPortPods
(
f
*
framework
.
Framework
,
id
string
,
replicas
int
,
expectRunning
bool
)
{
By
(
fmt
.
Sprintf
(
"Running RC which reserves host port"
))
config
:=
&
framework
.
RCConfig
{
...
...
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