mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Revert "Use Node IP Address instead of Node.Name in minion.ResourceLocation."
This commit is contained in:
parent
f8bf996000
commit
f72fa67924
@ -48,7 +48,6 @@ 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"
|
||||||
@ -288,7 +287,7 @@ func (s *KubeletServer) Run(_ []string) 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(nodeutil.GetHostname(s.HostnameOverride), s.TLSCertFile, s.TLSPrivateKeyFile); err != nil {
|
if err := util.GenerateSelfSignedCert(util.GetHostname(s.HostnameOverride), s.TLSCertFile, s.TLSPrivateKeyFile); err != nil {
|
||||||
return fmt.Errorf("unable to generate self signed cert: %v", err)
|
return 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)
|
||||||
@ -545,7 +544,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 = nodeutil.GetHostname(kcfg.HostnameOverride)
|
kcfg.Hostname = 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)
|
||||||
|
@ -42,11 +42,9 @@ import (
|
|||||||
"google.golang.org/cloud/compute/metadata"
|
"google.golang.org/cloud/compute/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const ProviderName = "gce"
|
||||||
ProviderName = "gce"
|
|
||||||
EXTERNAL_IP_METADATA_URL = "http://169.254.169.254/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip"
|
const 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 {
|
||||||
@ -478,17 +476,15 @@ 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(_ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,6 @@ 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"
|
||||||
@ -1724,7 +1723,21 @@ 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)
|
||||||
}
|
}
|
||||||
return nodeutil.GetNodeHostIP(node)
|
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.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
|
||||||
|
@ -33,7 +33,6 @@ 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,16 +141,13 @@ func ResourceLocation(getter ResourceGetter, connection client.ConnectionInfoGet
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
node := nodeObj.(*api.Node)
|
node := nodeObj.(*api.Node)
|
||||||
hostIP, err := nodeutil.GetNodeHostIP(node)
|
host := node.Name // TODO: use node's IP, don't expect the name to resolve.
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if portReq != "" {
|
if portReq != "" {
|
||||||
return &url.URL{Host: net.JoinHostPort(hostIP.String(), portReq)}, nil, nil
|
return &url.URL{Host: net.JoinHostPort(host, portReq)}, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
scheme, port, transport, err := connection.GetConnectionInfo(hostIP.String())
|
scheme, port, transport, err := connection.GetConnectionInfo(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@ -159,7 +155,7 @@ func ResourceLocation(getter ResourceGetter, connection client.ConnectionInfoGet
|
|||||||
return &url.URL{
|
return &url.URL{
|
||||||
Scheme: scheme,
|
Scheme: scheme,
|
||||||
Host: net.JoinHostPort(
|
Host: net.JoinHostPort(
|
||||||
hostIP.String(),
|
host,
|
||||||
strconv.FormatUint(uint64(port), 10),
|
strconv.FormatUint(uint64(port), 10),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
@ -14,15 +14,12 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package node
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,21 +34,3 @@ 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
|
|
||||||
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
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("host IP unknown; known addresses: %v", addresses)
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user