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
f62a2a1b
Commit
f62a2a1b
authored
Jun 09, 2015
by
krousey
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9451 from cjcullen/mig
Use Node IP Address instead of Node.Name in minion.ResourceLocation.
parents
1c58d2a7
2d85e4a0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
25 deletions
+47
-25
server.go
cmd/kubelet/app/server.go
+3
-2
gce.go
pkg/cloudprovider/gce/gce.go
+10
-6
kubelet.go
pkg/kubelet/kubelet.go
+2
-15
rest.go
pkg/registry/minion/rest.go
+6
-1
node.go
pkg/util/node/node.go
+26
-1
No files found.
cmd/kubelet/app/server.go
View file @
f62a2a1b
...
@@ -48,6 +48,7 @@ import (
...
@@ -48,6 +48,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/master/ports"
"github.com/GoogleCloudPlatform/kubernetes/pkg/master/ports"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
nodeutil
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/node"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
...
@@ -383,7 +384,7 @@ func (s *KubeletServer) InitializeTLS() (*kubelet.TLSOptions, error) {
...
@@ -383,7 +384,7 @@ func (s *KubeletServer) InitializeTLS() (*kubelet.TLSOptions, error) {
if
s
.
TLSCertFile
==
""
&&
s
.
TLSPrivateKeyFile
==
""
{
if
s
.
TLSCertFile
==
""
&&
s
.
TLSPrivateKeyFile
==
""
{
s
.
TLSCertFile
=
path
.
Join
(
s
.
CertDirectory
,
"kubelet.crt"
)
s
.
TLSCertFile
=
path
.
Join
(
s
.
CertDirectory
,
"kubelet.crt"
)
s
.
TLSPrivateKeyFile
=
path
.
Join
(
s
.
CertDirectory
,
"kubelet.key"
)
s
.
TLSPrivateKeyFile
=
path
.
Join
(
s
.
CertDirectory
,
"kubelet.key"
)
if
err
:=
util
.
GenerateSelfSignedCert
(
util
.
GetHostname
(
s
.
HostnameOverride
),
s
.
TLSCertFile
,
s
.
TLSPrivateKeyFile
);
err
!=
nil
{
if
err
:=
util
.
GenerateSelfSignedCert
(
node
util
.
GetHostname
(
s
.
HostnameOverride
),
s
.
TLSCertFile
,
s
.
TLSPrivateKeyFile
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"unable to generate self signed cert: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"unable to generate self signed cert: %v"
,
err
)
}
}
glog
.
V
(
4
)
.
Infof
(
"Using self-signed cert (%s, %s)"
,
s
.
TLSCertFile
,
s
.
TLSPrivateKeyFile
)
glog
.
V
(
4
)
.
Infof
(
"Using self-signed cert (%s, %s)"
,
s
.
TLSCertFile
,
s
.
TLSPrivateKeyFile
)
...
@@ -554,7 +555,7 @@ func SimpleKubelet(client *client.Client,
...
@@ -554,7 +555,7 @@ func SimpleKubelet(client *client.Client,
// 3 Standalone 'kubernetes' binary
// 3 Standalone 'kubernetes' binary
// Eventually, #2 will be replaced with instances of #3
// Eventually, #2 will be replaced with instances of #3
func
RunKubelet
(
kcfg
*
KubeletConfig
,
builder
KubeletBuilder
)
error
{
func
RunKubelet
(
kcfg
*
KubeletConfig
,
builder
KubeletBuilder
)
error
{
kcfg
.
Hostname
=
util
.
GetHostname
(
kcfg
.
HostnameOverride
)
kcfg
.
Hostname
=
node
util
.
GetHostname
(
kcfg
.
HostnameOverride
)
eventBroadcaster
:=
record
.
NewBroadcaster
()
eventBroadcaster
:=
record
.
NewBroadcaster
()
kcfg
.
Recorder
=
eventBroadcaster
.
NewRecorder
(
api
.
EventSource
{
Component
:
"kubelet"
,
Host
:
kcfg
.
Hostname
})
kcfg
.
Recorder
=
eventBroadcaster
.
NewRecorder
(
api
.
EventSource
{
Component
:
"kubelet"
,
Host
:
kcfg
.
Hostname
})
eventBroadcaster
.
StartLogging
(
glog
.
Infof
)
eventBroadcaster
.
StartLogging
(
glog
.
Infof
)
...
...
pkg/cloudprovider/gce/gce.go
View file @
f62a2a1b
...
@@ -43,9 +43,11 @@ import (
...
@@ -43,9 +43,11 @@ import (
"google.golang.org/cloud/compute/metadata"
"google.golang.org/cloud/compute/metadata"
)
)
const
ProviderName
=
"gce"
const
(
ProviderName
=
"gce"
const
EXTERNAL_IP_METADATA_URL
=
"http://169.254.169.254/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip"
EXTERNAL_IP_METADATA_URL
=
"http://169.254.169.254/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip"
INTERNAL_IP_METADATA_URL
=
"http://169.254.169.254/computeMetadata/v1/instance/network-interfaces/0/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
{
...
@@ -524,15 +526,17 @@ func addKey(metadataBefore, keyString string) string {
...
@@ -524,15 +526,17 @@ func addKey(metadataBefore, keyString string) string {
// NodeAddresses is an implementation of Instances.NodeAddresses.
// NodeAddresses is an implementation of Instances.NodeAddresses.
func
(
gce
*
GCECloud
)
NodeAddresses
(
_
string
)
([]
api
.
NodeAddress
,
error
)
{
func
(
gce
*
GCECloud
)
NodeAddresses
(
_
string
)
([]
api
.
NodeAddress
,
error
)
{
internalIP
,
err
:=
gce
.
metadataAccess
(
INTERNAL_IP_METADATA_URL
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"couldn't get internal IP: %v"
,
err
)
}
externalIP
,
err
:=
gce
.
metadataAccess
(
EXTERNAL_IP_METADATA_URL
)
externalIP
,
err
:=
gce
.
metadataAccess
(
EXTERNAL_IP_METADATA_URL
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"couldn't get external IP: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"couldn't get external IP: %v"
,
err
)
}
}
return
[]
api
.
NodeAddress
{
return
[]
api
.
NodeAddress
{
{
Type
:
api
.
NodeInternalIP
,
Address
:
internalIP
},
{
Type
:
api
.
NodeExternalIP
,
Address
:
externalIP
},
{
Type
:
api
.
NodeExternalIP
,
Address
:
externalIP
},
// TODO(mbforbes): Remove NodeLegacyHostIP once v1beta1 is removed.
{
Type
:
api
.
NodeLegacyHostIP
,
Address
:
externalIP
},
},
nil
},
nil
}
}
...
...
pkg/kubelet/kubelet.go
View file @
f62a2a1b
...
@@ -54,6 +54,7 @@ import (
...
@@ -54,6 +54,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
utilErrors
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors"
utilErrors
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
nodeutil
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/node"
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
...
@@ -1723,21 +1724,7 @@ func (kl *Kubelet) GetHostIP() (net.IP, error) {
...
@@ -1723,21 +1724,7 @@ func (kl *Kubelet) GetHostIP() (net.IP, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"cannot get node: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"cannot get node: %v"
,
err
)
}
}
addresses
:=
node
.
Status
.
Addresses
return
nodeutil
.
GetNodeHostIP
(
node
)
addressMap
:=
make
(
map
[
api
.
NodeAddressType
][]
api
.
NodeAddress
)
for
i
:=
range
addresses
{
addressMap
[
addresses
[
i
]
.
Type
]
=
append
(
addressMap
[
addresses
[
i
]
.
Type
],
addresses
[
i
])
}
if
addresses
,
ok
:=
addressMap
[
api
.
NodeLegacyHostIP
];
ok
{
return
net
.
ParseIP
(
addresses
[
0
]
.
Address
),
nil
}
if
addresses
,
ok
:=
addressMap
[
api
.
NodeInternalIP
];
ok
{
return
net
.
ParseIP
(
addresses
[
0
]
.
Address
),
nil
}
if
addresses
,
ok
:=
addressMap
[
api
.
NodeExternalIP
];
ok
{
return
net
.
ParseIP
(
addresses
[
0
]
.
Address
),
nil
}
return
nil
,
fmt
.
Errorf
(
"host IP unknown; known addresses: %v"
,
addresses
)
}
}
// GetPods returns all pods bound to the kubelet and their spec, and the mirror
// GetPods returns all pods bound to the kubelet and their spec, and the mirror
...
...
pkg/registry/minion/rest.go
View file @
f62a2a1b
...
@@ -34,6 +34,7 @@ import (
...
@@ -34,6 +34,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/fielderrors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/fielderrors"
nodeutil
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/node"
)
)
// nodeStrategy implements behavior for nodes
// nodeStrategy implements behavior for nodes
...
@@ -142,7 +143,11 @@ func ResourceLocation(getter ResourceGetter, connection client.ConnectionInfoGet
...
@@ -142,7 +143,11 @@ func ResourceLocation(getter ResourceGetter, connection client.ConnectionInfoGet
return
nil
,
nil
,
err
return
nil
,
nil
,
err
}
}
node
:=
nodeObj
.
(
*
api
.
Node
)
node
:=
nodeObj
.
(
*
api
.
Node
)
host
:=
node
.
Name
// TODO: use node's IP, don't expect the name to resolve.
hostIP
,
err
:=
nodeutil
.
GetNodeHostIP
(
node
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
host
:=
hostIP
.
String
()
if
portReq
==
""
||
strconv
.
Itoa
(
ports
.
KubeletPort
)
==
portReq
{
if
portReq
==
""
||
strconv
.
Itoa
(
ports
.
KubeletPort
)
==
portReq
{
scheme
,
port
,
transport
,
err
:=
connection
.
GetConnectionInfo
(
host
)
scheme
,
port
,
transport
,
err
:=
connection
.
GetConnectionInfo
(
host
)
...
...
pkg/util/node.go
→
pkg/util/node
/node
.go
View file @
f62a2a1b
...
@@ -14,12 +14,15 @@ See the License for the specific language governing permissions and
...
@@ -14,12 +14,15 @@ See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
package
util
package
node
import
(
import
(
"fmt"
"net"
"os/exec"
"os/exec"
"strings"
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/golang/glog"
"github.com/golang/glog"
)
)
...
@@ -34,3 +37,25 @@ func GetHostname(hostnameOverride string) string {
...
@@ -34,3 +37,25 @@ func GetHostname(hostnameOverride string) string {
}
}
return
strings
.
ToLower
(
strings
.
TrimSpace
(
hostname
))
return
strings
.
ToLower
(
strings
.
TrimSpace
(
hostname
))
}
}
// GetNodeHostIP returns the provided node's IP, based on the priority:
// 1. NodeInternalIP
// 2. NodeExternalIP
// 3. NodeLegacyHostIP
func
GetNodeHostIP
(
node
*
api
.
Node
)
(
net
.
IP
,
error
)
{
addresses
:=
node
.
Status
.
Addresses
addressMap
:=
make
(
map
[
api
.
NodeAddressType
][]
api
.
NodeAddress
)
for
i
:=
range
addresses
{
addressMap
[
addresses
[
i
]
.
Type
]
=
append
(
addressMap
[
addresses
[
i
]
.
Type
],
addresses
[
i
])
}
if
addresses
,
ok
:=
addressMap
[
api
.
NodeInternalIP
];
ok
{
return
net
.
ParseIP
(
addresses
[
0
]
.
Address
),
nil
}
if
addresses
,
ok
:=
addressMap
[
api
.
NodeExternalIP
];
ok
{
return
net
.
ParseIP
(
addresses
[
0
]
.
Address
),
nil
}
if
addresses
,
ok
:=
addressMap
[
api
.
NodeLegacyHostIP
];
ok
{
return
net
.
ParseIP
(
addresses
[
0
]
.
Address
),
nil
}
return
nil
,
fmt
.
Errorf
(
"host IP unknown; known addresses: %v"
,
addresses
)
}
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