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
2d37650c
Commit
2d37650c
authored
Apr 30, 2015
by
Brian Grant
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7530 from mbforbes/nodeExternal
Make nodes report their external IP rather than the master's.
parents
f45ef93a
e1c2e6b4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
13 deletions
+12
-13
gce.go
pkg/cloudprovider/gce/gce.go
+12
-13
No files found.
pkg/cloudprovider/gce/gce.go
View file @
2d37650c
...
@@ -42,8 +42,6 @@ import (
...
@@ -42,8 +42,6 @@ import (
"google.golang.org/cloud/compute/metadata"
"google.golang.org/cloud/compute/metadata"
)
)
const
EXTERNAL_IP_METADATA_URL
=
"http://169.254.169.254/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip"
// GCECloud is an implementation of Interface, TCPLoadBalancer and Instances for Google Compute Engine.
// GCECloud is an implementation of Interface, TCPLoadBalancer and Instances for Google Compute Engine.
type
GCECloud
struct
{
type
GCECloud
struct
{
service
*
compute
.
Service
service
*
compute
.
Service
...
@@ -414,27 +412,28 @@ func (gce *GCECloud) getInstanceByName(name string) (*compute.Instance, error) {
...
@@ -414,27 +412,28 @@ func (gce *GCECloud) getInstanceByName(name string) (*compute.Instance, error) {
// NodeAddresses is an implementation of Instances.NodeAddresses.
// NodeAddresses is an implementation of Instances.NodeAddresses.
func
(
gce
*
GCECloud
)
NodeAddresses
(
instance
string
)
([]
api
.
NodeAddress
,
error
)
{
func
(
gce
*
GCECloud
)
NodeAddresses
(
instance
string
)
([]
api
.
NodeAddress
,
error
)
{
externalIP
,
err
:=
gce
.
metadataAccess
(
EXTERNAL_IP_METADATA_URL
)
externalIP
,
err
:=
gce
.
getExternalIP
(
instance
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
fmt
.
Errorf
(
"couldn't get external IP for instance %s: %v"
,
instance
,
err
)
}
}
nodeAddresses
:=
[]
api
.
NodeAddress
{{
Type
:
api
.
NodeExternalIP
,
Address
:
externalIP
}}
if
legacyHostAddress
,
err
:=
gce
.
getLegacyHostAddress
(
instance
);
err
==
nil
{
return
[]
api
.
NodeAddress
{
nodeAddresses
=
append
(
nodeAddresses
,
*
legacyHostAddress
)
{
Type
:
api
.
NodeExternalIP
,
Address
:
externalIP
},
}
// TODO(mbforbes): Remove NodeLegacyHostIP once v1beta1 is removed.
return
nodeAddresses
,
nil
{
Type
:
api
.
NodeLegacyHostIP
,
Address
:
externalIP
},
},
nil
}
}
func
(
gce
*
GCECloud
)
get
LegacyHostAddress
(
instance
string
)
(
*
api
.
NodeAddress
,
error
)
{
func
(
gce
*
GCECloud
)
get
ExternalIP
(
instance
string
)
(
string
,
error
)
{
inst
,
err
:=
gce
.
getInstanceByName
(
instance
)
inst
,
err
:=
gce
.
getInstanceByName
(
instance
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
""
,
err
}
}
ip
:=
net
.
ParseIP
(
inst
.
NetworkInterfaces
[
0
]
.
AccessConfigs
[
0
]
.
NatIP
)
ip
:=
net
.
ParseIP
(
inst
.
NetworkInterfaces
[
0
]
.
AccessConfigs
[
0
]
.
NatIP
)
if
ip
==
nil
{
if
ip
==
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid network IP: %s"
,
inst
.
NetworkInterfaces
[
0
]
.
AccessConfigs
[
0
]
.
NatIP
)
return
""
,
fmt
.
Errorf
(
"invalid network IP: %s"
,
inst
.
NetworkInterfaces
[
0
]
.
AccessConfigs
[
0
]
.
NatIP
)
}
}
return
&
api
.
NodeAddress
{
Type
:
api
.
NodeLegacyHostIP
,
Address
:
ip
.
String
()}
,
nil
return
ip
.
String
()
,
nil
}
}
// ExternalID returns the cloud provider ID of the specified instance.
// ExternalID returns the cloud provider ID of the specified instance.
...
...
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