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
8387ff42
Commit
8387ff42
authored
Jan 19, 2018
by
Zihong Zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[e2e util] Remove static IP functions based on gcloud
parent
77ac663d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
79 deletions
+20
-79
google_compute.go
test/e2e/framework/google_compute.go
+0
-72
BUILD
test/e2e/network/BUILD
+1
-0
network_tiers.go
test/e2e/network/network_tiers.go
+5
-4
service.go
test/e2e/network/service.go
+14
-3
No files found.
test/e2e/framework/google_compute.go
View file @
8387ff42
...
@@ -22,84 +22,12 @@ import (
...
@@ -22,84 +22,12 @@ import (
"io/ioutil"
"io/ioutil"
"os/exec"
"os/exec"
"path/filepath"
"path/filepath"
"regexp"
"strings"
"strings"
"time"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce"
)
)
// TODO: These should really just use the GCE API client library or at least use
// TODO: These should really just use the GCE API client library or at least use
// better formatted output from the --format flag.
// better formatted output from the --format flag.
func
CreateGCEStaticIP
(
name
string
)
(
string
,
error
)
{
// gcloud compute --project "abshah-kubernetes-001" addresses create "test-static-ip" --region "us-central1"
// abshah@abhidesk:~/go/src/code.google.com/p/google-api-go-client/compute/v1$ gcloud compute --project "abshah-kubernetes-001" addresses create "test-static-ip" --region "us-central1"
// Created [https://www.googleapis.com/compute/v1/projects/abshah-kubernetes-001/regions/us-central1/addresses/test-static-ip].
// NAME REGION ADDRESS STATUS
// test-static-ip us-central1 104.197.143.7 RESERVED
var
outputBytes
[]
byte
var
err
error
region
,
err
:=
gce
.
GetGCERegion
(
TestContext
.
CloudConfig
.
Zone
)
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"failed to convert zone to region: %v"
,
err
)
}
glog
.
Infof
(
"Creating static IP with name %q in project %q in region %q"
,
name
,
TestContext
.
CloudConfig
.
ProjectID
,
region
)
for
attempts
:=
0
;
attempts
<
4
;
attempts
++
{
outputBytes
,
err
=
exec
.
Command
(
"gcloud"
,
"compute"
,
"addresses"
,
"create"
,
name
,
"--project"
,
TestContext
.
CloudConfig
.
ProjectID
,
"--region"
,
region
,
"-q"
,
"--format=yaml"
)
.
CombinedOutput
()
if
err
==
nil
{
break
}
glog
.
Errorf
(
"output from failed attempt to create static IP: %s"
,
outputBytes
)
time
.
Sleep
(
time
.
Duration
(
5
*
attempts
)
*
time
.
Second
)
}
if
err
!=
nil
{
// Ditch the error, since the stderr in the output is what actually contains
// any useful info.
return
""
,
fmt
.
Errorf
(
"failed to create static IP: %s"
,
outputBytes
)
}
output
:=
string
(
outputBytes
)
if
strings
.
Contains
(
output
,
"RESERVED"
)
{
r
,
_
:=
regexp
.
Compile
(
"[0-9]+
\\
.[0-9]+
\\
.[0-9]+
\\
.[0-9]+"
)
staticIP
:=
r
.
FindString
(
output
)
if
staticIP
==
""
{
return
""
,
fmt
.
Errorf
(
"static IP not found in gcloud command output: %v"
,
output
)
}
else
{
return
staticIP
,
nil
}
}
else
{
return
""
,
fmt
.
Errorf
(
"static IP %q could not be reserved: %v"
,
name
,
output
)
}
}
func
DeleteGCEStaticIP
(
name
string
)
error
{
// gcloud compute --project "abshah-kubernetes-001" addresses create "test-static-ip" --region "us-central1"
// abshah@abhidesk:~/go/src/code.google.com/p/google-api-go-client/compute/v1$ gcloud compute --project "abshah-kubernetes-001" addresses create "test-static-ip" --region "us-central1"
// Created [https://www.googleapis.com/compute/v1/projects/abshah-kubernetes-001/regions/us-central1/addresses/test-static-ip].
// NAME REGION ADDRESS STATUS
// test-static-ip us-central1 104.197.143.7 RESERVED
region
,
err
:=
gce
.
GetGCERegion
(
TestContext
.
CloudConfig
.
Zone
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to convert zone to region: %v"
,
err
)
}
glog
.
Infof
(
"Deleting static IP with name %q in project %q in region %q"
,
name
,
TestContext
.
CloudConfig
.
ProjectID
,
region
)
outputBytes
,
err
:=
exec
.
Command
(
"gcloud"
,
"compute"
,
"addresses"
,
"delete"
,
name
,
"--project"
,
TestContext
.
CloudConfig
.
ProjectID
,
"--region"
,
region
,
"-q"
)
.
CombinedOutput
()
if
err
!=
nil
{
// Ditch the error, since the stderr in the output is what actually contains
// any useful info.
return
fmt
.
Errorf
(
"failed to delete static IP %q: %v"
,
name
,
string
(
outputBytes
))
}
return
nil
}
// Returns master & node image string, or error
// Returns master & node image string, or error
func
lookupClusterImageSources
()
(
string
,
string
,
error
)
{
func
lookupClusterImageSources
()
(
string
,
string
,
error
)
{
// Given args for a gcloud compute command, run it with other args, and return the values,
// Given args for a gcloud compute command, run it with other args, and return the values,
...
...
test/e2e/network/BUILD
View file @
8387ff42
...
@@ -46,6 +46,7 @@ go_library(
...
@@ -46,6 +46,7 @@ go_library(
"//vendor/github.com/onsi/ginkgo:go_default_library",
"//vendor/github.com/onsi/ginkgo:go_default_library",
"//vendor/github.com/onsi/gomega:go_default_library",
"//vendor/github.com/onsi/gomega:go_default_library",
"//vendor/google.golang.org/api/compute/v0.alpha:go_default_library",
"//vendor/google.golang.org/api/compute/v0.alpha:go_default_library",
"//vendor/google.golang.org/api/compute/v1:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/api/networking/v1:go_default_library",
"//vendor/k8s.io/api/networking/v1:go_default_library",
"//vendor/k8s.io/api/rbac/v1beta1:go_default_library",
"//vendor/k8s.io/api/rbac/v1beta1:go_default_library",
...
...
test/e2e/network/network_tiers.go
View file @
8387ff42
...
@@ -104,12 +104,14 @@ var _ = SIGDescribe("Services [Feature:GCEAlphaFeature][Slow]", func() {
...
@@ -104,12 +104,14 @@ var _ = SIGDescribe("Services [Feature:GCEAlphaFeature][Slow]", func() {
// Test 3: create a standard-tierd LB with a user-requested IP.
// Test 3: create a standard-tierd LB with a user-requested IP.
By
(
"reserving a static IP for the load balancer"
)
By
(
"reserving a static IP for the load balancer"
)
requestedAddrName
:=
fmt
.
Sprintf
(
"e2e-ext-lb-net-tier-%s"
,
framework
.
RunId
)
requestedAddrName
:=
fmt
.
Sprintf
(
"e2e-ext-lb-net-tier-%s"
,
framework
.
RunId
)
requestedIP
,
err
:=
reserveAlphaRegionalAddress
(
requestedAddrName
,
gcecloud
.
NetworkTierStandard
)
gceCloud
,
err
:=
framework
.
GetGCECloud
()
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
requestedIP
,
err
:=
reserveAlphaRegionalAddress
(
gceCloud
,
requestedAddrName
,
gcecloud
.
NetworkTierStandard
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
"failed to reserve a STANDARD tiered address"
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
"failed to reserve a STANDARD tiered address"
)
defer
func
()
{
defer
func
()
{
if
requestedAddrName
!=
""
{
if
requestedAddrName
!=
""
{
// Release GCE static address - this is not kube-managed and will not be automatically released.
// Release GCE static address - this is not kube-managed and will not be automatically released.
if
err
:=
framework
.
DeleteGCEStaticIP
(
requestedAddrName
);
err
!=
nil
{
if
err
:=
gceCloud
.
DeleteRegionAddress
(
requestedAddrName
,
gceCloud
.
Region
()
);
err
!=
nil
{
framework
.
Logf
(
"failed to release static IP address %q: %v"
,
requestedAddrName
,
err
)
framework
.
Logf
(
"failed to release static IP address %q: %v"
,
requestedAddrName
,
err
)
}
}
}
}
...
@@ -221,8 +223,7 @@ func clearNetworkTier(svc *v1.Service) {
...
@@ -221,8 +223,7 @@ func clearNetworkTier(svc *v1.Service) {
// TODO: add retries if this turns out to be flaky.
// TODO: add retries if this turns out to be flaky.
// TODO(#51665): remove this helper function once Network Tiers becomes beta.
// TODO(#51665): remove this helper function once Network Tiers becomes beta.
func
reserveAlphaRegionalAddress
(
name
string
,
netTier
gcecloud
.
NetworkTier
)
(
string
,
error
)
{
func
reserveAlphaRegionalAddress
(
cloud
*
gcecloud
.
GCECloud
,
name
string
,
netTier
gcecloud
.
NetworkTier
)
(
string
,
error
)
{
cloud
,
err
:=
framework
.
GetGCECloud
()
alphaAddr
:=
&
computealpha
.
Address
{
alphaAddr
:=
&
computealpha
.
Address
{
Name
:
name
,
Name
:
name
,
NetworkTier
:
netTier
.
ToGCEValue
(),
NetworkTier
:
netTier
.
ToGCEValue
(),
...
...
test/e2e/network/service.go
View file @
8387ff42
...
@@ -25,6 +25,8 @@ import (
...
@@ -25,6 +25,8 @@ import (
"strings"
"strings"
"time"
"time"
compute
"google.golang.org/api/compute/v1"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/labels"
...
@@ -572,16 +574,23 @@ var _ = SIGDescribe("Services", func() {
...
@@ -572,16 +574,23 @@ var _ = SIGDescribe("Services", func() {
if
framework
.
ProviderIs
(
"gce"
,
"gke"
)
{
if
framework
.
ProviderIs
(
"gce"
,
"gke"
)
{
By
(
"creating a static load balancer IP"
)
By
(
"creating a static load balancer IP"
)
staticIPName
=
fmt
.
Sprintf
(
"e2e-external-lb-test-%s"
,
framework
.
RunId
)
staticIPName
=
fmt
.
Sprintf
(
"e2e-external-lb-test-%s"
,
framework
.
RunId
)
requestedIP
,
err
=
framework
.
CreateGCEStaticIP
(
staticIPName
)
gceCloud
,
err
:=
framework
.
GetGCECloud
()
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
err
=
gceCloud
.
ReserveRegionAddress
(
&
compute
.
Address
{
Name
:
staticIPName
},
gceCloud
.
Region
())
defer
func
()
{
defer
func
()
{
if
staticIPName
!=
""
{
if
staticIPName
!=
""
{
// Release GCE static IP - this is not kube-managed and will not be automatically released.
// Release GCE static IP - this is not kube-managed and will not be automatically released.
if
err
:=
framework
.
DeleteGCEStaticIP
(
staticIPName
);
err
!=
nil
{
if
err
:=
gceCloud
.
DeleteRegionAddress
(
staticIPName
,
gceCloud
.
Region
()
);
err
!=
nil
{
framework
.
Logf
(
"failed to release static IP %s: %v"
,
staticIPName
,
err
)
framework
.
Logf
(
"failed to release static IP %s: %v"
,
staticIPName
,
err
)
}
}
}
}
}()
}()
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
reservedAddr
,
err
:=
gceCloud
.
GetRegionAddress
(
staticIPName
,
gceCloud
.
Region
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
requestedIP
=
reservedAddr
.
Address
framework
.
Logf
(
"Allocated static load balancer IP: %s"
,
requestedIP
)
framework
.
Logf
(
"Allocated static load balancer IP: %s"
,
requestedIP
)
}
}
...
@@ -622,9 +631,11 @@ var _ = SIGDescribe("Services", func() {
...
@@ -622,9 +631,11 @@ var _ = SIGDescribe("Services", func() {
// coming from, so this is first-aid rather than surgery).
// coming from, so this is first-aid rather than surgery).
By
(
"demoting the static IP to ephemeral"
)
By
(
"demoting the static IP to ephemeral"
)
if
staticIPName
!=
""
{
if
staticIPName
!=
""
{
gceCloud
,
err
:=
framework
.
GetGCECloud
()
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
// Deleting it after it is attached "demotes" it to an
// Deleting it after it is attached "demotes" it to an
// ephemeral IP, which can be auto-released.
// ephemeral IP, which can be auto-released.
if
err
:=
framework
.
DeleteGCEStaticIP
(
staticIPName
);
err
!=
nil
{
if
err
:=
gceCloud
.
DeleteRegionAddress
(
staticIPName
,
gceCloud
.
Region
()
);
err
!=
nil
{
framework
.
Failf
(
"failed to release static IP %s: %v"
,
staticIPName
,
err
)
framework
.
Failf
(
"failed to release static IP %s: %v"
,
staticIPName
,
err
)
}
}
staticIPName
=
""
staticIPName
=
""
...
...
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