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
5d67b152
Commit
5d67b152
authored
Oct 07, 2015
by
Brendan Burns
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some retry to static ip creation
parent
ed382ec0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
12 deletions
+46
-12
util.sh
cluster/gce/util.sh
+33
-7
google_compute.go
test/e2e/google_compute.go
+13
-5
No files found.
cluster/gce/util.sh
View file @
5d67b152
...
@@ -333,6 +333,30 @@ function wait-for-jobs {
...
@@ -333,6 +333,30 @@ function wait-for-jobs {
fi
fi
}
}
# Robustly try to create a static ip.
# $1: The name of the ip to create
# $2: The name of the region to create the ip in.
function
create-static-ip
{
detect-project
local
attempt
=
0
local
REGION
=
"
$2
"
while
true
;
do
if
!
gcloud compute addresses create
"
$1
"
\
--project
"
${
PROJECT
}
"
\
--region
"
${
REGION
}
"
-q
>
/dev/null
;
then
if
((
attempt
>
4
))
;
then
echo
-e
"
${
color_red
}
Failed to create static ip
$1
${
color_norm
}
"
>
&2
exit
2
fi
attempt
=
$((
$attempt
+
1
))
echo
-e
"
${
color_yellow
}
Attempt
$attempt
failed to create static ip
$1
. Retrying.
${
color_norm
}
"
>
&2
sleep
$((
$attempt
*
5
))
else
break
fi
done
}
# Robustly try to create a firewall rule.
# Robustly try to create a firewall rule.
# $1: The name of firewall rule.
# $1: The name of firewall rule.
# $2: IP ranges.
# $2: IP ranges.
...
@@ -347,12 +371,13 @@ function create-firewall-rule {
...
@@ -347,12 +371,13 @@ function create-firewall-rule {
--source-ranges
"
$2
"
\
--source-ranges
"
$2
"
\
--target-tags
"
$3
"
\
--target-tags
"
$3
"
\
--allow
tcp,udp,icmp,esp,ah,sctp
;
then
--allow
tcp,udp,icmp,esp,ah,sctp
;
then
if
((
attempt
>
5
))
;
then
if
((
attempt
>
4
))
;
then
echo
-e
"
${
color_red
}
Failed to create firewall rule
$1
${
color_norm
}
"
>
&2
echo
-e
"
${
color_red
}
Failed to create firewall rule
$1
${
color_norm
}
"
>
&2
exit
2
exit
2
fi
fi
echo
-e
"
${
color_yellow
}
Attempt
$((
$attempt
+
1
))
failed to create firewall rule
$1
. Retrying.
${
color_norm
}
"
>
&2
echo
-e
"
${
color_yellow
}
Attempt
$((
$attempt
+
1
))
failed to create firewall rule
$1
. Retrying.
${
color_norm
}
"
>
&2
attempt
=
$((
$attempt
+
1
))
attempt
=
$((
$attempt
+
1
))
sleep
$((
$attempt
*
5
))
else
else
break
break
fi
fi
...
@@ -654,7 +679,8 @@ function kube-up {
...
@@ -654,7 +679,8 @@ function kube-up {
# so extract the region name, which is the same as the zone but with the final
# so extract the region name, which is the same as the zone but with the final
# dash and characters trailing the dash removed.
# dash and characters trailing the dash removed.
local
REGION
=
${
ZONE
%-*
}
local
REGION
=
${
ZONE
%-*
}
MASTER_RESERVED_IP
=
$(
gcloud compute addresses create
"
${
MASTER_NAME
}
-ip"
\
create-static-ip
"
${
MASTER_NAME
}
-ip"
"
${
REGION
}
"
MASTER_RESERVED_IP
=
$(
gcloud compute addresses describe
"
${
MASTER_NAME
}
-ip"
\
--project
"
${
PROJECT
}
"
\
--project
"
${
PROJECT
}
"
\
--region
"
${
REGION
}
"
-q
--format
yaml |
awk
'/^address:/ { print $2 }'
)
--region
"
${
REGION
}
"
-q
--format
yaml |
awk
'/^address:/ { print $2 }'
)
...
...
test/e2e/google_compute.go
View file @
5d67b152
...
@@ -21,6 +21,7 @@ import (
...
@@ -21,6 +21,7 @@ import (
"os/exec"
"os/exec"
"regexp"
"regexp"
"strings"
"strings"
"time"
"github.com/golang/glog"
"github.com/golang/glog"
)
)
...
@@ -32,15 +33,22 @@ func createGCEStaticIP(name string) (string, error) {
...
@@ -32,15 +33,22 @@ func createGCEStaticIP(name string) (string, error) {
// NAME REGION ADDRESS STATUS
// NAME REGION ADDRESS STATUS
// test-static-ip us-central1 104.197.143.7 RESERVED
// test-static-ip us-central1 104.197.143.7 RESERVED
output
,
err
:=
exec
.
Command
(
"gcloud"
,
"compute"
,
"addresses"
,
"create"
,
var
output
[]
byte
name
,
"--project"
,
testContext
.
CloudConfig
.
ProjectID
,
var
err
error
"--region"
,
"us-central1"
,
"-q"
)
.
CombinedOutput
()
for
attempts
:=
0
;
attempts
<
4
;
attempts
++
{
if
err
!=
nil
{
output
,
err
=
exec
.
Command
(
"gcloud"
,
"compute"
,
"addresses"
,
"create"
,
name
,
"--project"
,
testContext
.
CloudConfig
.
ProjectID
,
"--region"
,
"us-central1"
,
"-q"
)
.
CombinedOutput
()
if
err
==
nil
{
break
}
glog
.
Errorf
(
"Creating static IP with name:%s in project: %s"
,
name
,
testContext
.
CloudConfig
.
ProjectID
)
glog
.
Errorf
(
"Creating static IP with name:%s in project: %s"
,
name
,
testContext
.
CloudConfig
.
ProjectID
)
glog
.
Errorf
(
"output: %s"
,
output
)
glog
.
Errorf
(
"output: %s"
,
output
)
time
.
Sleep
(
time
.
Duration
(
5
*
attempts
)
*
time
.
Second
)
}
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
glog
.
Errorf
(
"Creating static IP with name:%s in project: %s"
,
name
,
testContext
.
CloudConfig
.
ProjectID
)
text
:=
string
(
output
)
text
:=
string
(
output
)
if
strings
.
Contains
(
text
,
"RESERVED"
)
{
if
strings
.
Contains
(
text
,
"RESERVED"
)
{
r
,
_
:=
regexp
.
Compile
(
"[0-9]+
\\
.[0-9]+
\\
.[0-9]+
\\
.[0-9]+"
)
r
,
_
:=
regexp
.
Compile
(
"[0-9]+
\\
.[0-9]+
\\
.[0-9]+
\\
.[0-9]+"
)
...
...
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