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
1f336dda
Commit
1f336dda
authored
Jun 14, 2018
by
Nick Sardo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use context with timeout instead of context.Background
parent
a1923f37
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
513 additions
and
139 deletions
+513
-139
BUILD
pkg/cloudprovider/providers/gce/cloud/BUILD
+1
-0
context.go
pkg/cloudprovider/providers/gce/cloud/context.go
+31
-0
gce_addresses.go
pkg/cloudprovider/providers/gce/gce_addresses.go
+48
-13
gce_backendservice.go
pkg/cloudprovider/providers/gce/gce_backendservice.go
+61
-17
gce_cert.go
pkg/cloudprovider/providers/gce/gce_cert.go
+17
-6
gce_firewall.go
pkg/cloudprovider/providers/gce/gce_firewall.go
+17
-6
gce_forwardingrule.go
pkg/cloudprovider/providers/gce/gce_forwardingrule.go
+48
-14
gce_healthchecks.go
pkg/cloudprovider/providers/gce/gce_healthchecks.go
+73
-20
gce_instancegroup.go
pkg/cloudprovider/providers/gce/gce_instancegroup.go
+33
-10
gce_instances.go
pkg/cloudprovider/providers/gce/gce_instances.go
+46
-13
gce_networkendpointgroup.go
pkg/cloudprovider/providers/gce/gce_networkendpointgroup.go
+33
-9
gce_routes.go
pkg/cloudprovider/providers/gce/gce_routes.go
+13
-3
gce_targetpool.go
pkg/cloudprovider/providers/gce/gce_targetpool.go
+21
-7
gce_targetproxy.go
pkg/cloudprovider/providers/gce/gce_targetproxy.go
+45
-13
gce_urlmap.go
pkg/cloudprovider/providers/gce/gce_urlmap.go
+21
-7
gce_zones.go
pkg/cloudprovider/providers/gce/gce_zones.go
+5
-1
No files found.
pkg/cloudprovider/providers/gce/cloud/BUILD
View file @
1f336dda
...
@@ -4,6 +4,7 @@ go_library(
...
@@ -4,6 +4,7 @@ go_library(
name = "go_default_library",
name = "go_default_library",
srcs = [
srcs = [
"constants.go",
"constants.go",
"context.go",
"doc.go",
"doc.go",
"errors.go",
"errors.go",
"gce_projects.go",
"gce_projects.go",
...
...
pkg/cloudprovider/providers/gce/cloud/context.go
0 → 100644
View file @
1f336dda
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
cloud
import
(
"context"
"time"
)
const
(
defaultCallTimeout
=
1
*
time
.
Hour
)
// ContextWithCallTimeout returns a context with a default timeout, used for generated client calls.
func
ContextWithCallTimeout
()
(
context
.
Context
,
context
.
CancelFunc
)
{
return
context
.
WithTimeout
(
context
.
Background
(),
defaultCallTimeout
)
}
pkg/cloudprovider/providers/gce/gce_addresses.go
View file @
1f336dda
...
@@ -17,7 +17,6 @@ limitations under the License.
...
@@ -17,7 +17,6 @@ limitations under the License.
package
gce
package
gce
import
(
import
(
"context"
"fmt"
"fmt"
"github.com/golang/glog"
"github.com/golang/glog"
...
@@ -44,72 +43,105 @@ func newAddressMetricContextWithVersion(request, region, version string) *metric
...
@@ -44,72 +43,105 @@ func newAddressMetricContextWithVersion(request, region, version string) *metric
// ipAddress is specified, it must belong to the current project, eg: an
// ipAddress is specified, it must belong to the current project, eg: an
// ephemeral IP associated with a global forwarding rule.
// ephemeral IP associated with a global forwarding rule.
func
(
gce
*
GCECloud
)
ReserveGlobalAddress
(
addr
*
compute
.
Address
)
error
{
func
(
gce
*
GCECloud
)
ReserveGlobalAddress
(
addr
*
compute
.
Address
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newAddressMetricContext
(
"reserve"
,
""
)
mc
:=
newAddressMetricContext
(
"reserve"
,
""
)
return
mc
.
Observe
(
gce
.
c
.
GlobalAddresses
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
addr
.
Name
),
addr
))
return
mc
.
Observe
(
gce
.
c
.
GlobalAddresses
()
.
Insert
(
c
tx
,
meta
.
GlobalKey
(
addr
.
Name
),
addr
))
}
}
// DeleteGlobalAddress deletes a global address by name.
// DeleteGlobalAddress deletes a global address by name.
func
(
gce
*
GCECloud
)
DeleteGlobalAddress
(
name
string
)
error
{
func
(
gce
*
GCECloud
)
DeleteGlobalAddress
(
name
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newAddressMetricContext
(
"delete"
,
""
)
mc
:=
newAddressMetricContext
(
"delete"
,
""
)
return
mc
.
Observe
(
gce
.
c
.
GlobalAddresses
()
.
Delete
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
)))
return
mc
.
Observe
(
gce
.
c
.
GlobalAddresses
()
.
Delete
(
c
tx
,
meta
.
GlobalKey
(
name
)))
}
}
// GetGlobalAddress returns the global address by name.
// GetGlobalAddress returns the global address by name.
func
(
gce
*
GCECloud
)
GetGlobalAddress
(
name
string
)
(
*
compute
.
Address
,
error
)
{
func
(
gce
*
GCECloud
)
GetGlobalAddress
(
name
string
)
(
*
compute
.
Address
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newAddressMetricContext
(
"get"
,
""
)
mc
:=
newAddressMetricContext
(
"get"
,
""
)
v
,
err
:=
gce
.
c
.
GlobalAddresses
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
))
v
,
err
:=
gce
.
c
.
GlobalAddresses
()
.
Get
(
c
tx
,
meta
.
GlobalKey
(
name
))
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// ReserveRegionAddress creates a region address
// ReserveRegionAddress creates a region address
func
(
gce
*
GCECloud
)
ReserveRegionAddress
(
addr
*
compute
.
Address
,
region
string
)
error
{
func
(
gce
*
GCECloud
)
ReserveRegionAddress
(
addr
*
compute
.
Address
,
region
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newAddressMetricContext
(
"reserve"
,
region
)
mc
:=
newAddressMetricContext
(
"reserve"
,
region
)
return
mc
.
Observe
(
gce
.
c
.
Addresses
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
RegionalKey
(
addr
.
Name
,
region
),
addr
))
return
mc
.
Observe
(
gce
.
c
.
Addresses
()
.
Insert
(
c
tx
,
meta
.
RegionalKey
(
addr
.
Name
,
region
),
addr
))
}
}
// ReserveAlphaRegionAddress creates an Alpha, regional address.
// ReserveAlphaRegionAddress creates an Alpha, regional address.
func
(
gce
*
GCECloud
)
ReserveAlphaRegionAddress
(
addr
*
computealpha
.
Address
,
region
string
)
error
{
func
(
gce
*
GCECloud
)
ReserveAlphaRegionAddress
(
addr
*
computealpha
.
Address
,
region
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newAddressMetricContext
(
"reserve"
,
region
)
mc
:=
newAddressMetricContext
(
"reserve"
,
region
)
return
mc
.
Observe
(
gce
.
c
.
AlphaAddresses
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
RegionalKey
(
addr
.
Name
,
region
),
addr
))
return
mc
.
Observe
(
gce
.
c
.
AlphaAddresses
()
.
Insert
(
c
tx
,
meta
.
RegionalKey
(
addr
.
Name
,
region
),
addr
))
}
}
// ReserveBetaRegionAddress creates a beta region address
// ReserveBetaRegionAddress creates a beta region address
func
(
gce
*
GCECloud
)
ReserveBetaRegionAddress
(
addr
*
computebeta
.
Address
,
region
string
)
error
{
func
(
gce
*
GCECloud
)
ReserveBetaRegionAddress
(
addr
*
computebeta
.
Address
,
region
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newAddressMetricContext
(
"reserve"
,
region
)
mc
:=
newAddressMetricContext
(
"reserve"
,
region
)
return
mc
.
Observe
(
gce
.
c
.
BetaAddresses
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
RegionalKey
(
addr
.
Name
,
region
),
addr
))
return
mc
.
Observe
(
gce
.
c
.
BetaAddresses
()
.
Insert
(
c
tx
,
meta
.
RegionalKey
(
addr
.
Name
,
region
),
addr
))
}
}
// DeleteRegionAddress deletes a region address by name.
// DeleteRegionAddress deletes a region address by name.
func
(
gce
*
GCECloud
)
DeleteRegionAddress
(
name
,
region
string
)
error
{
func
(
gce
*
GCECloud
)
DeleteRegionAddress
(
name
,
region
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newAddressMetricContext
(
"delete"
,
region
)
mc
:=
newAddressMetricContext
(
"delete"
,
region
)
return
mc
.
Observe
(
gce
.
c
.
Addresses
()
.
Delete
(
c
ontext
.
Background
()
,
meta
.
RegionalKey
(
name
,
region
)))
return
mc
.
Observe
(
gce
.
c
.
Addresses
()
.
Delete
(
c
tx
,
meta
.
RegionalKey
(
name
,
region
)))
}
}
// GetRegionAddress returns the region address by name
// GetRegionAddress returns the region address by name
func
(
gce
*
GCECloud
)
GetRegionAddress
(
name
,
region
string
)
(
*
compute
.
Address
,
error
)
{
func
(
gce
*
GCECloud
)
GetRegionAddress
(
name
,
region
string
)
(
*
compute
.
Address
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newAddressMetricContext
(
"get"
,
region
)
mc
:=
newAddressMetricContext
(
"get"
,
region
)
v
,
err
:=
gce
.
c
.
Addresses
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
RegionalKey
(
name
,
region
))
v
,
err
:=
gce
.
c
.
Addresses
()
.
Get
(
c
tx
,
meta
.
RegionalKey
(
name
,
region
))
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// GetAlphaRegionAddress returns the Alpha, regional address by name.
// GetAlphaRegionAddress returns the Alpha, regional address by name.
func
(
gce
*
GCECloud
)
GetAlphaRegionAddress
(
name
,
region
string
)
(
*
computealpha
.
Address
,
error
)
{
func
(
gce
*
GCECloud
)
GetAlphaRegionAddress
(
name
,
region
string
)
(
*
computealpha
.
Address
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newAddressMetricContext
(
"get"
,
region
)
mc
:=
newAddressMetricContext
(
"get"
,
region
)
v
,
err
:=
gce
.
c
.
AlphaAddresses
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
RegionalKey
(
name
,
region
))
v
,
err
:=
gce
.
c
.
AlphaAddresses
()
.
Get
(
c
tx
,
meta
.
RegionalKey
(
name
,
region
))
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// GetBetaRegionAddress returns the beta region address by name
// GetBetaRegionAddress returns the beta region address by name
func
(
gce
*
GCECloud
)
GetBetaRegionAddress
(
name
,
region
string
)
(
*
computebeta
.
Address
,
error
)
{
func
(
gce
*
GCECloud
)
GetBetaRegionAddress
(
name
,
region
string
)
(
*
computebeta
.
Address
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newAddressMetricContext
(
"get"
,
region
)
mc
:=
newAddressMetricContext
(
"get"
,
region
)
v
,
err
:=
gce
.
c
.
BetaAddresses
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
RegionalKey
(
name
,
region
))
v
,
err
:=
gce
.
c
.
BetaAddresses
()
.
Get
(
c
tx
,
meta
.
RegionalKey
(
name
,
region
))
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// GetRegionAddressByIP returns the regional address matching the given IP address.
// GetRegionAddressByIP returns the regional address matching the given IP address.
func
(
gce
*
GCECloud
)
GetRegionAddressByIP
(
region
,
ipAddress
string
)
(
*
compute
.
Address
,
error
)
{
func
(
gce
*
GCECloud
)
GetRegionAddressByIP
(
region
,
ipAddress
string
)
(
*
compute
.
Address
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newAddressMetricContext
(
"list"
,
region
)
mc
:=
newAddressMetricContext
(
"list"
,
region
)
addrs
,
err
:=
gce
.
c
.
Addresses
()
.
List
(
c
ontext
.
Background
()
,
region
,
filter
.
Regexp
(
"address"
,
ipAddress
))
addrs
,
err
:=
gce
.
c
.
Addresses
()
.
List
(
c
tx
,
region
,
filter
.
Regexp
(
"address"
,
ipAddress
))
mc
.
Observe
(
err
)
mc
.
Observe
(
err
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -129,8 +161,11 @@ func (gce *GCECloud) GetRegionAddressByIP(region, ipAddress string) (*compute.Ad
...
@@ -129,8 +161,11 @@ func (gce *GCECloud) GetRegionAddressByIP(region, ipAddress string) (*compute.Ad
// GetBetaRegionAddressByIP returns the beta regional address matching the given IP address.
// GetBetaRegionAddressByIP returns the beta regional address matching the given IP address.
func
(
gce
*
GCECloud
)
GetBetaRegionAddressByIP
(
region
,
ipAddress
string
)
(
*
computebeta
.
Address
,
error
)
{
func
(
gce
*
GCECloud
)
GetBetaRegionAddressByIP
(
region
,
ipAddress
string
)
(
*
computebeta
.
Address
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newAddressMetricContext
(
"list"
,
region
)
mc
:=
newAddressMetricContext
(
"list"
,
region
)
addrs
,
err
:=
gce
.
c
.
BetaAddresses
()
.
List
(
c
ontext
.
Background
()
,
region
,
filter
.
Regexp
(
"address"
,
ipAddress
))
addrs
,
err
:=
gce
.
c
.
BetaAddresses
()
.
List
(
c
tx
,
region
,
filter
.
Regexp
(
"address"
,
ipAddress
))
mc
.
Observe
(
err
)
mc
.
Observe
(
err
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/cloudprovider/providers/gce/gce_backendservice.go
View file @
1f336dda
...
@@ -17,11 +17,10 @@ limitations under the License.
...
@@ -17,11 +17,10 @@ limitations under the License.
package
gce
package
gce
import
(
import
(
"context"
computealpha
"google.golang.org/api/compute/v0.alpha"
computealpha
"google.golang.org/api/compute/v0.alpha"
compute
"google.golang.org/api/compute/v1"
compute
"google.golang.org/api/compute/v1"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
)
)
...
@@ -36,54 +35,78 @@ func newBackendServiceMetricContextWithVersion(request, region, version string)
...
@@ -36,54 +35,78 @@ func newBackendServiceMetricContextWithVersion(request, region, version string)
// GetGlobalBackendService retrieves a backend by name.
// GetGlobalBackendService retrieves a backend by name.
func
(
gce
*
GCECloud
)
GetGlobalBackendService
(
name
string
)
(
*
compute
.
BackendService
,
error
)
{
func
(
gce
*
GCECloud
)
GetGlobalBackendService
(
name
string
)
(
*
compute
.
BackendService
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newBackendServiceMetricContext
(
"get"
,
""
)
mc
:=
newBackendServiceMetricContext
(
"get"
,
""
)
v
,
err
:=
gce
.
c
.
BackendServices
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
))
v
,
err
:=
gce
.
c
.
BackendServices
()
.
Get
(
c
tx
,
meta
.
GlobalKey
(
name
))
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// GetAlphaGlobalBackendService retrieves alpha backend by name.
// GetAlphaGlobalBackendService retrieves alpha backend by name.
func
(
gce
*
GCECloud
)
GetAlphaGlobalBackendService
(
name
string
)
(
*
computealpha
.
BackendService
,
error
)
{
func
(
gce
*
GCECloud
)
GetAlphaGlobalBackendService
(
name
string
)
(
*
computealpha
.
BackendService
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newBackendServiceMetricContextWithVersion
(
"get"
,
""
,
computeAlphaVersion
)
mc
:=
newBackendServiceMetricContextWithVersion
(
"get"
,
""
,
computeAlphaVersion
)
v
,
err
:=
gce
.
c
.
AlphaBackendServices
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
))
v
,
err
:=
gce
.
c
.
AlphaBackendServices
()
.
Get
(
c
tx
,
meta
.
GlobalKey
(
name
))
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// UpdateGlobalBackendService applies the given BackendService as an update to
// UpdateGlobalBackendService applies the given BackendService as an update to
// an existing service.
// an existing service.
func
(
gce
*
GCECloud
)
UpdateGlobalBackendService
(
bg
*
compute
.
BackendService
)
error
{
func
(
gce
*
GCECloud
)
UpdateGlobalBackendService
(
bg
*
compute
.
BackendService
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newBackendServiceMetricContext
(
"update"
,
""
)
mc
:=
newBackendServiceMetricContext
(
"update"
,
""
)
return
mc
.
Observe
(
gce
.
c
.
BackendServices
()
.
Update
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
bg
.
Name
),
bg
))
return
mc
.
Observe
(
gce
.
c
.
BackendServices
()
.
Update
(
c
tx
,
meta
.
GlobalKey
(
bg
.
Name
),
bg
))
}
}
// UpdateAlphaGlobalBackendService applies the given alpha BackendService as an
// UpdateAlphaGlobalBackendService applies the given alpha BackendService as an
// update to an existing service.
// update to an existing service.
func
(
gce
*
GCECloud
)
UpdateAlphaGlobalBackendService
(
bg
*
computealpha
.
BackendService
)
error
{
func
(
gce
*
GCECloud
)
UpdateAlphaGlobalBackendService
(
bg
*
computealpha
.
BackendService
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newBackendServiceMetricContext
(
"update"
,
""
)
mc
:=
newBackendServiceMetricContext
(
"update"
,
""
)
return
mc
.
Observe
(
gce
.
c
.
AlphaBackendServices
()
.
Update
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
bg
.
Name
),
bg
))
return
mc
.
Observe
(
gce
.
c
.
AlphaBackendServices
()
.
Update
(
c
tx
,
meta
.
GlobalKey
(
bg
.
Name
),
bg
))
}
}
// DeleteGlobalBackendService deletes the given BackendService by name.
// DeleteGlobalBackendService deletes the given BackendService by name.
func
(
gce
*
GCECloud
)
DeleteGlobalBackendService
(
name
string
)
error
{
func
(
gce
*
GCECloud
)
DeleteGlobalBackendService
(
name
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newBackendServiceMetricContext
(
"delete"
,
""
)
mc
:=
newBackendServiceMetricContext
(
"delete"
,
""
)
return
mc
.
Observe
(
gce
.
c
.
BackendServices
()
.
Delete
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
)))
return
mc
.
Observe
(
gce
.
c
.
BackendServices
()
.
Delete
(
c
tx
,
meta
.
GlobalKey
(
name
)))
}
}
// CreateGlobalBackendService creates the given BackendService.
// CreateGlobalBackendService creates the given BackendService.
func
(
gce
*
GCECloud
)
CreateGlobalBackendService
(
bg
*
compute
.
BackendService
)
error
{
func
(
gce
*
GCECloud
)
CreateGlobalBackendService
(
bg
*
compute
.
BackendService
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newBackendServiceMetricContext
(
"create"
,
""
)
mc
:=
newBackendServiceMetricContext
(
"create"
,
""
)
return
mc
.
Observe
(
gce
.
c
.
BackendServices
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
bg
.
Name
),
bg
))
return
mc
.
Observe
(
gce
.
c
.
BackendServices
()
.
Insert
(
c
tx
,
meta
.
GlobalKey
(
bg
.
Name
),
bg
))
}
}
// CreateAlphaGlobalBackendService creates the given alpha BackendService.
// CreateAlphaGlobalBackendService creates the given alpha BackendService.
func
(
gce
*
GCECloud
)
CreateAlphaGlobalBackendService
(
bg
*
computealpha
.
BackendService
)
error
{
func
(
gce
*
GCECloud
)
CreateAlphaGlobalBackendService
(
bg
*
computealpha
.
BackendService
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newBackendServiceMetricContext
(
"create"
,
""
)
mc
:=
newBackendServiceMetricContext
(
"create"
,
""
)
return
mc
.
Observe
(
gce
.
c
.
AlphaBackendServices
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
bg
.
Name
),
bg
))
return
mc
.
Observe
(
gce
.
c
.
AlphaBackendServices
()
.
Insert
(
c
tx
,
meta
.
GlobalKey
(
bg
.
Name
),
bg
))
}
}
// ListGlobalBackendServices lists all backend services in the project.
// ListGlobalBackendServices lists all backend services in the project.
func
(
gce
*
GCECloud
)
ListGlobalBackendServices
()
([]
*
compute
.
BackendService
,
error
)
{
func
(
gce
*
GCECloud
)
ListGlobalBackendServices
()
([]
*
compute
.
BackendService
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newBackendServiceMetricContext
(
"list"
,
""
)
mc
:=
newBackendServiceMetricContext
(
"list"
,
""
)
v
,
err
:=
gce
.
c
.
BackendServices
()
.
List
(
c
ontext
.
Background
()
,
filter
.
None
)
v
,
err
:=
gce
.
c
.
BackendServices
()
.
List
(
c
tx
,
filter
.
None
)
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
...
@@ -91,42 +114,60 @@ func (gce *GCECloud) ListGlobalBackendServices() ([]*compute.BackendService, err
...
@@ -91,42 +114,60 @@ func (gce *GCECloud) ListGlobalBackendServices() ([]*compute.BackendService, err
// identified by the given name, in the given instanceGroup. The
// identified by the given name, in the given instanceGroup. The
// instanceGroupLink is the fully qualified self link of an instance group.
// instanceGroupLink is the fully qualified self link of an instance group.
func
(
gce
*
GCECloud
)
GetGlobalBackendServiceHealth
(
name
string
,
instanceGroupLink
string
)
(
*
compute
.
BackendServiceGroupHealth
,
error
)
{
func
(
gce
*
GCECloud
)
GetGlobalBackendServiceHealth
(
name
string
,
instanceGroupLink
string
)
(
*
compute
.
BackendServiceGroupHealth
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newBackendServiceMetricContext
(
"get_health"
,
""
)
mc
:=
newBackendServiceMetricContext
(
"get_health"
,
""
)
groupRef
:=
&
compute
.
ResourceGroupReference
{
Group
:
instanceGroupLink
}
groupRef
:=
&
compute
.
ResourceGroupReference
{
Group
:
instanceGroupLink
}
v
,
err
:=
gce
.
c
.
BackendServices
()
.
GetHealth
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
),
groupRef
)
v
,
err
:=
gce
.
c
.
BackendServices
()
.
GetHealth
(
c
tx
,
meta
.
GlobalKey
(
name
),
groupRef
)
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// GetRegionBackendService retrieves a backend by name.
// GetRegionBackendService retrieves a backend by name.
func
(
gce
*
GCECloud
)
GetRegionBackendService
(
name
,
region
string
)
(
*
compute
.
BackendService
,
error
)
{
func
(
gce
*
GCECloud
)
GetRegionBackendService
(
name
,
region
string
)
(
*
compute
.
BackendService
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newBackendServiceMetricContext
(
"get"
,
region
)
mc
:=
newBackendServiceMetricContext
(
"get"
,
region
)
v
,
err
:=
gce
.
c
.
RegionBackendServices
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
RegionalKey
(
name
,
region
))
v
,
err
:=
gce
.
c
.
RegionBackendServices
()
.
Get
(
c
tx
,
meta
.
RegionalKey
(
name
,
region
))
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// UpdateRegionBackendService applies the given BackendService as an update to
// UpdateRegionBackendService applies the given BackendService as an update to
// an existing service.
// an existing service.
func
(
gce
*
GCECloud
)
UpdateRegionBackendService
(
bg
*
compute
.
BackendService
,
region
string
)
error
{
func
(
gce
*
GCECloud
)
UpdateRegionBackendService
(
bg
*
compute
.
BackendService
,
region
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newBackendServiceMetricContext
(
"update"
,
region
)
mc
:=
newBackendServiceMetricContext
(
"update"
,
region
)
return
mc
.
Observe
(
gce
.
c
.
RegionBackendServices
()
.
Update
(
c
ontext
.
Background
()
,
meta
.
RegionalKey
(
bg
.
Name
,
region
),
bg
))
return
mc
.
Observe
(
gce
.
c
.
RegionBackendServices
()
.
Update
(
c
tx
,
meta
.
RegionalKey
(
bg
.
Name
,
region
),
bg
))
}
}
// DeleteRegionBackendService deletes the given BackendService by name.
// DeleteRegionBackendService deletes the given BackendService by name.
func
(
gce
*
GCECloud
)
DeleteRegionBackendService
(
name
,
region
string
)
error
{
func
(
gce
*
GCECloud
)
DeleteRegionBackendService
(
name
,
region
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newBackendServiceMetricContext
(
"delete"
,
region
)
mc
:=
newBackendServiceMetricContext
(
"delete"
,
region
)
return
mc
.
Observe
(
gce
.
c
.
RegionBackendServices
()
.
Delete
(
c
ontext
.
Background
()
,
meta
.
RegionalKey
(
name
,
region
)))
return
mc
.
Observe
(
gce
.
c
.
RegionBackendServices
()
.
Delete
(
c
tx
,
meta
.
RegionalKey
(
name
,
region
)))
}
}
// CreateRegionBackendService creates the given BackendService.
// CreateRegionBackendService creates the given BackendService.
func
(
gce
*
GCECloud
)
CreateRegionBackendService
(
bg
*
compute
.
BackendService
,
region
string
)
error
{
func
(
gce
*
GCECloud
)
CreateRegionBackendService
(
bg
*
compute
.
BackendService
,
region
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newBackendServiceMetricContext
(
"create"
,
region
)
mc
:=
newBackendServiceMetricContext
(
"create"
,
region
)
return
mc
.
Observe
(
gce
.
c
.
RegionBackendServices
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
RegionalKey
(
bg
.
Name
,
region
),
bg
))
return
mc
.
Observe
(
gce
.
c
.
RegionBackendServices
()
.
Insert
(
c
tx
,
meta
.
RegionalKey
(
bg
.
Name
,
region
),
bg
))
}
}
// ListRegionBackendServices lists all backend services in the project.
// ListRegionBackendServices lists all backend services in the project.
func
(
gce
*
GCECloud
)
ListRegionBackendServices
(
region
string
)
([]
*
compute
.
BackendService
,
error
)
{
func
(
gce
*
GCECloud
)
ListRegionBackendServices
(
region
string
)
([]
*
compute
.
BackendService
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newBackendServiceMetricContext
(
"list"
,
region
)
mc
:=
newBackendServiceMetricContext
(
"list"
,
region
)
v
,
err
:=
gce
.
c
.
RegionBackendServices
()
.
List
(
c
ontext
.
Background
()
,
region
,
filter
.
None
)
v
,
err
:=
gce
.
c
.
RegionBackendServices
()
.
List
(
c
tx
,
region
,
filter
.
None
)
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
...
@@ -134,8 +175,11 @@ func (gce *GCECloud) ListRegionBackendServices(region string) ([]*compute.Backen
...
@@ -134,8 +175,11 @@ func (gce *GCECloud) ListRegionBackendServices(region string) ([]*compute.Backen
// identified by the given name, in the given instanceGroup. The
// identified by the given name, in the given instanceGroup. The
// instanceGroupLink is the fully qualified self link of an instance group.
// instanceGroupLink is the fully qualified self link of an instance group.
func
(
gce
*
GCECloud
)
GetRegionalBackendServiceHealth
(
name
,
region
string
,
instanceGroupLink
string
)
(
*
compute
.
BackendServiceGroupHealth
,
error
)
{
func
(
gce
*
GCECloud
)
GetRegionalBackendServiceHealth
(
name
,
region
string
,
instanceGroupLink
string
)
(
*
compute
.
BackendServiceGroupHealth
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newBackendServiceMetricContext
(
"get_health"
,
region
)
mc
:=
newBackendServiceMetricContext
(
"get_health"
,
region
)
ref
:=
&
compute
.
ResourceGroupReference
{
Group
:
instanceGroupLink
}
ref
:=
&
compute
.
ResourceGroupReference
{
Group
:
instanceGroupLink
}
v
,
err
:=
gce
.
c
.
RegionBackendServices
()
.
GetHealth
(
c
ontext
.
Background
()
,
meta
.
RegionalKey
(
name
,
region
),
ref
)
v
,
err
:=
gce
.
c
.
RegionBackendServices
()
.
GetHealth
(
c
tx
,
meta
.
RegionalKey
(
name
,
region
),
ref
)
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
pkg/cloudprovider/providers/gce/gce_cert.go
View file @
1f336dda
...
@@ -17,10 +17,9 @@ limitations under the License.
...
@@ -17,10 +17,9 @@ limitations under the License.
package
gce
package
gce
import
(
import
(
"context"
compute
"google.golang.org/api/compute/v1"
compute
"google.golang.org/api/compute/v1"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
)
)
...
@@ -31,15 +30,21 @@ func newCertMetricContext(request string) *metricContext {
...
@@ -31,15 +30,21 @@ func newCertMetricContext(request string) *metricContext {
// GetSslCertificate returns the SslCertificate by name.
// GetSslCertificate returns the SslCertificate by name.
func
(
gce
*
GCECloud
)
GetSslCertificate
(
name
string
)
(
*
compute
.
SslCertificate
,
error
)
{
func
(
gce
*
GCECloud
)
GetSslCertificate
(
name
string
)
(
*
compute
.
SslCertificate
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newCertMetricContext
(
"get"
)
mc
:=
newCertMetricContext
(
"get"
)
v
,
err
:=
gce
.
c
.
SslCertificates
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
))
v
,
err
:=
gce
.
c
.
SslCertificates
()
.
Get
(
c
tx
,
meta
.
GlobalKey
(
name
))
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// CreateSslCertificate creates and returns a SslCertificate.
// CreateSslCertificate creates and returns a SslCertificate.
func
(
gce
*
GCECloud
)
CreateSslCertificate
(
sslCerts
*
compute
.
SslCertificate
)
(
*
compute
.
SslCertificate
,
error
)
{
func
(
gce
*
GCECloud
)
CreateSslCertificate
(
sslCerts
*
compute
.
SslCertificate
)
(
*
compute
.
SslCertificate
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newCertMetricContext
(
"create"
)
mc
:=
newCertMetricContext
(
"create"
)
err
:=
gce
.
c
.
SslCertificates
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
sslCerts
.
Name
),
sslCerts
)
err
:=
gce
.
c
.
SslCertificates
()
.
Insert
(
c
tx
,
meta
.
GlobalKey
(
sslCerts
.
Name
),
sslCerts
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
mc
.
Observe
(
err
)
return
nil
,
mc
.
Observe
(
err
)
}
}
...
@@ -48,13 +53,19 @@ func (gce *GCECloud) CreateSslCertificate(sslCerts *compute.SslCertificate) (*co
...
@@ -48,13 +53,19 @@ func (gce *GCECloud) CreateSslCertificate(sslCerts *compute.SslCertificate) (*co
// DeleteSslCertificate deletes the SslCertificate by name.
// DeleteSslCertificate deletes the SslCertificate by name.
func
(
gce
*
GCECloud
)
DeleteSslCertificate
(
name
string
)
error
{
func
(
gce
*
GCECloud
)
DeleteSslCertificate
(
name
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newCertMetricContext
(
"delete"
)
mc
:=
newCertMetricContext
(
"delete"
)
return
mc
.
Observe
(
gce
.
c
.
SslCertificates
()
.
Delete
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
)))
return
mc
.
Observe
(
gce
.
c
.
SslCertificates
()
.
Delete
(
c
tx
,
meta
.
GlobalKey
(
name
)))
}
}
// ListSslCertificates lists all SslCertificates in the project.
// ListSslCertificates lists all SslCertificates in the project.
func
(
gce
*
GCECloud
)
ListSslCertificates
()
([]
*
compute
.
SslCertificate
,
error
)
{
func
(
gce
*
GCECloud
)
ListSslCertificates
()
([]
*
compute
.
SslCertificate
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newCertMetricContext
(
"list"
)
mc
:=
newCertMetricContext
(
"list"
)
v
,
err
:=
gce
.
c
.
SslCertificates
()
.
List
(
c
ontext
.
Background
()
,
filter
.
None
)
v
,
err
:=
gce
.
c
.
SslCertificates
()
.
List
(
c
tx
,
filter
.
None
)
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
pkg/cloudprovider/providers/gce/gce_firewall.go
View file @
1f336dda
...
@@ -17,10 +17,9 @@ limitations under the License.
...
@@ -17,10 +17,9 @@ limitations under the License.
package
gce
package
gce
import
(
import
(
"context"
compute
"google.golang.org/api/compute/v1"
compute
"google.golang.org/api/compute/v1"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
)
)
...
@@ -30,25 +29,37 @@ func newFirewallMetricContext(request string) *metricContext {
...
@@ -30,25 +29,37 @@ func newFirewallMetricContext(request string) *metricContext {
// GetFirewall returns the Firewall by name.
// GetFirewall returns the Firewall by name.
func
(
gce
*
GCECloud
)
GetFirewall
(
name
string
)
(
*
compute
.
Firewall
,
error
)
{
func
(
gce
*
GCECloud
)
GetFirewall
(
name
string
)
(
*
compute
.
Firewall
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newFirewallMetricContext
(
"get"
)
mc
:=
newFirewallMetricContext
(
"get"
)
v
,
err
:=
gce
.
c
.
Firewalls
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
))
v
,
err
:=
gce
.
c
.
Firewalls
()
.
Get
(
c
tx
,
meta
.
GlobalKey
(
name
))
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// CreateFirewall creates the passed firewall
// CreateFirewall creates the passed firewall
func
(
gce
*
GCECloud
)
CreateFirewall
(
f
*
compute
.
Firewall
)
error
{
func
(
gce
*
GCECloud
)
CreateFirewall
(
f
*
compute
.
Firewall
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newFirewallMetricContext
(
"create"
)
mc
:=
newFirewallMetricContext
(
"create"
)
return
mc
.
Observe
(
gce
.
c
.
Firewalls
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
f
.
Name
),
f
))
return
mc
.
Observe
(
gce
.
c
.
Firewalls
()
.
Insert
(
c
tx
,
meta
.
GlobalKey
(
f
.
Name
),
f
))
}
}
// DeleteFirewall deletes the given firewall rule.
// DeleteFirewall deletes the given firewall rule.
func
(
gce
*
GCECloud
)
DeleteFirewall
(
name
string
)
error
{
func
(
gce
*
GCECloud
)
DeleteFirewall
(
name
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newFirewallMetricContext
(
"delete"
)
mc
:=
newFirewallMetricContext
(
"delete"
)
return
mc
.
Observe
(
gce
.
c
.
Firewalls
()
.
Delete
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
)))
return
mc
.
Observe
(
gce
.
c
.
Firewalls
()
.
Delete
(
c
tx
,
meta
.
GlobalKey
(
name
)))
}
}
// UpdateFirewall applies the given firewall as an update to an existing service.
// UpdateFirewall applies the given firewall as an update to an existing service.
func
(
gce
*
GCECloud
)
UpdateFirewall
(
f
*
compute
.
Firewall
)
error
{
func
(
gce
*
GCECloud
)
UpdateFirewall
(
f
*
compute
.
Firewall
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newFirewallMetricContext
(
"update"
)
mc
:=
newFirewallMetricContext
(
"update"
)
return
mc
.
Observe
(
gce
.
c
.
Firewalls
()
.
Update
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
f
.
Name
),
f
))
return
mc
.
Observe
(
gce
.
c
.
Firewalls
()
.
Update
(
c
tx
,
meta
.
GlobalKey
(
f
.
Name
),
f
))
}
}
pkg/cloudprovider/providers/gce/gce_forwardingrule.go
View file @
1f336dda
...
@@ -17,8 +17,6 @@ limitations under the License.
...
@@ -17,8 +17,6 @@ limitations under the License.
package
gce
package
gce
import
(
import
(
"context"
computealpha
"google.golang.org/api/compute/v0.alpha"
computealpha
"google.golang.org/api/compute/v0.alpha"
compute
"google.golang.org/api/compute/v1"
compute
"google.golang.org/api/compute/v1"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud"
...
@@ -35,84 +33,120 @@ func newForwardingRuleMetricContextWithVersion(request, region, version string)
...
@@ -35,84 +33,120 @@ func newForwardingRuleMetricContextWithVersion(request, region, version string)
// CreateGlobalForwardingRule creates the passed GlobalForwardingRule
// CreateGlobalForwardingRule creates the passed GlobalForwardingRule
func
(
gce
*
GCECloud
)
CreateGlobalForwardingRule
(
rule
*
compute
.
ForwardingRule
)
error
{
func
(
gce
*
GCECloud
)
CreateGlobalForwardingRule
(
rule
*
compute
.
ForwardingRule
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newForwardingRuleMetricContext
(
"create"
,
""
)
mc
:=
newForwardingRuleMetricContext
(
"create"
,
""
)
return
mc
.
Observe
(
gce
.
c
.
GlobalForwardingRules
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
rule
.
Name
),
rule
))
return
mc
.
Observe
(
gce
.
c
.
GlobalForwardingRules
()
.
Insert
(
c
tx
,
meta
.
GlobalKey
(
rule
.
Name
),
rule
))
}
}
// SetProxyForGlobalForwardingRule links the given TargetHttp(s)Proxy with the given GlobalForwardingRule.
// SetProxyForGlobalForwardingRule links the given TargetHttp(s)Proxy with the given GlobalForwardingRule.
// targetProxyLink is the SelfLink of a TargetHttp(s)Proxy.
// targetProxyLink is the SelfLink of a TargetHttp(s)Proxy.
func
(
gce
*
GCECloud
)
SetProxyForGlobalForwardingRule
(
forwardingRuleName
,
targetProxyLink
string
)
error
{
func
(
gce
*
GCECloud
)
SetProxyForGlobalForwardingRule
(
forwardingRuleName
,
targetProxyLink
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newForwardingRuleMetricContext
(
"set_proxy"
,
""
)
mc
:=
newForwardingRuleMetricContext
(
"set_proxy"
,
""
)
target
:=
&
compute
.
TargetReference
{
Target
:
targetProxyLink
}
target
:=
&
compute
.
TargetReference
{
Target
:
targetProxyLink
}
return
mc
.
Observe
(
gce
.
c
.
GlobalForwardingRules
()
.
SetTarget
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
forwardingRuleName
),
target
))
return
mc
.
Observe
(
gce
.
c
.
GlobalForwardingRules
()
.
SetTarget
(
c
tx
,
meta
.
GlobalKey
(
forwardingRuleName
),
target
))
}
}
// DeleteGlobalForwardingRule deletes the GlobalForwardingRule by name.
// DeleteGlobalForwardingRule deletes the GlobalForwardingRule by name.
func
(
gce
*
GCECloud
)
DeleteGlobalForwardingRule
(
name
string
)
error
{
func
(
gce
*
GCECloud
)
DeleteGlobalForwardingRule
(
name
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newForwardingRuleMetricContext
(
"delete"
,
""
)
mc
:=
newForwardingRuleMetricContext
(
"delete"
,
""
)
return
mc
.
Observe
(
gce
.
c
.
GlobalForwardingRules
()
.
Delete
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
)))
return
mc
.
Observe
(
gce
.
c
.
GlobalForwardingRules
()
.
Delete
(
c
tx
,
meta
.
GlobalKey
(
name
)))
}
}
// GetGlobalForwardingRule returns the GlobalForwardingRule by name.
// GetGlobalForwardingRule returns the GlobalForwardingRule by name.
func
(
gce
*
GCECloud
)
GetGlobalForwardingRule
(
name
string
)
(
*
compute
.
ForwardingRule
,
error
)
{
func
(
gce
*
GCECloud
)
GetGlobalForwardingRule
(
name
string
)
(
*
compute
.
ForwardingRule
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newForwardingRuleMetricContext
(
"get"
,
""
)
mc
:=
newForwardingRuleMetricContext
(
"get"
,
""
)
v
,
err
:=
gce
.
c
.
GlobalForwardingRules
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
))
v
,
err
:=
gce
.
c
.
GlobalForwardingRules
()
.
Get
(
c
tx
,
meta
.
GlobalKey
(
name
))
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// ListGlobalForwardingRules lists all GlobalForwardingRules in the project.
// ListGlobalForwardingRules lists all GlobalForwardingRules in the project.
func
(
gce
*
GCECloud
)
ListGlobalForwardingRules
()
([]
*
compute
.
ForwardingRule
,
error
)
{
func
(
gce
*
GCECloud
)
ListGlobalForwardingRules
()
([]
*
compute
.
ForwardingRule
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newForwardingRuleMetricContext
(
"list"
,
""
)
mc
:=
newForwardingRuleMetricContext
(
"list"
,
""
)
v
,
err
:=
gce
.
c
.
GlobalForwardingRules
()
.
List
(
c
ontext
.
Background
()
,
filter
.
None
)
v
,
err
:=
gce
.
c
.
GlobalForwardingRules
()
.
List
(
c
tx
,
filter
.
None
)
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// GetRegionForwardingRule returns the RegionalForwardingRule by name & region.
// GetRegionForwardingRule returns the RegionalForwardingRule by name & region.
func
(
gce
*
GCECloud
)
GetRegionForwardingRule
(
name
,
region
string
)
(
*
compute
.
ForwardingRule
,
error
)
{
func
(
gce
*
GCECloud
)
GetRegionForwardingRule
(
name
,
region
string
)
(
*
compute
.
ForwardingRule
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newForwardingRuleMetricContext
(
"get"
,
region
)
mc
:=
newForwardingRuleMetricContext
(
"get"
,
region
)
v
,
err
:=
gce
.
c
.
ForwardingRules
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
RegionalKey
(
name
,
region
))
v
,
err
:=
gce
.
c
.
ForwardingRules
()
.
Get
(
c
tx
,
meta
.
RegionalKey
(
name
,
region
))
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// GetAlphaRegionForwardingRule returns the Alpha forwarding rule by name & region.
// GetAlphaRegionForwardingRule returns the Alpha forwarding rule by name & region.
func
(
gce
*
GCECloud
)
GetAlphaRegionForwardingRule
(
name
,
region
string
)
(
*
computealpha
.
ForwardingRule
,
error
)
{
func
(
gce
*
GCECloud
)
GetAlphaRegionForwardingRule
(
name
,
region
string
)
(
*
computealpha
.
ForwardingRule
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newForwardingRuleMetricContextWithVersion
(
"get"
,
region
,
computeAlphaVersion
)
mc
:=
newForwardingRuleMetricContextWithVersion
(
"get"
,
region
,
computeAlphaVersion
)
v
,
err
:=
gce
.
c
.
AlphaForwardingRules
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
RegionalKey
(
name
,
region
))
v
,
err
:=
gce
.
c
.
AlphaForwardingRules
()
.
Get
(
c
tx
,
meta
.
RegionalKey
(
name
,
region
))
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// ListRegionForwardingRules lists all RegionalForwardingRules in the project & region.
// ListRegionForwardingRules lists all RegionalForwardingRules in the project & region.
func
(
gce
*
GCECloud
)
ListRegionForwardingRules
(
region
string
)
([]
*
compute
.
ForwardingRule
,
error
)
{
func
(
gce
*
GCECloud
)
ListRegionForwardingRules
(
region
string
)
([]
*
compute
.
ForwardingRule
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newForwardingRuleMetricContext
(
"list"
,
region
)
mc
:=
newForwardingRuleMetricContext
(
"list"
,
region
)
v
,
err
:=
gce
.
c
.
ForwardingRules
()
.
List
(
c
ontext
.
Background
()
,
region
,
filter
.
None
)
v
,
err
:=
gce
.
c
.
ForwardingRules
()
.
List
(
c
tx
,
region
,
filter
.
None
)
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// ListAlphaRegionForwardingRules lists all RegionalForwardingRules in the project & region.
// ListAlphaRegionForwardingRules lists all RegionalForwardingRules in the project & region.
func
(
gce
*
GCECloud
)
ListAlphaRegionForwardingRules
(
region
string
)
([]
*
computealpha
.
ForwardingRule
,
error
)
{
func
(
gce
*
GCECloud
)
ListAlphaRegionForwardingRules
(
region
string
)
([]
*
computealpha
.
ForwardingRule
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newForwardingRuleMetricContextWithVersion
(
"list"
,
region
,
computeAlphaVersion
)
mc
:=
newForwardingRuleMetricContextWithVersion
(
"list"
,
region
,
computeAlphaVersion
)
v
,
err
:=
gce
.
c
.
AlphaForwardingRules
()
.
List
(
c
ontext
.
Background
()
,
region
,
filter
.
None
)
v
,
err
:=
gce
.
c
.
AlphaForwardingRules
()
.
List
(
c
tx
,
region
,
filter
.
None
)
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// CreateRegionForwardingRule creates and returns a
// CreateRegionForwardingRule creates and returns a
// RegionalForwardingRule that points to the given BackendService
// RegionalForwardingRule that points to the given BackendService
func
(
gce
*
GCECloud
)
CreateRegionForwardingRule
(
rule
*
compute
.
ForwardingRule
,
region
string
)
error
{
func
(
gce
*
GCECloud
)
CreateRegionForwardingRule
(
rule
*
compute
.
ForwardingRule
,
region
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newForwardingRuleMetricContext
(
"create"
,
region
)
mc
:=
newForwardingRuleMetricContext
(
"create"
,
region
)
return
mc
.
Observe
(
gce
.
c
.
ForwardingRules
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
RegionalKey
(
rule
.
Name
,
region
),
rule
))
return
mc
.
Observe
(
gce
.
c
.
ForwardingRules
()
.
Insert
(
c
tx
,
meta
.
RegionalKey
(
rule
.
Name
,
region
),
rule
))
}
}
// CreateAlphaRegionForwardingRule creates and returns an Alpha
// CreateAlphaRegionForwardingRule creates and returns an Alpha
// forwarding fule in the given region.
// forwarding fule in the given region.
func
(
gce
*
GCECloud
)
CreateAlphaRegionForwardingRule
(
rule
*
computealpha
.
ForwardingRule
,
region
string
)
error
{
func
(
gce
*
GCECloud
)
CreateAlphaRegionForwardingRule
(
rule
*
computealpha
.
ForwardingRule
,
region
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newForwardingRuleMetricContextWithVersion
(
"create"
,
region
,
computeAlphaVersion
)
mc
:=
newForwardingRuleMetricContextWithVersion
(
"create"
,
region
,
computeAlphaVersion
)
return
mc
.
Observe
(
gce
.
c
.
AlphaForwardingRules
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
RegionalKey
(
rule
.
Name
,
region
),
rule
))
return
mc
.
Observe
(
gce
.
c
.
AlphaForwardingRules
()
.
Insert
(
c
tx
,
meta
.
RegionalKey
(
rule
.
Name
,
region
),
rule
))
}
}
// DeleteRegionForwardingRule deletes the RegionalForwardingRule by name & region.
// DeleteRegionForwardingRule deletes the RegionalForwardingRule by name & region.
func
(
gce
*
GCECloud
)
DeleteRegionForwardingRule
(
name
,
region
string
)
error
{
func
(
gce
*
GCECloud
)
DeleteRegionForwardingRule
(
name
,
region
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newForwardingRuleMetricContext
(
"delete"
,
region
)
mc
:=
newForwardingRuleMetricContext
(
"delete"
,
region
)
return
mc
.
Observe
(
gce
.
c
.
ForwardingRules
()
.
Delete
(
c
ontext
.
Background
()
,
meta
.
RegionalKey
(
name
,
region
)))
return
mc
.
Observe
(
gce
.
c
.
ForwardingRules
()
.
Delete
(
c
tx
,
meta
.
RegionalKey
(
name
,
region
)))
}
}
// TODO(#51665): retire this function once Network Tiers becomes Beta in GCP.
// TODO(#51665): retire this function once Network Tiers becomes Beta in GCP.
...
...
pkg/cloudprovider/providers/gce/gce_healthchecks.go
View file @
1f336dda
...
@@ -17,14 +17,13 @@ limitations under the License.
...
@@ -17,14 +17,13 @@ limitations under the License.
package
gce
package
gce
import
(
import
(
"context"
"github.com/golang/glog"
"github.com/golang/glog"
computealpha
"google.golang.org/api/compute/v0.alpha"
computealpha
"google.golang.org/api/compute/v0.alpha"
compute
"google.golang.org/api/compute/v1"
compute
"google.golang.org/api/compute/v1"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
"k8s.io/kubernetes/pkg/master/ports"
"k8s.io/kubernetes/pkg/master/ports"
...
@@ -58,33 +57,48 @@ func newHealthcheckMetricContextWithVersion(request, version string) *metricCont
...
@@ -58,33 +57,48 @@ func newHealthcheckMetricContextWithVersion(request, version string) *metricCont
// GetHttpHealthCheck returns the given HttpHealthCheck by name.
// GetHttpHealthCheck returns the given HttpHealthCheck by name.
func
(
gce
*
GCECloud
)
GetHttpHealthCheck
(
name
string
)
(
*
compute
.
HttpHealthCheck
,
error
)
{
func
(
gce
*
GCECloud
)
GetHttpHealthCheck
(
name
string
)
(
*
compute
.
HttpHealthCheck
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newHealthcheckMetricContext
(
"get_legacy"
)
mc
:=
newHealthcheckMetricContext
(
"get_legacy"
)
v
,
err
:=
gce
.
c
.
HttpHealthChecks
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
))
v
,
err
:=
gce
.
c
.
HttpHealthChecks
()
.
Get
(
c
tx
,
meta
.
GlobalKey
(
name
))
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// UpdateHttpHealthCheck applies the given HttpHealthCheck as an update.
// UpdateHttpHealthCheck applies the given HttpHealthCheck as an update.
func
(
gce
*
GCECloud
)
UpdateHttpHealthCheck
(
hc
*
compute
.
HttpHealthCheck
)
error
{
func
(
gce
*
GCECloud
)
UpdateHttpHealthCheck
(
hc
*
compute
.
HttpHealthCheck
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newHealthcheckMetricContext
(
"update_legacy"
)
mc
:=
newHealthcheckMetricContext
(
"update_legacy"
)
return
mc
.
Observe
(
gce
.
c
.
HttpHealthChecks
()
.
Update
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
hc
.
Name
),
hc
))
return
mc
.
Observe
(
gce
.
c
.
HttpHealthChecks
()
.
Update
(
c
tx
,
meta
.
GlobalKey
(
hc
.
Name
),
hc
))
}
}
// DeleteHttpHealthCheck deletes the given HttpHealthCheck by name.
// DeleteHttpHealthCheck deletes the given HttpHealthCheck by name.
func
(
gce
*
GCECloud
)
DeleteHttpHealthCheck
(
name
string
)
error
{
func
(
gce
*
GCECloud
)
DeleteHttpHealthCheck
(
name
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newHealthcheckMetricContext
(
"delete_legacy"
)
mc
:=
newHealthcheckMetricContext
(
"delete_legacy"
)
return
mc
.
Observe
(
gce
.
c
.
HttpHealthChecks
()
.
Delete
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
)))
return
mc
.
Observe
(
gce
.
c
.
HttpHealthChecks
()
.
Delete
(
c
tx
,
meta
.
GlobalKey
(
name
)))
}
}
// CreateHttpHealthCheck creates the given HttpHealthCheck.
// CreateHttpHealthCheck creates the given HttpHealthCheck.
func
(
gce
*
GCECloud
)
CreateHttpHealthCheck
(
hc
*
compute
.
HttpHealthCheck
)
error
{
func
(
gce
*
GCECloud
)
CreateHttpHealthCheck
(
hc
*
compute
.
HttpHealthCheck
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newHealthcheckMetricContext
(
"create_legacy"
)
mc
:=
newHealthcheckMetricContext
(
"create_legacy"
)
return
mc
.
Observe
(
gce
.
c
.
HttpHealthChecks
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
hc
.
Name
),
hc
))
return
mc
.
Observe
(
gce
.
c
.
HttpHealthChecks
()
.
Insert
(
c
tx
,
meta
.
GlobalKey
(
hc
.
Name
),
hc
))
}
}
// ListHttpHealthChecks lists all HttpHealthChecks in the project.
// ListHttpHealthChecks lists all HttpHealthChecks in the project.
func
(
gce
*
GCECloud
)
ListHttpHealthChecks
()
([]
*
compute
.
HttpHealthCheck
,
error
)
{
func
(
gce
*
GCECloud
)
ListHttpHealthChecks
()
([]
*
compute
.
HttpHealthCheck
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newHealthcheckMetricContext
(
"list_legacy"
)
mc
:=
newHealthcheckMetricContext
(
"list_legacy"
)
v
,
err
:=
gce
.
c
.
HttpHealthChecks
()
.
List
(
c
ontext
.
Background
()
,
filter
.
None
)
v
,
err
:=
gce
.
c
.
HttpHealthChecks
()
.
List
(
c
tx
,
filter
.
None
)
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
...
@@ -92,33 +106,48 @@ func (gce *GCECloud) ListHttpHealthChecks() ([]*compute.HttpHealthCheck, error)
...
@@ -92,33 +106,48 @@ func (gce *GCECloud) ListHttpHealthChecks() ([]*compute.HttpHealthCheck, error)
// GetHttpsHealthCheck returns the given HttpsHealthCheck by name.
// GetHttpsHealthCheck returns the given HttpsHealthCheck by name.
func
(
gce
*
GCECloud
)
GetHttpsHealthCheck
(
name
string
)
(
*
compute
.
HttpsHealthCheck
,
error
)
{
func
(
gce
*
GCECloud
)
GetHttpsHealthCheck
(
name
string
)
(
*
compute
.
HttpsHealthCheck
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newHealthcheckMetricContext
(
"get_legacy"
)
mc
:=
newHealthcheckMetricContext
(
"get_legacy"
)
v
,
err
:=
gce
.
c
.
HttpsHealthChecks
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
))
v
,
err
:=
gce
.
c
.
HttpsHealthChecks
()
.
Get
(
c
tx
,
meta
.
GlobalKey
(
name
))
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// UpdateHttpsHealthCheck applies the given HttpsHealthCheck as an update.
// UpdateHttpsHealthCheck applies the given HttpsHealthCheck as an update.
func
(
gce
*
GCECloud
)
UpdateHttpsHealthCheck
(
hc
*
compute
.
HttpsHealthCheck
)
error
{
func
(
gce
*
GCECloud
)
UpdateHttpsHealthCheck
(
hc
*
compute
.
HttpsHealthCheck
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newHealthcheckMetricContext
(
"update_legacy"
)
mc
:=
newHealthcheckMetricContext
(
"update_legacy"
)
return
mc
.
Observe
(
gce
.
c
.
HttpsHealthChecks
()
.
Update
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
hc
.
Name
),
hc
))
return
mc
.
Observe
(
gce
.
c
.
HttpsHealthChecks
()
.
Update
(
c
tx
,
meta
.
GlobalKey
(
hc
.
Name
),
hc
))
}
}
// DeleteHttpsHealthCheck deletes the given HttpsHealthCheck by name.
// DeleteHttpsHealthCheck deletes the given HttpsHealthCheck by name.
func
(
gce
*
GCECloud
)
DeleteHttpsHealthCheck
(
name
string
)
error
{
func
(
gce
*
GCECloud
)
DeleteHttpsHealthCheck
(
name
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newHealthcheckMetricContext
(
"delete_legacy"
)
mc
:=
newHealthcheckMetricContext
(
"delete_legacy"
)
return
mc
.
Observe
(
gce
.
c
.
HttpsHealthChecks
()
.
Delete
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
)))
return
mc
.
Observe
(
gce
.
c
.
HttpsHealthChecks
()
.
Delete
(
c
tx
,
meta
.
GlobalKey
(
name
)))
}
}
// CreateHttpsHealthCheck creates the given HttpsHealthCheck.
// CreateHttpsHealthCheck creates the given HttpsHealthCheck.
func
(
gce
*
GCECloud
)
CreateHttpsHealthCheck
(
hc
*
compute
.
HttpsHealthCheck
)
error
{
func
(
gce
*
GCECloud
)
CreateHttpsHealthCheck
(
hc
*
compute
.
HttpsHealthCheck
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newHealthcheckMetricContext
(
"create_legacy"
)
mc
:=
newHealthcheckMetricContext
(
"create_legacy"
)
return
mc
.
Observe
(
gce
.
c
.
HttpsHealthChecks
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
hc
.
Name
),
hc
))
return
mc
.
Observe
(
gce
.
c
.
HttpsHealthChecks
()
.
Insert
(
c
tx
,
meta
.
GlobalKey
(
hc
.
Name
),
hc
))
}
}
// ListHttpsHealthChecks lists all HttpsHealthChecks in the project.
// ListHttpsHealthChecks lists all HttpsHealthChecks in the project.
func
(
gce
*
GCECloud
)
ListHttpsHealthChecks
()
([]
*
compute
.
HttpsHealthCheck
,
error
)
{
func
(
gce
*
GCECloud
)
ListHttpsHealthChecks
()
([]
*
compute
.
HttpsHealthCheck
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newHealthcheckMetricContext
(
"list_legacy"
)
mc
:=
newHealthcheckMetricContext
(
"list_legacy"
)
v
,
err
:=
gce
.
c
.
HttpsHealthChecks
()
.
List
(
c
ontext
.
Background
()
,
filter
.
None
)
v
,
err
:=
gce
.
c
.
HttpsHealthChecks
()
.
List
(
c
tx
,
filter
.
None
)
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
...
@@ -126,52 +155,76 @@ func (gce *GCECloud) ListHttpsHealthChecks() ([]*compute.HttpsHealthCheck, error
...
@@ -126,52 +155,76 @@ func (gce *GCECloud) ListHttpsHealthChecks() ([]*compute.HttpsHealthCheck, error
// GetHealthCheck returns the given HealthCheck by name.
// GetHealthCheck returns the given HealthCheck by name.
func
(
gce
*
GCECloud
)
GetHealthCheck
(
name
string
)
(
*
compute
.
HealthCheck
,
error
)
{
func
(
gce
*
GCECloud
)
GetHealthCheck
(
name
string
)
(
*
compute
.
HealthCheck
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newHealthcheckMetricContext
(
"get"
)
mc
:=
newHealthcheckMetricContext
(
"get"
)
v
,
err
:=
gce
.
c
.
HealthChecks
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
))
v
,
err
:=
gce
.
c
.
HealthChecks
()
.
Get
(
c
tx
,
meta
.
GlobalKey
(
name
))
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// GetAlphaHealthCheck returns the given alpha HealthCheck by name.
// GetAlphaHealthCheck returns the given alpha HealthCheck by name.
func
(
gce
*
GCECloud
)
GetAlphaHealthCheck
(
name
string
)
(
*
computealpha
.
HealthCheck
,
error
)
{
func
(
gce
*
GCECloud
)
GetAlphaHealthCheck
(
name
string
)
(
*
computealpha
.
HealthCheck
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newHealthcheckMetricContextWithVersion
(
"get"
,
computeAlphaVersion
)
mc
:=
newHealthcheckMetricContextWithVersion
(
"get"
,
computeAlphaVersion
)
v
,
err
:=
gce
.
c
.
AlphaHealthChecks
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
))
v
,
err
:=
gce
.
c
.
AlphaHealthChecks
()
.
Get
(
c
tx
,
meta
.
GlobalKey
(
name
))
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// UpdateHealthCheck applies the given HealthCheck as an update.
// UpdateHealthCheck applies the given HealthCheck as an update.
func
(
gce
*
GCECloud
)
UpdateHealthCheck
(
hc
*
compute
.
HealthCheck
)
error
{
func
(
gce
*
GCECloud
)
UpdateHealthCheck
(
hc
*
compute
.
HealthCheck
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newHealthcheckMetricContext
(
"update"
)
mc
:=
newHealthcheckMetricContext
(
"update"
)
return
mc
.
Observe
(
gce
.
c
.
HealthChecks
()
.
Update
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
hc
.
Name
),
hc
))
return
mc
.
Observe
(
gce
.
c
.
HealthChecks
()
.
Update
(
c
tx
,
meta
.
GlobalKey
(
hc
.
Name
),
hc
))
}
}
// UpdateAlphaHealthCheck applies the given alpha HealthCheck as an update.
// UpdateAlphaHealthCheck applies the given alpha HealthCheck as an update.
func
(
gce
*
GCECloud
)
UpdateAlphaHealthCheck
(
hc
*
computealpha
.
HealthCheck
)
error
{
func
(
gce
*
GCECloud
)
UpdateAlphaHealthCheck
(
hc
*
computealpha
.
HealthCheck
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newHealthcheckMetricContextWithVersion
(
"update"
,
computeAlphaVersion
)
mc
:=
newHealthcheckMetricContextWithVersion
(
"update"
,
computeAlphaVersion
)
return
mc
.
Observe
(
gce
.
c
.
AlphaHealthChecks
()
.
Update
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
hc
.
Name
),
hc
))
return
mc
.
Observe
(
gce
.
c
.
AlphaHealthChecks
()
.
Update
(
c
tx
,
meta
.
GlobalKey
(
hc
.
Name
),
hc
))
}
}
// DeleteHealthCheck deletes the given HealthCheck by name.
// DeleteHealthCheck deletes the given HealthCheck by name.
func
(
gce
*
GCECloud
)
DeleteHealthCheck
(
name
string
)
error
{
func
(
gce
*
GCECloud
)
DeleteHealthCheck
(
name
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newHealthcheckMetricContext
(
"delete"
)
mc
:=
newHealthcheckMetricContext
(
"delete"
)
return
mc
.
Observe
(
gce
.
c
.
HealthChecks
()
.
Delete
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
)))
return
mc
.
Observe
(
gce
.
c
.
HealthChecks
()
.
Delete
(
c
tx
,
meta
.
GlobalKey
(
name
)))
}
}
// CreateHealthCheck creates the given HealthCheck.
// CreateHealthCheck creates the given HealthCheck.
func
(
gce
*
GCECloud
)
CreateHealthCheck
(
hc
*
compute
.
HealthCheck
)
error
{
func
(
gce
*
GCECloud
)
CreateHealthCheck
(
hc
*
compute
.
HealthCheck
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newHealthcheckMetricContext
(
"create"
)
mc
:=
newHealthcheckMetricContext
(
"create"
)
return
mc
.
Observe
(
gce
.
c
.
HealthChecks
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
hc
.
Name
),
hc
))
return
mc
.
Observe
(
gce
.
c
.
HealthChecks
()
.
Insert
(
c
tx
,
meta
.
GlobalKey
(
hc
.
Name
),
hc
))
}
}
// CreateAlphaHealthCheck creates the given alpha HealthCheck.
// CreateAlphaHealthCheck creates the given alpha HealthCheck.
func
(
gce
*
GCECloud
)
CreateAlphaHealthCheck
(
hc
*
computealpha
.
HealthCheck
)
error
{
func
(
gce
*
GCECloud
)
CreateAlphaHealthCheck
(
hc
*
computealpha
.
HealthCheck
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newHealthcheckMetricContextWithVersion
(
"create"
,
computeAlphaVersion
)
mc
:=
newHealthcheckMetricContextWithVersion
(
"create"
,
computeAlphaVersion
)
return
mc
.
Observe
(
gce
.
c
.
AlphaHealthChecks
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
hc
.
Name
),
hc
))
return
mc
.
Observe
(
gce
.
c
.
AlphaHealthChecks
()
.
Insert
(
c
tx
,
meta
.
GlobalKey
(
hc
.
Name
),
hc
))
}
}
// ListHealthChecks lists all HealthCheck in the project.
// ListHealthChecks lists all HealthCheck in the project.
func
(
gce
*
GCECloud
)
ListHealthChecks
()
([]
*
compute
.
HealthCheck
,
error
)
{
func
(
gce
*
GCECloud
)
ListHealthChecks
()
([]
*
compute
.
HealthCheck
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newHealthcheckMetricContext
(
"list"
)
mc
:=
newHealthcheckMetricContext
(
"list"
)
v
,
err
:=
gce
.
c
.
HealthChecks
()
.
List
(
c
ontext
.
Background
()
,
filter
.
None
)
v
,
err
:=
gce
.
c
.
HealthChecks
()
.
List
(
c
tx
,
filter
.
None
)
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
...
...
pkg/cloudprovider/providers/gce/gce_instancegroup.go
View file @
1f336dda
...
@@ -17,10 +17,9 @@ limitations under the License.
...
@@ -17,10 +17,9 @@ limitations under the License.
package
gce
package
gce
import
(
import
(
"context"
compute
"google.golang.org/api/compute/v1"
compute
"google.golang.org/api/compute/v1"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
)
)
...
@@ -32,36 +31,51 @@ func newInstanceGroupMetricContext(request string, zone string) *metricContext {
...
@@ -32,36 +31,51 @@ func newInstanceGroupMetricContext(request string, zone string) *metricContext {
// CreateInstanceGroup creates an instance group with the given
// CreateInstanceGroup creates an instance group with the given
// instances. It is the callers responsibility to add named ports.
// instances. It is the callers responsibility to add named ports.
func
(
gce
*
GCECloud
)
CreateInstanceGroup
(
ig
*
compute
.
InstanceGroup
,
zone
string
)
error
{
func
(
gce
*
GCECloud
)
CreateInstanceGroup
(
ig
*
compute
.
InstanceGroup
,
zone
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newInstanceGroupMetricContext
(
"create"
,
zone
)
mc
:=
newInstanceGroupMetricContext
(
"create"
,
zone
)
return
mc
.
Observe
(
gce
.
c
.
InstanceGroups
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
ZonalKey
(
ig
.
Name
,
zone
),
ig
))
return
mc
.
Observe
(
gce
.
c
.
InstanceGroups
()
.
Insert
(
c
tx
,
meta
.
ZonalKey
(
ig
.
Name
,
zone
),
ig
))
}
}
// DeleteInstanceGroup deletes an instance group.
// DeleteInstanceGroup deletes an instance group.
func
(
gce
*
GCECloud
)
DeleteInstanceGroup
(
name
string
,
zone
string
)
error
{
func
(
gce
*
GCECloud
)
DeleteInstanceGroup
(
name
string
,
zone
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newInstanceGroupMetricContext
(
"delete"
,
zone
)
mc
:=
newInstanceGroupMetricContext
(
"delete"
,
zone
)
return
mc
.
Observe
(
gce
.
c
.
InstanceGroups
()
.
Delete
(
c
ontext
.
Background
()
,
meta
.
ZonalKey
(
name
,
zone
)))
return
mc
.
Observe
(
gce
.
c
.
InstanceGroups
()
.
Delete
(
c
tx
,
meta
.
ZonalKey
(
name
,
zone
)))
}
}
// ListInstanceGroups lists all InstanceGroups in the project and
// ListInstanceGroups lists all InstanceGroups in the project and
// zone.
// zone.
func
(
gce
*
GCECloud
)
ListInstanceGroups
(
zone
string
)
([]
*
compute
.
InstanceGroup
,
error
)
{
func
(
gce
*
GCECloud
)
ListInstanceGroups
(
zone
string
)
([]
*
compute
.
InstanceGroup
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newInstanceGroupMetricContext
(
"list"
,
zone
)
mc
:=
newInstanceGroupMetricContext
(
"list"
,
zone
)
v
,
err
:=
gce
.
c
.
InstanceGroups
()
.
List
(
c
ontext
.
Background
()
,
zone
,
filter
.
None
)
v
,
err
:=
gce
.
c
.
InstanceGroups
()
.
List
(
c
tx
,
zone
,
filter
.
None
)
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// ListInstancesInInstanceGroup lists all the instances in a given
// ListInstancesInInstanceGroup lists all the instances in a given
// instance group and state.
// instance group and state.
func
(
gce
*
GCECloud
)
ListInstancesInInstanceGroup
(
name
string
,
zone
string
,
state
string
)
([]
*
compute
.
InstanceWithNamedPorts
,
error
)
{
func
(
gce
*
GCECloud
)
ListInstancesInInstanceGroup
(
name
string
,
zone
string
,
state
string
)
([]
*
compute
.
InstanceWithNamedPorts
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newInstanceGroupMetricContext
(
"list_instances"
,
zone
)
mc
:=
newInstanceGroupMetricContext
(
"list_instances"
,
zone
)
req
:=
&
compute
.
InstanceGroupsListInstancesRequest
{
InstanceState
:
state
}
req
:=
&
compute
.
InstanceGroupsListInstancesRequest
{
InstanceState
:
state
}
v
,
err
:=
gce
.
c
.
InstanceGroups
()
.
ListInstances
(
c
ontext
.
Background
()
,
meta
.
ZonalKey
(
name
,
zone
),
req
,
filter
.
None
)
v
,
err
:=
gce
.
c
.
InstanceGroups
()
.
ListInstances
(
c
tx
,
meta
.
ZonalKey
(
name
,
zone
),
req
,
filter
.
None
)
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// AddInstancesToInstanceGroup adds the given instances to the given
// AddInstancesToInstanceGroup adds the given instances to the given
// instance group.
// instance group.
func
(
gce
*
GCECloud
)
AddInstancesToInstanceGroup
(
name
string
,
zone
string
,
instanceRefs
[]
*
compute
.
InstanceReference
)
error
{
func
(
gce
*
GCECloud
)
AddInstancesToInstanceGroup
(
name
string
,
zone
string
,
instanceRefs
[]
*
compute
.
InstanceReference
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newInstanceGroupMetricContext
(
"add_instances"
,
zone
)
mc
:=
newInstanceGroupMetricContext
(
"add_instances"
,
zone
)
// TODO: should cull operation above this layer.
// TODO: should cull operation above this layer.
if
len
(
instanceRefs
)
==
0
{
if
len
(
instanceRefs
)
==
0
{
...
@@ -70,12 +84,15 @@ func (gce *GCECloud) AddInstancesToInstanceGroup(name string, zone string, insta
...
@@ -70,12 +84,15 @@ func (gce *GCECloud) AddInstancesToInstanceGroup(name string, zone string, insta
req
:=
&
compute
.
InstanceGroupsAddInstancesRequest
{
req
:=
&
compute
.
InstanceGroupsAddInstancesRequest
{
Instances
:
instanceRefs
,
Instances
:
instanceRefs
,
}
}
return
mc
.
Observe
(
gce
.
c
.
InstanceGroups
()
.
AddInstances
(
c
ontext
.
Background
()
,
meta
.
ZonalKey
(
name
,
zone
),
req
))
return
mc
.
Observe
(
gce
.
c
.
InstanceGroups
()
.
AddInstances
(
c
tx
,
meta
.
ZonalKey
(
name
,
zone
),
req
))
}
}
// RemoveInstancesFromInstanceGroup removes the given instances from
// RemoveInstancesFromInstanceGroup removes the given instances from
// the instance group.
// the instance group.
func
(
gce
*
GCECloud
)
RemoveInstancesFromInstanceGroup
(
name
string
,
zone
string
,
instanceRefs
[]
*
compute
.
InstanceReference
)
error
{
func
(
gce
*
GCECloud
)
RemoveInstancesFromInstanceGroup
(
name
string
,
zone
string
,
instanceRefs
[]
*
compute
.
InstanceReference
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newInstanceGroupMetricContext
(
"remove_instances"
,
zone
)
mc
:=
newInstanceGroupMetricContext
(
"remove_instances"
,
zone
)
// TODO: should cull operation above this layer.
// TODO: should cull operation above this layer.
if
len
(
instanceRefs
)
==
0
{
if
len
(
instanceRefs
)
==
0
{
...
@@ -84,19 +101,25 @@ func (gce *GCECloud) RemoveInstancesFromInstanceGroup(name string, zone string,
...
@@ -84,19 +101,25 @@ func (gce *GCECloud) RemoveInstancesFromInstanceGroup(name string, zone string,
req
:=
&
compute
.
InstanceGroupsRemoveInstancesRequest
{
req
:=
&
compute
.
InstanceGroupsRemoveInstancesRequest
{
Instances
:
instanceRefs
,
Instances
:
instanceRefs
,
}
}
return
mc
.
Observe
(
gce
.
c
.
InstanceGroups
()
.
RemoveInstances
(
c
ontext
.
Background
()
,
meta
.
ZonalKey
(
name
,
zone
),
req
))
return
mc
.
Observe
(
gce
.
c
.
InstanceGroups
()
.
RemoveInstances
(
c
tx
,
meta
.
ZonalKey
(
name
,
zone
),
req
))
}
}
// SetNamedPortsOfInstanceGroup sets the list of named ports on a given instance group
// SetNamedPortsOfInstanceGroup sets the list of named ports on a given instance group
func
(
gce
*
GCECloud
)
SetNamedPortsOfInstanceGroup
(
igName
,
zone
string
,
namedPorts
[]
*
compute
.
NamedPort
)
error
{
func
(
gce
*
GCECloud
)
SetNamedPortsOfInstanceGroup
(
igName
,
zone
string
,
namedPorts
[]
*
compute
.
NamedPort
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newInstanceGroupMetricContext
(
"set_namedports"
,
zone
)
mc
:=
newInstanceGroupMetricContext
(
"set_namedports"
,
zone
)
req
:=
&
compute
.
InstanceGroupsSetNamedPortsRequest
{
NamedPorts
:
namedPorts
}
req
:=
&
compute
.
InstanceGroupsSetNamedPortsRequest
{
NamedPorts
:
namedPorts
}
return
mc
.
Observe
(
gce
.
c
.
InstanceGroups
()
.
SetNamedPorts
(
c
ontext
.
Background
()
,
meta
.
ZonalKey
(
igName
,
zone
),
req
))
return
mc
.
Observe
(
gce
.
c
.
InstanceGroups
()
.
SetNamedPorts
(
c
tx
,
meta
.
ZonalKey
(
igName
,
zone
),
req
))
}
}
// GetInstanceGroup returns an instance group by name.
// GetInstanceGroup returns an instance group by name.
func
(
gce
*
GCECloud
)
GetInstanceGroup
(
name
string
,
zone
string
)
(
*
compute
.
InstanceGroup
,
error
)
{
func
(
gce
*
GCECloud
)
GetInstanceGroup
(
name
string
,
zone
string
)
(
*
compute
.
InstanceGroup
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newInstanceGroupMetricContext
(
"get"
,
zone
)
mc
:=
newInstanceGroupMetricContext
(
"get"
,
zone
)
v
,
err
:=
gce
.
c
.
InstanceGroups
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
ZonalKey
(
name
,
zone
))
v
,
err
:=
gce
.
c
.
InstanceGroups
()
.
Get
(
c
tx
,
meta
.
ZonalKey
(
name
,
zone
))
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
pkg/cloudprovider/providers/gce/gce_instances.go
View file @
1f336dda
...
@@ -35,6 +35,7 @@ import (
...
@@ -35,6 +35,7 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/kubernetes/pkg/cloudprovider"
"k8s.io/kubernetes/pkg/cloudprovider"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
kubeletapis
"k8s.io/kubernetes/pkg/kubelet/apis"
kubeletapis
"k8s.io/kubernetes/pkg/kubelet/apis"
...
@@ -100,12 +101,15 @@ func (gce *GCECloud) NodeAddresses(_ context.Context, _ types.NodeName) ([]v1.No
...
@@ -100,12 +101,15 @@ func (gce *GCECloud) NodeAddresses(_ context.Context, _ types.NodeName) ([]v1.No
// NodeAddressesByProviderID will not be called from the node that is requesting this ID.
// NodeAddressesByProviderID will not be called from the node that is requesting this ID.
// i.e. metadata service and other local methods cannot be used here
// i.e. metadata service and other local methods cannot be used here
func
(
gce
*
GCECloud
)
NodeAddressesByProviderID
(
ctx
context
.
Context
,
providerID
string
)
([]
v1
.
NodeAddress
,
error
)
{
func
(
gce
*
GCECloud
)
NodeAddressesByProviderID
(
ctx
context
.
Context
,
providerID
string
)
([]
v1
.
NodeAddress
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
_
,
zone
,
name
,
err
:=
splitProviderID
(
providerID
)
_
,
zone
,
name
,
err
:=
splitProviderID
(
providerID
)
if
err
!=
nil
{
if
err
!=
nil
{
return
[]
v1
.
NodeAddress
{},
err
return
[]
v1
.
NodeAddress
{},
err
}
}
instance
,
err
:=
gce
.
c
.
Instances
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
ZonalKey
(
canonicalizeInstanceName
(
name
),
zone
))
instance
,
err
:=
gce
.
c
.
Instances
()
.
Get
(
c
tx
,
meta
.
ZonalKey
(
canonicalizeInstanceName
(
name
),
zone
))
if
err
!=
nil
{
if
err
!=
nil
{
return
[]
v1
.
NodeAddress
{},
fmt
.
Errorf
(
"error while querying for providerID %q: %v"
,
providerID
,
err
)
return
[]
v1
.
NodeAddress
{},
fmt
.
Errorf
(
"error while querying for providerID %q: %v"
,
providerID
,
err
)
}
}
...
@@ -229,8 +233,11 @@ func (gce *GCECloud) InstanceType(ctx context.Context, nodeName types.NodeName)
...
@@ -229,8 +233,11 @@ func (gce *GCECloud) InstanceType(ctx context.Context, nodeName types.NodeName)
}
}
func
(
gce
*
GCECloud
)
AddSSHKeyToAllInstances
(
ctx
context
.
Context
,
user
string
,
keyData
[]
byte
)
error
{
func
(
gce
*
GCECloud
)
AddSSHKeyToAllInstances
(
ctx
context
.
Context
,
user
string
,
keyData
[]
byte
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
return
wait
.
Poll
(
2
*
time
.
Second
,
30
*
time
.
Second
,
func
()
(
bool
,
error
)
{
return
wait
.
Poll
(
2
*
time
.
Second
,
30
*
time
.
Second
,
func
()
(
bool
,
error
)
{
project
,
err
:=
gce
.
c
.
Projects
()
.
Get
(
c
ontext
.
Background
()
,
gce
.
projectID
)
project
,
err
:=
gce
.
c
.
Projects
()
.
Get
(
c
tx
,
gce
.
projectID
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Could not get project: %v"
,
err
)
glog
.
Errorf
(
"Could not get project: %v"
,
err
)
return
false
,
nil
return
false
,
nil
...
@@ -261,7 +268,7 @@ func (gce *GCECloud) AddSSHKeyToAllInstances(ctx context.Context, user string, k
...
@@ -261,7 +268,7 @@ func (gce *GCECloud) AddSSHKeyToAllInstances(ctx context.Context, user string, k
}
}
mc
:=
newInstancesMetricContext
(
"add_ssh_key"
,
""
)
mc
:=
newInstancesMetricContext
(
"add_ssh_key"
,
""
)
err
=
gce
.
c
.
Projects
()
.
SetCommonInstanceMetadata
(
c
ontext
.
Background
()
,
gce
.
projectID
,
project
.
CommonInstanceMetadata
)
err
=
gce
.
c
.
Projects
()
.
SetCommonInstanceMetadata
(
c
tx
,
gce
.
projectID
,
project
.
CommonInstanceMetadata
)
mc
.
Observe
(
err
)
mc
.
Observe
(
err
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -301,9 +308,12 @@ func (gce *GCECloud) GetAllCurrentZones() (sets.String, error) {
...
@@ -301,9 +308,12 @@ func (gce *GCECloud) GetAllCurrentZones() (sets.String, error) {
//
//
// TODO: this should be removed from the cloud provider.
// TODO: this should be removed from the cloud provider.
func
(
gce
*
GCECloud
)
GetAllZonesFromCloudProvider
()
(
sets
.
String
,
error
)
{
func
(
gce
*
GCECloud
)
GetAllZonesFromCloudProvider
()
(
sets
.
String
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
zones
:=
sets
.
NewString
()
zones
:=
sets
.
NewString
()
for
_
,
zone
:=
range
gce
.
managedZones
{
for
_
,
zone
:=
range
gce
.
managedZones
{
instances
,
err
:=
gce
.
c
.
Instances
()
.
List
(
c
ontext
.
Background
()
,
zone
,
filter
.
None
)
instances
,
err
:=
gce
.
c
.
Instances
()
.
List
(
c
tx
,
zone
,
filter
.
None
)
if
err
!=
nil
{
if
err
!=
nil
{
return
sets
.
NewString
(),
err
return
sets
.
NewString
(),
err
}
}
...
@@ -316,15 +326,21 @@ func (gce *GCECloud) GetAllZonesFromCloudProvider() (sets.String, error) {
...
@@ -316,15 +326,21 @@ func (gce *GCECloud) GetAllZonesFromCloudProvider() (sets.String, error) {
// InsertInstance creates a new instance on GCP
// InsertInstance creates a new instance on GCP
func
(
gce
*
GCECloud
)
InsertInstance
(
project
string
,
zone
string
,
i
*
compute
.
Instance
)
error
{
func
(
gce
*
GCECloud
)
InsertInstance
(
project
string
,
zone
string
,
i
*
compute
.
Instance
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newInstancesMetricContext
(
"create"
,
zone
)
mc
:=
newInstancesMetricContext
(
"create"
,
zone
)
return
mc
.
Observe
(
gce
.
c
.
Instances
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
ZonalKey
(
i
.
Name
,
zone
),
i
))
return
mc
.
Observe
(
gce
.
c
.
Instances
()
.
Insert
(
c
tx
,
meta
.
ZonalKey
(
i
.
Name
,
zone
),
i
))
}
}
// ListInstanceNames returns a string of instance names separated by spaces.
// ListInstanceNames returns a string of instance names separated by spaces.
// This method should only be used for e2e testing.
// This method should only be used for e2e testing.
// TODO: remove this method.
// TODO: remove this method.
func
(
gce
*
GCECloud
)
ListInstanceNames
(
project
,
zone
string
)
(
string
,
error
)
{
func
(
gce
*
GCECloud
)
ListInstanceNames
(
project
,
zone
string
)
(
string
,
error
)
{
l
,
err
:=
gce
.
c
.
Instances
()
.
List
(
context
.
Background
(),
zone
,
filter
.
None
)
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
l
,
err
:=
gce
.
c
.
Instances
()
.
List
(
ctx
,
zone
,
filter
.
None
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
...
@@ -337,7 +353,10 @@ func (gce *GCECloud) ListInstanceNames(project, zone string) (string, error) {
...
@@ -337,7 +353,10 @@ func (gce *GCECloud) ListInstanceNames(project, zone string) (string, error) {
// DeleteInstance deletes an instance specified by project, zone, and name
// DeleteInstance deletes an instance specified by project, zone, and name
func
(
gce
*
GCECloud
)
DeleteInstance
(
project
,
zone
,
name
string
)
error
{
func
(
gce
*
GCECloud
)
DeleteInstance
(
project
,
zone
,
name
string
)
error
{
return
gce
.
c
.
Instances
()
.
Delete
(
context
.
Background
(),
meta
.
ZonalKey
(
name
,
zone
))
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
return
gce
.
c
.
Instances
()
.
Delete
(
ctx
,
meta
.
ZonalKey
(
name
,
zone
))
}
}
// Implementation of Instances.CurrentNodeName
// Implementation of Instances.CurrentNodeName
...
@@ -349,6 +368,9 @@ func (gce *GCECloud) CurrentNodeName(ctx context.Context, hostname string) (type
...
@@ -349,6 +368,9 @@ func (gce *GCECloud) CurrentNodeName(ctx context.Context, hostname string) (type
// `node` for allocation to pods. Returns a list of the form
// `node` for allocation to pods. Returns a list of the form
// "<ip>/<netmask>".
// "<ip>/<netmask>".
func
(
gce
*
GCECloud
)
AliasRanges
(
nodeName
types
.
NodeName
)
(
cidrs
[]
string
,
err
error
)
{
func
(
gce
*
GCECloud
)
AliasRanges
(
nodeName
types
.
NodeName
)
(
cidrs
[]
string
,
err
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
var
instance
*
gceInstance
var
instance
*
gceInstance
instance
,
err
=
gce
.
getInstanceByName
(
mapNodeNameToInstanceName
(
nodeName
))
instance
,
err
=
gce
.
getInstanceByName
(
mapNodeNameToInstanceName
(
nodeName
))
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -356,7 +378,7 @@ func (gce *GCECloud) AliasRanges(nodeName types.NodeName) (cidrs []string, err e
...
@@ -356,7 +378,7 @@ func (gce *GCECloud) AliasRanges(nodeName types.NodeName) (cidrs []string, err e
}
}
var
res
*
computebeta
.
Instance
var
res
*
computebeta
.
Instance
res
,
err
=
gce
.
c
.
BetaInstances
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
ZonalKey
(
instance
.
Name
,
lastComponent
(
instance
.
Zone
)))
res
,
err
=
gce
.
c
.
BetaInstances
()
.
Get
(
c
tx
,
meta
.
ZonalKey
(
instance
.
Name
,
lastComponent
(
instance
.
Zone
)))
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
...
@@ -372,12 +394,14 @@ func (gce *GCECloud) AliasRanges(nodeName types.NodeName) (cidrs []string, err e
...
@@ -372,12 +394,14 @@ func (gce *GCECloud) AliasRanges(nodeName types.NodeName) (cidrs []string, err e
// AddAliasToInstance adds an alias to the given instance from the named
// AddAliasToInstance adds an alias to the given instance from the named
// secondary range.
// secondary range.
func
(
gce
*
GCECloud
)
AddAliasToInstance
(
nodeName
types
.
NodeName
,
alias
*
net
.
IPNet
)
error
{
func
(
gce
*
GCECloud
)
AddAliasToInstance
(
nodeName
types
.
NodeName
,
alias
*
net
.
IPNet
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
v1instance
,
err
:=
gce
.
getInstanceByName
(
mapNodeNameToInstanceName
(
nodeName
))
v1instance
,
err
:=
gce
.
getInstanceByName
(
mapNodeNameToInstanceName
(
nodeName
))
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
instance
,
err
:=
gce
.
c
.
BetaInstances
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
ZonalKey
(
v1instance
.
Name
,
lastComponent
(
v1instance
.
Zone
)))
instance
,
err
:=
gce
.
c
.
BetaInstances
()
.
Get
(
c
tx
,
meta
.
ZonalKey
(
v1instance
.
Name
,
lastComponent
(
v1instance
.
Zone
)))
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -400,13 +424,16 @@ func (gce *GCECloud) AddAliasToInstance(nodeName types.NodeName, alias *net.IPNe
...
@@ -400,13 +424,16 @@ func (gce *GCECloud) AddAliasToInstance(nodeName types.NodeName, alias *net.IPNe
})
})
mc
:=
newInstancesMetricContext
(
"add_alias"
,
v1instance
.
Zone
)
mc
:=
newInstancesMetricContext
(
"add_alias"
,
v1instance
.
Zone
)
err
=
gce
.
c
.
BetaInstances
()
.
UpdateNetworkInterface
(
c
ontext
.
Background
()
,
meta
.
ZonalKey
(
instance
.
Name
,
lastComponent
(
instance
.
Zone
)),
iface
.
Name
,
iface
)
err
=
gce
.
c
.
BetaInstances
()
.
UpdateNetworkInterface
(
c
tx
,
meta
.
ZonalKey
(
instance
.
Name
,
lastComponent
(
instance
.
Zone
)),
iface
.
Name
,
iface
)
return
mc
.
Observe
(
err
)
return
mc
.
Observe
(
err
)
}
}
// Gets the named instances, returning cloudprovider.InstanceNotFound if any
// Gets the named instances, returning cloudprovider.InstanceNotFound if any
// instance is not found
// instance is not found
func
(
gce
*
GCECloud
)
getInstancesByNames
(
names
[]
string
)
([]
*
gceInstance
,
error
)
{
func
(
gce
*
GCECloud
)
getInstancesByNames
(
names
[]
string
)
([]
*
gceInstance
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
found
:=
map
[
string
]
*
gceInstance
{}
found
:=
map
[
string
]
*
gceInstance
{}
remaining
:=
len
(
names
)
remaining
:=
len
(
names
)
...
@@ -424,7 +451,7 @@ func (gce *GCECloud) getInstancesByNames(names []string) ([]*gceInstance, error)
...
@@ -424,7 +451,7 @@ func (gce *GCECloud) getInstancesByNames(names []string) ([]*gceInstance, error)
if
remaining
==
0
{
if
remaining
==
0
{
break
break
}
}
instances
,
err
:=
gce
.
c
.
Instances
()
.
List
(
c
ontext
.
Background
()
,
zone
,
filter
.
Regexp
(
"name"
,
nodeInstancePrefix
+
".*"
))
instances
,
err
:=
gce
.
c
.
Instances
()
.
List
(
c
tx
,
zone
,
filter
.
Regexp
(
"name"
,
nodeInstancePrefix
+
".*"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -488,9 +515,12 @@ func (gce *GCECloud) getInstanceByName(name string) (*gceInstance, error) {
...
@@ -488,9 +515,12 @@ func (gce *GCECloud) getInstanceByName(name string) (*gceInstance, error) {
}
}
func
(
gce
*
GCECloud
)
getInstanceFromProjectInZoneByName
(
project
,
zone
,
name
string
)
(
*
gceInstance
,
error
)
{
func
(
gce
*
GCECloud
)
getInstanceFromProjectInZoneByName
(
project
,
zone
,
name
string
)
(
*
gceInstance
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
name
=
canonicalizeInstanceName
(
name
)
name
=
canonicalizeInstanceName
(
name
)
mc
:=
newInstancesMetricContext
(
"get"
,
zone
)
mc
:=
newInstancesMetricContext
(
"get"
,
zone
)
res
,
err
:=
gce
.
c
.
Instances
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
ZonalKey
(
name
,
zone
))
res
,
err
:=
gce
.
c
.
Instances
()
.
Get
(
c
tx
,
meta
.
ZonalKey
(
name
,
zone
))
mc
.
Observe
(
err
)
mc
.
Observe
(
err
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -557,6 +587,9 @@ func (gce *GCECloud) isCurrentInstance(instanceID string) bool {
...
@@ -557,6 +587,9 @@ func (gce *GCECloud) isCurrentInstance(instanceID string) bool {
// format of the host names in the cluster. Only use it as a fallback if
// format of the host names in the cluster. Only use it as a fallback if
// gce.nodeTags is unspecified
// gce.nodeTags is unspecified
func
(
gce
*
GCECloud
)
computeHostTags
(
hosts
[]
*
gceInstance
)
([]
string
,
error
)
{
func
(
gce
*
GCECloud
)
computeHostTags
(
hosts
[]
*
gceInstance
)
([]
string
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
// TODO: We could store the tags in gceInstance, so we could have already fetched it
// TODO: We could store the tags in gceInstance, so we could have already fetched it
hostNamesByZone
:=
make
(
map
[
string
]
map
[
string
]
bool
)
// map of zones -> map of names -> bool (for easy lookup)
hostNamesByZone
:=
make
(
map
[
string
]
map
[
string
]
bool
)
// map of zones -> map of names -> bool (for easy lookup)
nodeInstancePrefix
:=
gce
.
nodeInstancePrefix
nodeInstancePrefix
:=
gce
.
nodeInstancePrefix
...
@@ -581,7 +614,7 @@ func (gce *GCECloud) computeHostTags(hosts []*gceInstance) ([]string, error) {
...
@@ -581,7 +614,7 @@ func (gce *GCECloud) computeHostTags(hosts []*gceInstance) ([]string, error) {
filt
=
filter
.
Regexp
(
"name"
,
nodeInstancePrefix
+
".*"
)
filt
=
filter
.
Regexp
(
"name"
,
nodeInstancePrefix
+
".*"
)
}
}
for
zone
,
hostNames
:=
range
hostNamesByZone
{
for
zone
,
hostNames
:=
range
hostNamesByZone
{
instances
,
err
:=
gce
.
c
.
Instances
()
.
List
(
c
ontext
.
Background
()
,
zone
,
filt
)
instances
,
err
:=
gce
.
c
.
Instances
()
.
List
(
c
tx
,
zone
,
filt
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
pkg/cloudprovider/providers/gce/gce_networkendpointgroup.go
View file @
1f336dda
...
@@ -17,12 +17,12 @@ limitations under the License.
...
@@ -17,12 +17,12 @@ limitations under the License.
package
gce
package
gce
import
(
import
(
"context"
"fmt"
"fmt"
"strings"
"strings"
computealpha
"google.golang.org/api/compute/v0.alpha"
computealpha
"google.golang.org/api/compute/v0.alpha"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
)
)
...
@@ -37,31 +37,40 @@ func newNetworkEndpointGroupMetricContext(request string, zone string) *metricCo
...
@@ -37,31 +37,40 @@ func newNetworkEndpointGroupMetricContext(request string, zone string) *metricCo
}
}
func
(
gce
*
GCECloud
)
GetNetworkEndpointGroup
(
name
string
,
zone
string
)
(
*
computealpha
.
NetworkEndpointGroup
,
error
)
{
func
(
gce
*
GCECloud
)
GetNetworkEndpointGroup
(
name
string
,
zone
string
)
(
*
computealpha
.
NetworkEndpointGroup
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newNetworkEndpointGroupMetricContext
(
"get"
,
zone
)
mc
:=
newNetworkEndpointGroupMetricContext
(
"get"
,
zone
)
if
err
:=
gce
.
alphaFeatureEnabled
(
AlphaFeatureNetworkEndpointGroup
);
err
!=
nil
{
if
err
:=
gce
.
alphaFeatureEnabled
(
AlphaFeatureNetworkEndpointGroup
);
err
!=
nil
{
return
nil
,
mc
.
Observe
(
err
)
return
nil
,
mc
.
Observe
(
err
)
}
}
v
,
err
:=
gce
.
c
.
AlphaNetworkEndpointGroups
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
ZonalKey
(
name
,
zone
))
v
,
err
:=
gce
.
c
.
AlphaNetworkEndpointGroups
()
.
Get
(
c
tx
,
meta
.
ZonalKey
(
name
,
zone
))
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
func
(
gce
*
GCECloud
)
ListNetworkEndpointGroup
(
zone
string
)
([]
*
computealpha
.
NetworkEndpointGroup
,
error
)
{
func
(
gce
*
GCECloud
)
ListNetworkEndpointGroup
(
zone
string
)
([]
*
computealpha
.
NetworkEndpointGroup
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newNetworkEndpointGroupMetricContext
(
"list"
,
zone
)
mc
:=
newNetworkEndpointGroupMetricContext
(
"list"
,
zone
)
if
err
:=
gce
.
alphaFeatureEnabled
(
AlphaFeatureNetworkEndpointGroup
);
err
!=
nil
{
if
err
:=
gce
.
alphaFeatureEnabled
(
AlphaFeatureNetworkEndpointGroup
);
err
!=
nil
{
return
nil
,
mc
.
Observe
(
err
)
return
nil
,
mc
.
Observe
(
err
)
}
}
negs
,
err
:=
gce
.
c
.
AlphaNetworkEndpointGroups
()
.
List
(
c
ontext
.
Background
()
,
zone
,
filter
.
None
)
negs
,
err
:=
gce
.
c
.
AlphaNetworkEndpointGroups
()
.
List
(
c
tx
,
zone
,
filter
.
None
)
return
negs
,
mc
.
Observe
(
err
)
return
negs
,
mc
.
Observe
(
err
)
}
}
// AggregatedListNetworkEndpointGroup returns a map of zone -> endpoint group.
// AggregatedListNetworkEndpointGroup returns a map of zone -> endpoint group.
func
(
gce
*
GCECloud
)
AggregatedListNetworkEndpointGroup
()
(
map
[
string
][]
*
computealpha
.
NetworkEndpointGroup
,
error
)
{
func
(
gce
*
GCECloud
)
AggregatedListNetworkEndpointGroup
()
(
map
[
string
][]
*
computealpha
.
NetworkEndpointGroup
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newNetworkEndpointGroupMetricContext
(
"aggregated_list"
,
""
)
mc
:=
newNetworkEndpointGroupMetricContext
(
"aggregated_list"
,
""
)
if
err
:=
gce
.
alphaFeatureEnabled
(
AlphaFeatureNetworkEndpointGroup
);
err
!=
nil
{
if
err
:=
gce
.
alphaFeatureEnabled
(
AlphaFeatureNetworkEndpointGroup
);
err
!=
nil
{
return
nil
,
mc
.
Observe
(
err
)
return
nil
,
mc
.
Observe
(
err
)
}
}
// TODO: filter for the region the cluster is in.
// TODO: filter for the region the cluster is in.
all
,
err
:=
gce
.
c
.
AlphaNetworkEndpointGroups
()
.
AggregatedList
(
c
ontext
.
Background
()
,
filter
.
None
)
all
,
err
:=
gce
.
c
.
AlphaNetworkEndpointGroups
()
.
AggregatedList
(
c
tx
,
filter
.
None
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
mc
.
Observe
(
err
)
return
nil
,
mc
.
Observe
(
err
)
}
}
...
@@ -79,22 +88,31 @@ func (gce *GCECloud) AggregatedListNetworkEndpointGroup() (map[string][]*compute
...
@@ -79,22 +88,31 @@ func (gce *GCECloud) AggregatedListNetworkEndpointGroup() (map[string][]*compute
}
}
func
(
gce
*
GCECloud
)
CreateNetworkEndpointGroup
(
neg
*
computealpha
.
NetworkEndpointGroup
,
zone
string
)
error
{
func
(
gce
*
GCECloud
)
CreateNetworkEndpointGroup
(
neg
*
computealpha
.
NetworkEndpointGroup
,
zone
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
if
err
:=
gce
.
alphaFeatureEnabled
(
AlphaFeatureNetworkEndpointGroup
);
err
!=
nil
{
if
err
:=
gce
.
alphaFeatureEnabled
(
AlphaFeatureNetworkEndpointGroup
);
err
!=
nil
{
return
err
return
err
}
}
mc
:=
newNetworkEndpointGroupMetricContext
(
"create"
,
zone
)
mc
:=
newNetworkEndpointGroupMetricContext
(
"create"
,
zone
)
return
mc
.
Observe
(
gce
.
c
.
AlphaNetworkEndpointGroups
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
ZonalKey
(
neg
.
Name
,
zone
),
neg
))
return
mc
.
Observe
(
gce
.
c
.
AlphaNetworkEndpointGroups
()
.
Insert
(
c
tx
,
meta
.
ZonalKey
(
neg
.
Name
,
zone
),
neg
))
}
}
func
(
gce
*
GCECloud
)
DeleteNetworkEndpointGroup
(
name
string
,
zone
string
)
error
{
func
(
gce
*
GCECloud
)
DeleteNetworkEndpointGroup
(
name
string
,
zone
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
if
err
:=
gce
.
alphaFeatureEnabled
(
AlphaFeatureNetworkEndpointGroup
);
err
!=
nil
{
if
err
:=
gce
.
alphaFeatureEnabled
(
AlphaFeatureNetworkEndpointGroup
);
err
!=
nil
{
return
err
return
err
}
}
mc
:=
newNetworkEndpointGroupMetricContext
(
"delete"
,
zone
)
mc
:=
newNetworkEndpointGroupMetricContext
(
"delete"
,
zone
)
return
mc
.
Observe
(
gce
.
c
.
AlphaNetworkEndpointGroups
()
.
Delete
(
c
ontext
.
Background
()
,
meta
.
ZonalKey
(
name
,
zone
)))
return
mc
.
Observe
(
gce
.
c
.
AlphaNetworkEndpointGroups
()
.
Delete
(
c
tx
,
meta
.
ZonalKey
(
name
,
zone
)))
}
}
func
(
gce
*
GCECloud
)
AttachNetworkEndpoints
(
name
,
zone
string
,
endpoints
[]
*
computealpha
.
NetworkEndpoint
)
error
{
func
(
gce
*
GCECloud
)
AttachNetworkEndpoints
(
name
,
zone
string
,
endpoints
[]
*
computealpha
.
NetworkEndpoint
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newNetworkEndpointGroupMetricContext
(
"attach"
,
zone
)
mc
:=
newNetworkEndpointGroupMetricContext
(
"attach"
,
zone
)
if
err
:=
gce
.
alphaFeatureEnabled
(
AlphaFeatureNetworkEndpointGroup
);
err
!=
nil
{
if
err
:=
gce
.
alphaFeatureEnabled
(
AlphaFeatureNetworkEndpointGroup
);
err
!=
nil
{
return
mc
.
Observe
(
err
)
return
mc
.
Observe
(
err
)
...
@@ -102,10 +120,13 @@ func (gce *GCECloud) AttachNetworkEndpoints(name, zone string, endpoints []*comp
...
@@ -102,10 +120,13 @@ func (gce *GCECloud) AttachNetworkEndpoints(name, zone string, endpoints []*comp
req
:=
&
computealpha
.
NetworkEndpointGroupsAttachEndpointsRequest
{
req
:=
&
computealpha
.
NetworkEndpointGroupsAttachEndpointsRequest
{
NetworkEndpoints
:
endpoints
,
NetworkEndpoints
:
endpoints
,
}
}
return
mc
.
Observe
(
gce
.
c
.
AlphaNetworkEndpointGroups
()
.
AttachNetworkEndpoints
(
c
ontext
.
Background
()
,
meta
.
ZonalKey
(
name
,
zone
),
req
))
return
mc
.
Observe
(
gce
.
c
.
AlphaNetworkEndpointGroups
()
.
AttachNetworkEndpoints
(
c
tx
,
meta
.
ZonalKey
(
name
,
zone
),
req
))
}
}
func
(
gce
*
GCECloud
)
DetachNetworkEndpoints
(
name
,
zone
string
,
endpoints
[]
*
computealpha
.
NetworkEndpoint
)
error
{
func
(
gce
*
GCECloud
)
DetachNetworkEndpoints
(
name
,
zone
string
,
endpoints
[]
*
computealpha
.
NetworkEndpoint
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newNetworkEndpointGroupMetricContext
(
"detach"
,
zone
)
mc
:=
newNetworkEndpointGroupMetricContext
(
"detach"
,
zone
)
if
err
:=
gce
.
alphaFeatureEnabled
(
AlphaFeatureNetworkEndpointGroup
);
err
!=
nil
{
if
err
:=
gce
.
alphaFeatureEnabled
(
AlphaFeatureNetworkEndpointGroup
);
err
!=
nil
{
return
mc
.
Observe
(
err
)
return
mc
.
Observe
(
err
)
...
@@ -113,10 +134,13 @@ func (gce *GCECloud) DetachNetworkEndpoints(name, zone string, endpoints []*comp
...
@@ -113,10 +134,13 @@ func (gce *GCECloud) DetachNetworkEndpoints(name, zone string, endpoints []*comp
req
:=
&
computealpha
.
NetworkEndpointGroupsDetachEndpointsRequest
{
req
:=
&
computealpha
.
NetworkEndpointGroupsDetachEndpointsRequest
{
NetworkEndpoints
:
endpoints
,
NetworkEndpoints
:
endpoints
,
}
}
return
mc
.
Observe
(
gce
.
c
.
AlphaNetworkEndpointGroups
()
.
DetachNetworkEndpoints
(
c
ontext
.
Background
()
,
meta
.
ZonalKey
(
name
,
zone
),
req
))
return
mc
.
Observe
(
gce
.
c
.
AlphaNetworkEndpointGroups
()
.
DetachNetworkEndpoints
(
c
tx
,
meta
.
ZonalKey
(
name
,
zone
),
req
))
}
}
func
(
gce
*
GCECloud
)
ListNetworkEndpoints
(
name
,
zone
string
,
showHealthStatus
bool
)
([]
*
computealpha
.
NetworkEndpointWithHealthStatus
,
error
)
{
func
(
gce
*
GCECloud
)
ListNetworkEndpoints
(
name
,
zone
string
,
showHealthStatus
bool
)
([]
*
computealpha
.
NetworkEndpointWithHealthStatus
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newNetworkEndpointGroupMetricContext
(
"list_networkendpoints"
,
zone
)
mc
:=
newNetworkEndpointGroupMetricContext
(
"list_networkendpoints"
,
zone
)
if
err
:=
gce
.
alphaFeatureEnabled
(
AlphaFeatureNetworkEndpointGroup
);
err
!=
nil
{
if
err
:=
gce
.
alphaFeatureEnabled
(
AlphaFeatureNetworkEndpointGroup
);
err
!=
nil
{
return
nil
,
mc
.
Observe
(
err
)
return
nil
,
mc
.
Observe
(
err
)
...
@@ -128,6 +152,6 @@ func (gce *GCECloud) ListNetworkEndpoints(name, zone string, showHealthStatus bo
...
@@ -128,6 +152,6 @@ func (gce *GCECloud) ListNetworkEndpoints(name, zone string, showHealthStatus bo
req
:=
&
computealpha
.
NetworkEndpointGroupsListEndpointsRequest
{
req
:=
&
computealpha
.
NetworkEndpointGroupsListEndpointsRequest
{
HealthStatus
:
healthStatus
,
HealthStatus
:
healthStatus
,
}
}
l
,
err
:=
gce
.
c
.
AlphaNetworkEndpointGroups
()
.
ListNetworkEndpoints
(
c
ontext
.
Background
()
,
meta
.
ZonalKey
(
name
,
zone
),
req
,
filter
.
None
)
l
,
err
:=
gce
.
c
.
AlphaNetworkEndpointGroups
()
.
ListNetworkEndpoints
(
c
tx
,
meta
.
ZonalKey
(
name
,
zone
),
req
,
filter
.
None
)
return
l
,
mc
.
Observe
(
err
)
return
l
,
mc
.
Observe
(
err
)
}
}
pkg/cloudprovider/providers/gce/gce_routes.go
View file @
1f336dda
...
@@ -27,6 +27,7 @@ import (
...
@@ -27,6 +27,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/types"
"k8s.io/kubernetes/pkg/cloudprovider"
"k8s.io/kubernetes/pkg/cloudprovider"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
)
)
...
@@ -37,10 +38,13 @@ func newRoutesMetricContext(request string) *metricContext {
...
@@ -37,10 +38,13 @@ func newRoutesMetricContext(request string) *metricContext {
// ListRoutes in the cloud environment.
// ListRoutes in the cloud environment.
func
(
gce
*
GCECloud
)
ListRoutes
(
ctx
context
.
Context
,
clusterName
string
)
([]
*
cloudprovider
.
Route
,
error
)
{
func
(
gce
*
GCECloud
)
ListRoutes
(
ctx
context
.
Context
,
clusterName
string
)
([]
*
cloudprovider
.
Route
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newRoutesMetricContext
(
"list"
)
mc
:=
newRoutesMetricContext
(
"list"
)
prefix
:=
truncateClusterName
(
clusterName
)
prefix
:=
truncateClusterName
(
clusterName
)
f
:=
filter
.
Regexp
(
"name"
,
prefix
+
"-.*"
)
.
AndRegexp
(
"network"
,
gce
.
NetworkURL
())
.
AndRegexp
(
"description"
,
k8sNodeRouteTag
)
f
:=
filter
.
Regexp
(
"name"
,
prefix
+
"-.*"
)
.
AndRegexp
(
"network"
,
gce
.
NetworkURL
())
.
AndRegexp
(
"description"
,
k8sNodeRouteTag
)
routes
,
err
:=
gce
.
c
.
Routes
()
.
List
(
c
ontext
.
Background
()
,
f
)
routes
,
err
:=
gce
.
c
.
Routes
()
.
List
(
c
tx
,
f
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
mc
.
Observe
(
err
)
return
nil
,
mc
.
Observe
(
err
)
}
}
...
@@ -60,6 +64,9 @@ func (gce *GCECloud) ListRoutes(ctx context.Context, clusterName string) ([]*clo
...
@@ -60,6 +64,9 @@ func (gce *GCECloud) ListRoutes(ctx context.Context, clusterName string) ([]*clo
// CreateRoute in the cloud environment.
// CreateRoute in the cloud environment.
func
(
gce
*
GCECloud
)
CreateRoute
(
ctx
context
.
Context
,
clusterName
string
,
nameHint
string
,
route
*
cloudprovider
.
Route
)
error
{
func
(
gce
*
GCECloud
)
CreateRoute
(
ctx
context
.
Context
,
clusterName
string
,
nameHint
string
,
route
*
cloudprovider
.
Route
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newRoutesMetricContext
(
"create"
)
mc
:=
newRoutesMetricContext
(
"create"
)
targetInstance
,
err
:=
gce
.
getInstanceByName
(
mapNodeNameToInstanceName
(
route
.
TargetNode
))
targetInstance
,
err
:=
gce
.
getInstanceByName
(
mapNodeNameToInstanceName
(
route
.
TargetNode
))
...
@@ -74,7 +81,7 @@ func (gce *GCECloud) CreateRoute(ctx context.Context, clusterName string, nameHi
...
@@ -74,7 +81,7 @@ func (gce *GCECloud) CreateRoute(ctx context.Context, clusterName string, nameHi
Priority
:
1000
,
Priority
:
1000
,
Description
:
k8sNodeRouteTag
,
Description
:
k8sNodeRouteTag
,
}
}
err
=
gce
.
c
.
Routes
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
cr
.
Name
),
cr
)
err
=
gce
.
c
.
Routes
()
.
Insert
(
c
tx
,
meta
.
GlobalKey
(
cr
.
Name
),
cr
)
if
isHTTPErrorCode
(
err
,
http
.
StatusConflict
)
{
if
isHTTPErrorCode
(
err
,
http
.
StatusConflict
)
{
glog
.
Infof
(
"Route %q already exists."
,
cr
.
Name
)
glog
.
Infof
(
"Route %q already exists."
,
cr
.
Name
)
err
=
nil
err
=
nil
...
@@ -84,8 +91,11 @@ func (gce *GCECloud) CreateRoute(ctx context.Context, clusterName string, nameHi
...
@@ -84,8 +91,11 @@ func (gce *GCECloud) CreateRoute(ctx context.Context, clusterName string, nameHi
// DeleteRoute from the cloud environment.
// DeleteRoute from the cloud environment.
func
(
gce
*
GCECloud
)
DeleteRoute
(
ctx
context
.
Context
,
clusterName
string
,
route
*
cloudprovider
.
Route
)
error
{
func
(
gce
*
GCECloud
)
DeleteRoute
(
ctx
context
.
Context
,
clusterName
string
,
route
*
cloudprovider
.
Route
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newRoutesMetricContext
(
"delete"
)
mc
:=
newRoutesMetricContext
(
"delete"
)
return
mc
.
Observe
(
gce
.
c
.
Routes
()
.
Delete
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
route
.
Name
)))
return
mc
.
Observe
(
gce
.
c
.
Routes
()
.
Delete
(
c
tx
,
meta
.
GlobalKey
(
route
.
Name
)))
}
}
func
truncateClusterName
(
clusterName
string
)
string
{
func
truncateClusterName
(
clusterName
string
)
string
{
...
...
pkg/cloudprovider/providers/gce/gce_targetpool.go
View file @
1f336dda
...
@@ -17,10 +17,9 @@ limitations under the License.
...
@@ -17,10 +17,9 @@ limitations under the License.
package
gce
package
gce
import
(
import
(
"context"
compute
"google.golang.org/api/compute/v1"
compute
"google.golang.org/api/compute/v1"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
)
)
...
@@ -30,37 +29,52 @@ func newTargetPoolMetricContext(request, region string) *metricContext {
...
@@ -30,37 +29,52 @@ func newTargetPoolMetricContext(request, region string) *metricContext {
// GetTargetPool returns the TargetPool by name.
// GetTargetPool returns the TargetPool by name.
func
(
gce
*
GCECloud
)
GetTargetPool
(
name
,
region
string
)
(
*
compute
.
TargetPool
,
error
)
{
func
(
gce
*
GCECloud
)
GetTargetPool
(
name
,
region
string
)
(
*
compute
.
TargetPool
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newTargetPoolMetricContext
(
"get"
,
region
)
mc
:=
newTargetPoolMetricContext
(
"get"
,
region
)
v
,
err
:=
gce
.
c
.
TargetPools
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
RegionalKey
(
name
,
region
))
v
,
err
:=
gce
.
c
.
TargetPools
()
.
Get
(
c
tx
,
meta
.
RegionalKey
(
name
,
region
))
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// CreateTargetPool creates the passed TargetPool
// CreateTargetPool creates the passed TargetPool
func
(
gce
*
GCECloud
)
CreateTargetPool
(
tp
*
compute
.
TargetPool
,
region
string
)
error
{
func
(
gce
*
GCECloud
)
CreateTargetPool
(
tp
*
compute
.
TargetPool
,
region
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newTargetPoolMetricContext
(
"create"
,
region
)
mc
:=
newTargetPoolMetricContext
(
"create"
,
region
)
return
mc
.
Observe
(
gce
.
c
.
TargetPools
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
RegionalKey
(
tp
.
Name
,
region
),
tp
))
return
mc
.
Observe
(
gce
.
c
.
TargetPools
()
.
Insert
(
c
tx
,
meta
.
RegionalKey
(
tp
.
Name
,
region
),
tp
))
}
}
// DeleteTargetPool deletes TargetPool by name.
// DeleteTargetPool deletes TargetPool by name.
func
(
gce
*
GCECloud
)
DeleteTargetPool
(
name
,
region
string
)
error
{
func
(
gce
*
GCECloud
)
DeleteTargetPool
(
name
,
region
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newTargetPoolMetricContext
(
"delete"
,
region
)
mc
:=
newTargetPoolMetricContext
(
"delete"
,
region
)
return
mc
.
Observe
(
gce
.
c
.
TargetPools
()
.
Delete
(
c
ontext
.
Background
()
,
meta
.
RegionalKey
(
name
,
region
)))
return
mc
.
Observe
(
gce
.
c
.
TargetPools
()
.
Delete
(
c
tx
,
meta
.
RegionalKey
(
name
,
region
)))
}
}
// AddInstancesToTargetPool adds instances by link to the TargetPool
// AddInstancesToTargetPool adds instances by link to the TargetPool
func
(
gce
*
GCECloud
)
AddInstancesToTargetPool
(
name
,
region
string
,
instanceRefs
[]
*
compute
.
InstanceReference
)
error
{
func
(
gce
*
GCECloud
)
AddInstancesToTargetPool
(
name
,
region
string
,
instanceRefs
[]
*
compute
.
InstanceReference
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
req
:=
&
compute
.
TargetPoolsAddInstanceRequest
{
req
:=
&
compute
.
TargetPoolsAddInstanceRequest
{
Instances
:
instanceRefs
,
Instances
:
instanceRefs
,
}
}
mc
:=
newTargetPoolMetricContext
(
"add_instances"
,
region
)
mc
:=
newTargetPoolMetricContext
(
"add_instances"
,
region
)
return
mc
.
Observe
(
gce
.
c
.
TargetPools
()
.
AddInstance
(
c
ontext
.
Background
()
,
meta
.
RegionalKey
(
name
,
region
),
req
))
return
mc
.
Observe
(
gce
.
c
.
TargetPools
()
.
AddInstance
(
c
tx
,
meta
.
RegionalKey
(
name
,
region
),
req
))
}
}
// RemoveInstancesFromTargetPool removes instances by link to the TargetPool
// RemoveInstancesFromTargetPool removes instances by link to the TargetPool
func
(
gce
*
GCECloud
)
RemoveInstancesFromTargetPool
(
name
,
region
string
,
instanceRefs
[]
*
compute
.
InstanceReference
)
error
{
func
(
gce
*
GCECloud
)
RemoveInstancesFromTargetPool
(
name
,
region
string
,
instanceRefs
[]
*
compute
.
InstanceReference
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
req
:=
&
compute
.
TargetPoolsRemoveInstanceRequest
{
req
:=
&
compute
.
TargetPoolsRemoveInstanceRequest
{
Instances
:
instanceRefs
,
Instances
:
instanceRefs
,
}
}
mc
:=
newTargetPoolMetricContext
(
"remove_instances"
,
region
)
mc
:=
newTargetPoolMetricContext
(
"remove_instances"
,
region
)
return
mc
.
Observe
(
gce
.
c
.
TargetPools
()
.
RemoveInstance
(
c
ontext
.
Background
()
,
meta
.
RegionalKey
(
name
,
region
),
req
))
return
mc
.
Observe
(
gce
.
c
.
TargetPools
()
.
RemoveInstance
(
c
tx
,
meta
.
RegionalKey
(
name
,
region
),
req
))
}
}
pkg/cloudprovider/providers/gce/gce_targetproxy.go
View file @
1f336dda
...
@@ -17,10 +17,9 @@ limitations under the License.
...
@@ -17,10 +17,9 @@ limitations under the License.
package
gce
package
gce
import
(
import
(
"context"
compute
"google.golang.org/api/compute/v1"
compute
"google.golang.org/api/compute/v1"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
)
)
...
@@ -31,34 +30,49 @@ func newTargetProxyMetricContext(request string) *metricContext {
...
@@ -31,34 +30,49 @@ func newTargetProxyMetricContext(request string) *metricContext {
// GetTargetHttpProxy returns the UrlMap by name.
// GetTargetHttpProxy returns the UrlMap by name.
func
(
gce
*
GCECloud
)
GetTargetHttpProxy
(
name
string
)
(
*
compute
.
TargetHttpProxy
,
error
)
{
func
(
gce
*
GCECloud
)
GetTargetHttpProxy
(
name
string
)
(
*
compute
.
TargetHttpProxy
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newTargetProxyMetricContext
(
"get"
)
mc
:=
newTargetProxyMetricContext
(
"get"
)
v
,
err
:=
gce
.
c
.
TargetHttpProxies
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
))
v
,
err
:=
gce
.
c
.
TargetHttpProxies
()
.
Get
(
c
tx
,
meta
.
GlobalKey
(
name
))
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// CreateTargetHttpProxy creates a TargetHttpProxy
// CreateTargetHttpProxy creates a TargetHttpProxy
func
(
gce
*
GCECloud
)
CreateTargetHttpProxy
(
proxy
*
compute
.
TargetHttpProxy
)
error
{
func
(
gce
*
GCECloud
)
CreateTargetHttpProxy
(
proxy
*
compute
.
TargetHttpProxy
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newTargetProxyMetricContext
(
"create"
)
mc
:=
newTargetProxyMetricContext
(
"create"
)
return
mc
.
Observe
(
gce
.
c
.
TargetHttpProxies
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
proxy
.
Name
),
proxy
))
return
mc
.
Observe
(
gce
.
c
.
TargetHttpProxies
()
.
Insert
(
c
tx
,
meta
.
GlobalKey
(
proxy
.
Name
),
proxy
))
}
}
// SetUrlMapForTargetHttpProxy sets the given UrlMap for the given TargetHttpProxy.
// SetUrlMapForTargetHttpProxy sets the given UrlMap for the given TargetHttpProxy.
func
(
gce
*
GCECloud
)
SetUrlMapForTargetHttpProxy
(
proxy
*
compute
.
TargetHttpProxy
,
urlMap
*
compute
.
UrlMap
)
error
{
func
(
gce
*
GCECloud
)
SetUrlMapForTargetHttpProxy
(
proxy
*
compute
.
TargetHttpProxy
,
urlMap
*
compute
.
UrlMap
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
ref
:=
&
compute
.
UrlMapReference
{
UrlMap
:
urlMap
.
SelfLink
}
ref
:=
&
compute
.
UrlMapReference
{
UrlMap
:
urlMap
.
SelfLink
}
mc
:=
newTargetProxyMetricContext
(
"set_url_map"
)
mc
:=
newTargetProxyMetricContext
(
"set_url_map"
)
return
mc
.
Observe
(
gce
.
c
.
TargetHttpProxies
()
.
SetUrlMap
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
proxy
.
Name
),
ref
))
return
mc
.
Observe
(
gce
.
c
.
TargetHttpProxies
()
.
SetUrlMap
(
c
tx
,
meta
.
GlobalKey
(
proxy
.
Name
),
ref
))
}
}
// DeleteTargetHttpProxy deletes the TargetHttpProxy by name.
// DeleteTargetHttpProxy deletes the TargetHttpProxy by name.
func
(
gce
*
GCECloud
)
DeleteTargetHttpProxy
(
name
string
)
error
{
func
(
gce
*
GCECloud
)
DeleteTargetHttpProxy
(
name
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newTargetProxyMetricContext
(
"delete"
)
mc
:=
newTargetProxyMetricContext
(
"delete"
)
return
mc
.
Observe
(
gce
.
c
.
TargetHttpProxies
()
.
Delete
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
)))
return
mc
.
Observe
(
gce
.
c
.
TargetHttpProxies
()
.
Delete
(
c
tx
,
meta
.
GlobalKey
(
name
)))
}
}
// ListTargetHttpProxies lists all TargetHttpProxies in the project.
// ListTargetHttpProxies lists all TargetHttpProxies in the project.
func
(
gce
*
GCECloud
)
ListTargetHttpProxies
()
([]
*
compute
.
TargetHttpProxy
,
error
)
{
func
(
gce
*
GCECloud
)
ListTargetHttpProxies
()
([]
*
compute
.
TargetHttpProxy
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newTargetProxyMetricContext
(
"list"
)
mc
:=
newTargetProxyMetricContext
(
"list"
)
v
,
err
:=
gce
.
c
.
TargetHttpProxies
()
.
List
(
c
ontext
.
Background
()
,
filter
.
None
)
v
,
err
:=
gce
.
c
.
TargetHttpProxies
()
.
List
(
c
tx
,
filter
.
None
)
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
...
@@ -66,42 +80,60 @@ func (gce *GCECloud) ListTargetHttpProxies() ([]*compute.TargetHttpProxy, error)
...
@@ -66,42 +80,60 @@ func (gce *GCECloud) ListTargetHttpProxies() ([]*compute.TargetHttpProxy, error)
// GetTargetHttpsProxy returns the UrlMap by name.
// GetTargetHttpsProxy returns the UrlMap by name.
func
(
gce
*
GCECloud
)
GetTargetHttpsProxy
(
name
string
)
(
*
compute
.
TargetHttpsProxy
,
error
)
{
func
(
gce
*
GCECloud
)
GetTargetHttpsProxy
(
name
string
)
(
*
compute
.
TargetHttpsProxy
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newTargetProxyMetricContext
(
"get"
)
mc
:=
newTargetProxyMetricContext
(
"get"
)
v
,
err
:=
gce
.
c
.
TargetHttpsProxies
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
))
v
,
err
:=
gce
.
c
.
TargetHttpsProxies
()
.
Get
(
c
tx
,
meta
.
GlobalKey
(
name
))
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// CreateTargetHttpsProxy creates a TargetHttpsProxy
// CreateTargetHttpsProxy creates a TargetHttpsProxy
func
(
gce
*
GCECloud
)
CreateTargetHttpsProxy
(
proxy
*
compute
.
TargetHttpsProxy
)
error
{
func
(
gce
*
GCECloud
)
CreateTargetHttpsProxy
(
proxy
*
compute
.
TargetHttpsProxy
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newTargetProxyMetricContext
(
"create"
)
mc
:=
newTargetProxyMetricContext
(
"create"
)
return
mc
.
Observe
(
gce
.
c
.
TargetHttpsProxies
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
proxy
.
Name
),
proxy
))
return
mc
.
Observe
(
gce
.
c
.
TargetHttpsProxies
()
.
Insert
(
c
tx
,
meta
.
GlobalKey
(
proxy
.
Name
),
proxy
))
}
}
// SetUrlMapForTargetHttpsProxy sets the given UrlMap for the given TargetHttpsProxy.
// SetUrlMapForTargetHttpsProxy sets the given UrlMap for the given TargetHttpsProxy.
func
(
gce
*
GCECloud
)
SetUrlMapForTargetHttpsProxy
(
proxy
*
compute
.
TargetHttpsProxy
,
urlMap
*
compute
.
UrlMap
)
error
{
func
(
gce
*
GCECloud
)
SetUrlMapForTargetHttpsProxy
(
proxy
*
compute
.
TargetHttpsProxy
,
urlMap
*
compute
.
UrlMap
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newTargetProxyMetricContext
(
"set_url_map"
)
mc
:=
newTargetProxyMetricContext
(
"set_url_map"
)
ref
:=
&
compute
.
UrlMapReference
{
UrlMap
:
urlMap
.
SelfLink
}
ref
:=
&
compute
.
UrlMapReference
{
UrlMap
:
urlMap
.
SelfLink
}
return
mc
.
Observe
(
gce
.
c
.
TargetHttpsProxies
()
.
SetUrlMap
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
proxy
.
Name
),
ref
))
return
mc
.
Observe
(
gce
.
c
.
TargetHttpsProxies
()
.
SetUrlMap
(
c
tx
,
meta
.
GlobalKey
(
proxy
.
Name
),
ref
))
}
}
// SetSslCertificateForTargetHttpsProxy sets the given SslCertificate for the given TargetHttpsProxy.
// SetSslCertificateForTargetHttpsProxy sets the given SslCertificate for the given TargetHttpsProxy.
func
(
gce
*
GCECloud
)
SetSslCertificateForTargetHttpsProxy
(
proxy
*
compute
.
TargetHttpsProxy
,
sslCert
*
compute
.
SslCertificate
)
error
{
func
(
gce
*
GCECloud
)
SetSslCertificateForTargetHttpsProxy
(
proxy
*
compute
.
TargetHttpsProxy
,
sslCert
*
compute
.
SslCertificate
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newTargetProxyMetricContext
(
"set_ssl_cert"
)
mc
:=
newTargetProxyMetricContext
(
"set_ssl_cert"
)
req
:=
&
compute
.
TargetHttpsProxiesSetSslCertificatesRequest
{
req
:=
&
compute
.
TargetHttpsProxiesSetSslCertificatesRequest
{
SslCertificates
:
[]
string
{
sslCert
.
SelfLink
},
SslCertificates
:
[]
string
{
sslCert
.
SelfLink
},
}
}
return
mc
.
Observe
(
gce
.
c
.
TargetHttpsProxies
()
.
SetSslCertificates
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
proxy
.
Name
),
req
))
return
mc
.
Observe
(
gce
.
c
.
TargetHttpsProxies
()
.
SetSslCertificates
(
c
tx
,
meta
.
GlobalKey
(
proxy
.
Name
),
req
))
}
}
// DeleteTargetHttpsProxy deletes the TargetHttpsProxy by name.
// DeleteTargetHttpsProxy deletes the TargetHttpsProxy by name.
func
(
gce
*
GCECloud
)
DeleteTargetHttpsProxy
(
name
string
)
error
{
func
(
gce
*
GCECloud
)
DeleteTargetHttpsProxy
(
name
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newTargetProxyMetricContext
(
"delete"
)
mc
:=
newTargetProxyMetricContext
(
"delete"
)
return
mc
.
Observe
(
gce
.
c
.
TargetHttpsProxies
()
.
Delete
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
)))
return
mc
.
Observe
(
gce
.
c
.
TargetHttpsProxies
()
.
Delete
(
c
tx
,
meta
.
GlobalKey
(
name
)))
}
}
// ListTargetHttpsProxies lists all TargetHttpsProxies in the project.
// ListTargetHttpsProxies lists all TargetHttpsProxies in the project.
func
(
gce
*
GCECloud
)
ListTargetHttpsProxies
()
([]
*
compute
.
TargetHttpsProxy
,
error
)
{
func
(
gce
*
GCECloud
)
ListTargetHttpsProxies
()
([]
*
compute
.
TargetHttpsProxy
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newTargetProxyMetricContext
(
"list"
)
mc
:=
newTargetProxyMetricContext
(
"list"
)
v
,
err
:=
gce
.
c
.
TargetHttpsProxies
()
.
List
(
c
ontext
.
Background
()
,
filter
.
None
)
v
,
err
:=
gce
.
c
.
TargetHttpsProxies
()
.
List
(
c
tx
,
filter
.
None
)
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
pkg/cloudprovider/providers/gce/gce_urlmap.go
View file @
1f336dda
...
@@ -17,10 +17,9 @@ limitations under the License.
...
@@ -17,10 +17,9 @@ limitations under the License.
package
gce
package
gce
import
(
import
(
"context"
compute
"google.golang.org/api/compute/v1"
compute
"google.golang.org/api/compute/v1"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
)
)
...
@@ -31,32 +30,47 @@ func newUrlMapMetricContext(request string) *metricContext {
...
@@ -31,32 +30,47 @@ func newUrlMapMetricContext(request string) *metricContext {
// GetUrlMap returns the UrlMap by name.
// GetUrlMap returns the UrlMap by name.
func
(
gce
*
GCECloud
)
GetUrlMap
(
name
string
)
(
*
compute
.
UrlMap
,
error
)
{
func
(
gce
*
GCECloud
)
GetUrlMap
(
name
string
)
(
*
compute
.
UrlMap
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newUrlMapMetricContext
(
"get"
)
mc
:=
newUrlMapMetricContext
(
"get"
)
v
,
err
:=
gce
.
c
.
UrlMaps
()
.
Get
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
))
v
,
err
:=
gce
.
c
.
UrlMaps
()
.
Get
(
c
tx
,
meta
.
GlobalKey
(
name
))
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
// CreateUrlMap creates a url map
// CreateUrlMap creates a url map
func
(
gce
*
GCECloud
)
CreateUrlMap
(
urlMap
*
compute
.
UrlMap
)
error
{
func
(
gce
*
GCECloud
)
CreateUrlMap
(
urlMap
*
compute
.
UrlMap
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newUrlMapMetricContext
(
"create"
)
mc
:=
newUrlMapMetricContext
(
"create"
)
return
mc
.
Observe
(
gce
.
c
.
UrlMaps
()
.
Insert
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
urlMap
.
Name
),
urlMap
))
return
mc
.
Observe
(
gce
.
c
.
UrlMaps
()
.
Insert
(
c
tx
,
meta
.
GlobalKey
(
urlMap
.
Name
),
urlMap
))
}
}
// UpdateUrlMap applies the given UrlMap as an update
// UpdateUrlMap applies the given UrlMap as an update
func
(
gce
*
GCECloud
)
UpdateUrlMap
(
urlMap
*
compute
.
UrlMap
)
error
{
func
(
gce
*
GCECloud
)
UpdateUrlMap
(
urlMap
*
compute
.
UrlMap
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newUrlMapMetricContext
(
"update"
)
mc
:=
newUrlMapMetricContext
(
"update"
)
return
mc
.
Observe
(
gce
.
c
.
UrlMaps
()
.
Update
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
urlMap
.
Name
),
urlMap
))
return
mc
.
Observe
(
gce
.
c
.
UrlMaps
()
.
Update
(
c
tx
,
meta
.
GlobalKey
(
urlMap
.
Name
),
urlMap
))
}
}
// DeleteUrlMap deletes a url map by name.
// DeleteUrlMap deletes a url map by name.
func
(
gce
*
GCECloud
)
DeleteUrlMap
(
name
string
)
error
{
func
(
gce
*
GCECloud
)
DeleteUrlMap
(
name
string
)
error
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newUrlMapMetricContext
(
"delete"
)
mc
:=
newUrlMapMetricContext
(
"delete"
)
return
mc
.
Observe
(
gce
.
c
.
UrlMaps
()
.
Delete
(
c
ontext
.
Background
()
,
meta
.
GlobalKey
(
name
)))
return
mc
.
Observe
(
gce
.
c
.
UrlMaps
()
.
Delete
(
c
tx
,
meta
.
GlobalKey
(
name
)))
}
}
// ListUrlMaps lists all UrlMaps in the project.
// ListUrlMaps lists all UrlMaps in the project.
func
(
gce
*
GCECloud
)
ListUrlMaps
()
([]
*
compute
.
UrlMap
,
error
)
{
func
(
gce
*
GCECloud
)
ListUrlMaps
()
([]
*
compute
.
UrlMap
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newUrlMapMetricContext
(
"list"
)
mc
:=
newUrlMapMetricContext
(
"list"
)
v
,
err
:=
gce
.
c
.
UrlMaps
()
.
List
(
c
ontext
.
Background
()
,
filter
.
None
)
v
,
err
:=
gce
.
c
.
UrlMaps
()
.
List
(
c
tx
,
filter
.
None
)
return
v
,
mc
.
Observe
(
err
)
return
v
,
mc
.
Observe
(
err
)
}
}
pkg/cloudprovider/providers/gce/gce_zones.go
View file @
1f336dda
...
@@ -24,6 +24,7 @@ import (
...
@@ -24,6 +24,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/types"
"k8s.io/kubernetes/pkg/cloudprovider"
"k8s.io/kubernetes/pkg/cloudprovider"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
)
)
...
@@ -72,8 +73,11 @@ func (gce *GCECloud) GetZoneByNodeName(ctx context.Context, nodeName types.NodeN
...
@@ -72,8 +73,11 @@ func (gce *GCECloud) GetZoneByNodeName(ctx context.Context, nodeName types.NodeN
// ListZonesInRegion returns all zones in a GCP region
// ListZonesInRegion returns all zones in a GCP region
func
(
gce
*
GCECloud
)
ListZonesInRegion
(
region
string
)
([]
*
compute
.
Zone
,
error
)
{
func
(
gce
*
GCECloud
)
ListZonesInRegion
(
region
string
)
([]
*
compute
.
Zone
,
error
)
{
ctx
,
cancel
:=
cloud
.
ContextWithCallTimeout
()
defer
cancel
()
mc
:=
newZonesMetricContext
(
"list"
,
region
)
mc
:=
newZonesMetricContext
(
"list"
,
region
)
list
,
err
:=
gce
.
c
.
Zones
()
.
List
(
c
ontext
.
Background
()
,
filter
.
Regexp
(
"region"
,
gce
.
getRegionLink
(
region
)))
list
,
err
:=
gce
.
c
.
Zones
()
.
List
(
c
tx
,
filter
.
Regexp
(
"region"
,
gce
.
getRegionLink
(
region
)))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
mc
.
Observe
(
err
)
return
nil
,
mc
.
Observe
(
err
)
}
}
...
...
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