2016-05-29 03:54:26 +00:00
|
|
|
/*
|
|
|
|
Copyright 2016 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 azure
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2017-06-22 17:25:57 +00:00
|
|
|
"k8s.io/api/core/v1"
|
2016-05-29 03:54:26 +00:00
|
|
|
"k8s.io/kubernetes/pkg/cloudprovider"
|
|
|
|
|
2017-06-05 23:06:50 +00:00
|
|
|
"github.com/golang/glog"
|
2017-01-11 14:09:48 +00:00
|
|
|
"k8s.io/apimachinery/pkg/types"
|
2016-05-29 03:54:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// NodeAddresses returns the addresses of the specified instance.
|
2016-11-18 20:58:42 +00:00
|
|
|
func (az *Cloud) NodeAddresses(name types.NodeName) ([]v1.NodeAddress, error) {
|
2017-11-16 23:04:08 +00:00
|
|
|
ip, err := az.GetIPForMachineWithRetry(name)
|
2016-05-29 03:54:26 +00:00
|
|
|
if err != nil {
|
2017-11-16 23:04:08 +00:00
|
|
|
glog.V(2).Infof("NodeAddresses(%s) abort backoff", name)
|
|
|
|
return nil, err
|
2016-05-29 03:54:26 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 20:58:42 +00:00
|
|
|
return []v1.NodeAddress{
|
|
|
|
{Type: v1.NodeInternalIP, Address: ip},
|
|
|
|
{Type: v1.NodeHostName, Address: string(name)},
|
2016-05-29 03:54:26 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2017-03-06 21:33:26 +00:00
|
|
|
// NodeAddressesByProviderID returns the node addresses of an instances with the specified unique providerID
|
|
|
|
// This method will not be called from the node that is requesting this ID. i.e. metadata service
|
|
|
|
// and other local methods cannot be used here
|
|
|
|
func (az *Cloud) NodeAddressesByProviderID(providerID string) ([]v1.NodeAddress, error) {
|
2017-12-13 06:19:47 +00:00
|
|
|
name, err := az.vmSet.GetNodeNameByProviderID(providerID)
|
2017-05-31 21:21:39 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return az.NodeAddresses(name)
|
2017-03-06 21:33:26 +00:00
|
|
|
}
|
|
|
|
|
2016-05-29 03:54:26 +00:00
|
|
|
// ExternalID returns the cloud provider ID of the specified instance (deprecated).
|
2016-07-16 06:10:29 +00:00
|
|
|
func (az *Cloud) ExternalID(name types.NodeName) (string, error) {
|
2016-05-29 03:54:26 +00:00
|
|
|
return az.InstanceID(name)
|
|
|
|
}
|
|
|
|
|
2017-08-21 18:55:43 +00:00
|
|
|
// InstanceExistsByProviderID returns true if the instance with the given provider id still exists and is running.
|
2017-08-25 22:04:10 +00:00
|
|
|
// If false is returned with no error, the instance will be immediately deleted by the cloud controller manager.
|
2017-08-21 18:55:43 +00:00
|
|
|
func (az *Cloud) InstanceExistsByProviderID(providerID string) (bool, error) {
|
2017-12-13 06:19:47 +00:00
|
|
|
name, err := az.vmSet.GetNodeNameByProviderID(providerID)
|
2017-10-20 06:59:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = az.InstanceID(name)
|
|
|
|
if err != nil {
|
|
|
|
if err == cloudprovider.InstanceNotFound {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return true, nil
|
2017-08-21 18:55:43 +00:00
|
|
|
}
|
|
|
|
|
2016-05-29 03:54:26 +00:00
|
|
|
// InstanceID returns the cloud provider ID of the specified instance.
|
|
|
|
// Note that if the instance does not exist or is no longer running, we must return ("", cloudprovider.InstanceNotFound)
|
2016-07-16 06:10:29 +00:00
|
|
|
func (az *Cloud) InstanceID(name types.NodeName) (string, error) {
|
2017-12-13 06:19:47 +00:00
|
|
|
return az.vmSet.GetInstanceIDByNodeName(string(name))
|
2016-05-29 03:54:26 +00:00
|
|
|
}
|
|
|
|
|
2017-03-06 21:33:26 +00:00
|
|
|
// InstanceTypeByProviderID returns the cloudprovider instance type of the node with the specified unique providerID
|
|
|
|
// This method will not be called from the node that is requesting this ID. i.e. metadata service
|
|
|
|
// and other local methods cannot be used here
|
|
|
|
func (az *Cloud) InstanceTypeByProviderID(providerID string) (string, error) {
|
2017-12-13 06:19:47 +00:00
|
|
|
name, err := az.vmSet.GetNodeNameByProviderID(providerID)
|
2017-05-31 21:21:39 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2017-08-30 05:00:21 +00:00
|
|
|
return az.InstanceType(name)
|
2017-03-06 21:33:26 +00:00
|
|
|
}
|
|
|
|
|
2016-05-29 03:54:26 +00:00
|
|
|
// InstanceType returns the type of the specified instance.
|
|
|
|
// Note that if the instance does not exist or is no longer running, we must return ("", cloudprovider.InstanceNotFound)
|
|
|
|
// (Implementer Note): This is used by kubelet. Kubelet will label the node. Real log from kubelet:
|
|
|
|
// Adding node label from cloud provider: beta.kubernetes.io/instance-type=[value]
|
2016-07-16 06:10:29 +00:00
|
|
|
func (az *Cloud) InstanceType(name types.NodeName) (string, error) {
|
2017-12-13 06:19:47 +00:00
|
|
|
return az.vmSet.GetInstanceTypeByNodeName(string(name))
|
2016-05-29 03:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddSSHKeyToAllInstances adds an SSH public key as a legal identity for all instances
|
|
|
|
// expected format for the key is standard ssh-keygen format: <protocol> <blob>
|
|
|
|
func (az *Cloud) AddSSHKeyToAllInstances(user string, keyData []byte) error {
|
|
|
|
return fmt.Errorf("not supported")
|
|
|
|
}
|
|
|
|
|
2017-12-13 06:19:47 +00:00
|
|
|
// CurrentNodeName returns the name of the node we are currently running on.
|
|
|
|
// On Azure this is the hostname, so we just return the hostname.
|
2016-07-16 06:10:29 +00:00
|
|
|
func (az *Cloud) CurrentNodeName(hostname string) (types.NodeName, error) {
|
|
|
|
return types.NodeName(hostname), nil
|
2016-05-29 03:54:26 +00:00
|
|
|
}
|
|
|
|
|
2016-07-16 06:10:29 +00:00
|
|
|
// mapNodeNameToVMName maps a k8s NodeName to an Azure VM Name
|
|
|
|
// This is a simple string cast.
|
|
|
|
func mapNodeNameToVMName(nodeName types.NodeName) string {
|
|
|
|
return string(nodeName)
|
|
|
|
}
|