mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Initialize vmSet based on vmType setting and call vmSet interface instead of azureClient
This commit is contained in:
parent
906abde733
commit
af5b079ef7
@ -198,6 +198,7 @@ type Cloud struct {
|
|||||||
operationPollRateLimiter flowcontrol.RateLimiter
|
operationPollRateLimiter flowcontrol.RateLimiter
|
||||||
resourceRequestBackoff wait.Backoff
|
resourceRequestBackoff wait.Backoff
|
||||||
metadata *InstanceMetadata
|
metadata *InstanceMetadata
|
||||||
|
vmSet VMSet
|
||||||
|
|
||||||
// Clients for vmss.
|
// Clients for vmss.
|
||||||
VirtualMachineScaleSetsClient compute.VirtualMachineScaleSetsClient
|
VirtualMachineScaleSetsClient compute.VirtualMachineScaleSetsClient
|
||||||
@ -346,16 +347,16 @@ func NewCloud(configReader io.Reader) (cloudprovider.Interface, error) {
|
|||||||
az.SecurityGroupsClient = securityGroupsClient
|
az.SecurityGroupsClient = securityGroupsClient
|
||||||
|
|
||||||
virtualMachineScaleSetVMsClient := compute.NewVirtualMachineScaleSetVMsClient(az.SubscriptionID)
|
virtualMachineScaleSetVMsClient := compute.NewVirtualMachineScaleSetVMsClient(az.SubscriptionID)
|
||||||
az.VirtualMachineScaleSetVMsClient.BaseURI = az.Environment.ResourceManagerEndpoint
|
virtualMachineScaleSetVMsClient.BaseURI = az.Environment.ResourceManagerEndpoint
|
||||||
az.VirtualMachineScaleSetVMsClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
virtualMachineScaleSetVMsClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||||
az.VirtualMachineScaleSetVMsClient.PollingDelay = 5 * time.Second
|
virtualMachineScaleSetVMsClient.PollingDelay = 5 * time.Second
|
||||||
configureUserAgent(&virtualMachineScaleSetVMsClient.Client)
|
configureUserAgent(&virtualMachineScaleSetVMsClient.Client)
|
||||||
az.VirtualMachineScaleSetVMsClient = virtualMachineScaleSetVMsClient
|
az.VirtualMachineScaleSetVMsClient = virtualMachineScaleSetVMsClient
|
||||||
|
|
||||||
virtualMachineScaleSetsClient := compute.NewVirtualMachineScaleSetsClient(az.SubscriptionID)
|
virtualMachineScaleSetsClient := compute.NewVirtualMachineScaleSetsClient(az.SubscriptionID)
|
||||||
az.VirtualMachineScaleSetsClient.BaseURI = az.Environment.ResourceManagerEndpoint
|
virtualMachineScaleSetsClient.BaseURI = az.Environment.ResourceManagerEndpoint
|
||||||
az.VirtualMachineScaleSetsClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
virtualMachineScaleSetsClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||||
az.VirtualMachineScaleSetsClient.PollingDelay = 5 * time.Second
|
virtualMachineScaleSetsClient.PollingDelay = 5 * time.Second
|
||||||
configureUserAgent(&virtualMachineScaleSetsClient.Client)
|
configureUserAgent(&virtualMachineScaleSetsClient.Client)
|
||||||
az.VirtualMachineScaleSetsClient = virtualMachineScaleSetsClient
|
az.VirtualMachineScaleSetsClient = virtualMachineScaleSetsClient
|
||||||
|
|
||||||
@ -421,6 +422,12 @@ func NewCloud(configReader io.Reader) (cloudprovider.Interface, error) {
|
|||||||
az.MaximumLoadBalancerRuleCount = maximumLoadBalancerRuleCount
|
az.MaximumLoadBalancerRuleCount = maximumLoadBalancerRuleCount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if az.Config.VMType == vmTypeVMSS {
|
||||||
|
az.vmSet = newScaleSet(&az)
|
||||||
|
} else {
|
||||||
|
az.vmSet = newAvailabilitySet(&az)
|
||||||
|
}
|
||||||
|
|
||||||
if err := initDiskControllers(&az); err != nil {
|
if err := initDiskControllers(&az); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
"k8s.io/kubernetes/pkg/cloudprovider"
|
"k8s.io/kubernetes/pkg/cloudprovider"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/arm/compute"
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
)
|
)
|
||||||
@ -48,6 +47,7 @@ func (az *Cloud) NodeAddresses(name types.NodeName) ([]v1.NodeAddress, error) {
|
|||||||
}
|
}
|
||||||
return addresses, nil
|
return addresses, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ip, err := az.GetIPForMachineWithRetry(name)
|
ip, err := az.GetIPForMachineWithRetry(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(2).Infof("NodeAddresses(%s) abort backoff", name)
|
glog.V(2).Infof("NodeAddresses(%s) abort backoff", name)
|
||||||
@ -64,7 +64,7 @@ func (az *Cloud) NodeAddresses(name types.NodeName) ([]v1.NodeAddress, error) {
|
|||||||
// This method will not be called from the node that is requesting this ID. i.e. metadata service
|
// 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
|
// and other local methods cannot be used here
|
||||||
func (az *Cloud) NodeAddressesByProviderID(providerID string) ([]v1.NodeAddress, error) {
|
func (az *Cloud) NodeAddressesByProviderID(providerID string) ([]v1.NodeAddress, error) {
|
||||||
name, err := splitProviderID(providerID)
|
name, err := az.vmSet.GetNodeNameByProviderID(providerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ func (az *Cloud) ExternalID(name types.NodeName) (string, error) {
|
|||||||
// InstanceExistsByProviderID returns true if the instance with the given provider id still exists and is running.
|
// InstanceExistsByProviderID returns true if the instance with the given provider id still exists and is running.
|
||||||
// If false is returned with no error, the instance will be immediately deleted by the cloud controller manager.
|
// If false is returned with no error, the instance will be immediately deleted by the cloud controller manager.
|
||||||
func (az *Cloud) InstanceExistsByProviderID(providerID string) (bool, error) {
|
func (az *Cloud) InstanceExistsByProviderID(providerID string) (bool, error) {
|
||||||
name, err := splitProviderID(providerID)
|
name, err := az.vmSet.GetNodeNameByProviderID(providerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@ -118,70 +118,14 @@ func (az *Cloud) InstanceID(name types.NodeName) (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if az.Config.VMType == vmTypeVMSS {
|
return az.vmSet.GetInstanceIDByNodeName(string(name))
|
||||||
id, err := az.getVmssInstanceID(name)
|
|
||||||
if err == cloudprovider.InstanceNotFound || err == ErrorNotVmssInstance {
|
|
||||||
// Retry with standard type because master nodes may not belong to any vmss.
|
|
||||||
return az.getStandardInstanceID(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
return id, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return az.getStandardInstanceID(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (az *Cloud) getVmssInstanceID(name types.NodeName) (string, error) {
|
|
||||||
var machine compute.VirtualMachineScaleSetVM
|
|
||||||
var exists bool
|
|
||||||
var err error
|
|
||||||
az.operationPollRateLimiter.Accept()
|
|
||||||
machine, exists, err = az.getVmssVirtualMachine(name)
|
|
||||||
if err != nil {
|
|
||||||
if az.CloudProviderBackoff {
|
|
||||||
glog.V(2).Infof("InstanceID(%s) backing off", name)
|
|
||||||
machine, exists, err = az.GetScaleSetsVMWithRetry(name)
|
|
||||||
if err != nil {
|
|
||||||
glog.V(2).Infof("InstanceID(%s) abort backoff", name)
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
} else if !exists {
|
|
||||||
return "", cloudprovider.InstanceNotFound
|
|
||||||
}
|
|
||||||
return *machine.ID, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (az *Cloud) getStandardInstanceID(name types.NodeName) (string, error) {
|
|
||||||
var machine compute.VirtualMachine
|
|
||||||
var exists bool
|
|
||||||
var err error
|
|
||||||
az.operationPollRateLimiter.Accept()
|
|
||||||
machine, exists, err = az.getVirtualMachine(name)
|
|
||||||
if err != nil {
|
|
||||||
if az.CloudProviderBackoff {
|
|
||||||
glog.V(2).Infof("InstanceID(%s) backing off", name)
|
|
||||||
machine, exists, err = az.GetVirtualMachineWithRetry(name)
|
|
||||||
if err != nil {
|
|
||||||
glog.V(2).Infof("InstanceID(%s) abort backoff", name)
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
} else if !exists {
|
|
||||||
return "", cloudprovider.InstanceNotFound
|
|
||||||
}
|
|
||||||
return *machine.ID, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// InstanceTypeByProviderID returns the cloudprovider instance type of the node with the specified unique providerID
|
// 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
|
// 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
|
// and other local methods cannot be used here
|
||||||
func (az *Cloud) InstanceTypeByProviderID(providerID string) (string, error) {
|
func (az *Cloud) InstanceTypeByProviderID(providerID string) (string, error) {
|
||||||
name, err := splitProviderID(providerID)
|
name, err := az.vmSet.GetNodeNameByProviderID(providerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -207,46 +151,7 @@ func (az *Cloud) InstanceType(name types.NodeName) (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if az.Config.VMType == vmTypeVMSS {
|
return az.vmSet.GetInstanceTypeByNodeName(string(name))
|
||||||
machineType, err := az.getVmssInstanceType(name)
|
|
||||||
if err == cloudprovider.InstanceNotFound || err == ErrorNotVmssInstance {
|
|
||||||
// Retry with standard type because master nodes may not belong to any vmss.
|
|
||||||
return az.getStandardInstanceType(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
return machineType, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return az.getStandardInstanceType(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// getVmssInstanceType gets instance with type vmss.
|
|
||||||
func (az *Cloud) getVmssInstanceType(name types.NodeName) (string, error) {
|
|
||||||
machine, exists, err := az.getVmssVirtualMachine(name)
|
|
||||||
if err != nil {
|
|
||||||
glog.Errorf("error: az.InstanceType(%s), az.getVmssVirtualMachine(%s) err=%v", name, name, err)
|
|
||||||
return "", err
|
|
||||||
} else if !exists {
|
|
||||||
return "", cloudprovider.InstanceNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
if machine.Sku.Name != nil {
|
|
||||||
return *machine.Sku.Name, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return "", fmt.Errorf("instance type is not set")
|
|
||||||
}
|
|
||||||
|
|
||||||
// getStandardInstanceType gets instance with standard type.
|
|
||||||
func (az *Cloud) getStandardInstanceType(name types.NodeName) (string, error) {
|
|
||||||
machine, exists, err := az.getVirtualMachine(name)
|
|
||||||
if err != nil {
|
|
||||||
glog.Errorf("error: az.InstanceType(%s), az.getVirtualMachine(%s) err=%v", name, name, err)
|
|
||||||
return "", err
|
|
||||||
} else if !exists {
|
|
||||||
return "", cloudprovider.InstanceNotFound
|
|
||||||
}
|
|
||||||
return string(machine.HardwareProfile.VMSize), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddSSHKeyToAllInstances adds an SSH public key as a legal identity for all instances
|
// AddSSHKeyToAllInstances adds an SSH public key as a legal identity for all instances
|
||||||
@ -255,8 +160,8 @@ func (az *Cloud) AddSSHKeyToAllInstances(user string, keyData []byte) error {
|
|||||||
return fmt.Errorf("not supported")
|
return fmt.Errorf("not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
// CurrentNodeName returns the name of the node we are currently running on
|
// CurrentNodeName returns the name of the node we are currently running on.
|
||||||
// On most clouds (e.g. GCE) this is the hostname, so we provide the hostname
|
// On Azure this is the hostname, so we just return the hostname.
|
||||||
func (az *Cloud) CurrentNodeName(hostname string) (types.NodeName, error) {
|
func (az *Cloud) CurrentNodeName(hostname string) (types.NodeName, error) {
|
||||||
return types.NodeName(hostname), nil
|
return types.NodeName(hostname), nil
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,10 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/kubernetes/pkg/cloudprovider"
|
"k8s.io/kubernetes/pkg/cloudprovider"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/arm/compute"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const instanceInfoURL = "http://169.254.169.254/metadata/v1/InstanceInfo"
|
const instanceInfoURL = "http://169.254.169.254/metadata/v1/InstanceInfo"
|
||||||
@ -63,10 +60,11 @@ func (az *Cloud) GetZone() (cloudprovider.Zone, error) {
|
|||||||
// This is particularly useful in external cloud providers where the kubelet
|
// This is particularly useful in external cloud providers where the kubelet
|
||||||
// does not initialize node data.
|
// does not initialize node data.
|
||||||
func (az *Cloud) GetZoneByProviderID(providerID string) (cloudprovider.Zone, error) {
|
func (az *Cloud) GetZoneByProviderID(providerID string) (cloudprovider.Zone, error) {
|
||||||
nodeName, err := splitProviderID(providerID)
|
nodeName, err := az.vmSet.GetNodeNameByProviderID(providerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cloudprovider.Zone{}, err
|
return cloudprovider.Zone{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return az.GetZoneByNodeName(nodeName)
|
return az.GetZoneByNodeName(nodeName)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,20 +72,7 @@ func (az *Cloud) GetZoneByProviderID(providerID string) (cloudprovider.Zone, err
|
|||||||
// This is particularly useful in external cloud providers where the kubelet
|
// This is particularly useful in external cloud providers where the kubelet
|
||||||
// does not initialize node data.
|
// does not initialize node data.
|
||||||
func (az *Cloud) GetZoneByNodeName(nodeName types.NodeName) (cloudprovider.Zone, error) {
|
func (az *Cloud) GetZoneByNodeName(nodeName types.NodeName) (cloudprovider.Zone, error) {
|
||||||
|
return az.vmSet.GetZoneByNodeName(string(nodeName))
|
||||||
vm, err := az.VirtualMachinesClient.Get(az.ResourceGroup, string(nodeName), compute.InstanceView)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return cloudprovider.Zone{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
failureDomain := strconv.Itoa(int(*vm.VirtualMachineProperties.InstanceView.PlatformFaultDomain))
|
|
||||||
|
|
||||||
zone := cloudprovider.Zone{
|
|
||||||
FailureDomain: failureDomain,
|
|
||||||
Region: *(vm.Location),
|
|
||||||
}
|
|
||||||
return zone, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchFaultDomain() (*string, error) {
|
func fetchFaultDomain() (*string, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user