mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Update azure cloud provider for new azure SDK
This commit is contained in:
parent
8d90cadc0b
commit
a8c5c8123e
@ -68,7 +68,7 @@ func (az *Cloud) InstanceType(name types.NodeName) (string, error) {
|
||||
} else if !exists {
|
||||
return "", cloudprovider.InstanceNotFound
|
||||
}
|
||||
return string(machine.Properties.HardwareProfile.VMSize), nil
|
||||
return string(machine.HardwareProfile.VMSize), nil
|
||||
}
|
||||
|
||||
// List lists instances that match 'filter' which is a regular expression which must match the entire instance name (fqdn)
|
||||
|
@ -57,7 +57,7 @@ func (az *Cloud) GetLoadBalancer(clusterName string, service *v1.Service) (statu
|
||||
}
|
||||
|
||||
return &v1.LoadBalancerStatus{
|
||||
Ingress: []v1.LoadBalancerIngress{{IP: *pip.Properties.IPAddress}},
|
||||
Ingress: []v1.LoadBalancerIngress{{IP: *pip.IPAddress}},
|
||||
}, true, nil
|
||||
}
|
||||
|
||||
@ -95,9 +95,9 @@ func (az *Cloud) EnsureLoadBalancer(clusterName string, service *v1.Service, nod
|
||||
}
|
||||
if !existsLb {
|
||||
lb = network.LoadBalancer{
|
||||
Name: &lbName,
|
||||
Location: &az.Location,
|
||||
Properties: &network.LoadBalancerPropertiesFormat{},
|
||||
Name: &lbName,
|
||||
Location: &az.Location,
|
||||
LoadBalancerPropertiesFormat: &network.LoadBalancerPropertiesFormat{},
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,9 +134,9 @@ func (az *Cloud) EnsureLoadBalancer(clusterName string, service *v1.Service, nod
|
||||
return nil, utilerrors.Flatten(errs)
|
||||
}
|
||||
|
||||
glog.V(2).Infof("ensure(%s): FINISH - %s", serviceName, *pip.Properties.IPAddress)
|
||||
glog.V(2).Infof("ensure(%s): FINISH - %s", serviceName, *pip.IPAddress)
|
||||
return &v1.LoadBalancerStatus{
|
||||
Ingress: []v1.LoadBalancerIngress{{IP: *pip.Properties.IPAddress}},
|
||||
Ingress: []v1.LoadBalancerIngress{{IP: *pip.IPAddress}},
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -172,7 +172,7 @@ func (az *Cloud) EnsureLoadBalancerDeleted(clusterName string, service *v1.Servi
|
||||
return reconcileErr
|
||||
}
|
||||
if lbNeedsUpdate {
|
||||
if len(*lb.Properties.FrontendIPConfigurations) > 0 {
|
||||
if len(*lb.FrontendIPConfigurations) > 0 {
|
||||
glog.V(3).Infof("delete(%s): lb(%s) - updating", serviceName, lbName)
|
||||
_, err = az.LoadBalancerClient.CreateOrUpdate(az.ResourceGroup, *lb.Name, lb, nil)
|
||||
if err != nil {
|
||||
@ -227,7 +227,7 @@ func (az *Cloud) ensurePublicIPExists(serviceName, pipName string) (*network.Pub
|
||||
|
||||
pip.Name = to.StringPtr(pipName)
|
||||
pip.Location = to.StringPtr(az.Location)
|
||||
pip.Properties = &network.PublicIPAddressPropertiesFormat{
|
||||
pip.PublicIPAddressPropertiesFormat = &network.PublicIPAddressPropertiesFormat{
|
||||
PublicIPAllocationMethod: network.Static,
|
||||
}
|
||||
pip.Tags = &map[string]*string{"service": &serviceName}
|
||||
@ -273,8 +273,8 @@ func (az *Cloud) reconcileLoadBalancer(lb network.LoadBalancer, pip *network.Pub
|
||||
// Ensure LoadBalancer's Backend Pool Configuration
|
||||
if wantLb {
|
||||
newBackendPools := []network.BackendAddressPool{}
|
||||
if lb.Properties.BackendAddressPools != nil {
|
||||
newBackendPools = *lb.Properties.BackendAddressPools
|
||||
if lb.BackendAddressPools != nil {
|
||||
newBackendPools = *lb.BackendAddressPools
|
||||
}
|
||||
|
||||
foundBackendPool := false
|
||||
@ -294,15 +294,15 @@ func (az *Cloud) reconcileLoadBalancer(lb network.LoadBalancer, pip *network.Pub
|
||||
glog.V(10).Infof("reconcile(%s)(%t): lb backendpool - adding backendpool", serviceName, wantLb)
|
||||
|
||||
dirtyLb = true
|
||||
lb.Properties.BackendAddressPools = &newBackendPools
|
||||
lb.BackendAddressPools = &newBackendPools
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure LoadBalancer's Frontend IP Configurations
|
||||
dirtyConfigs := false
|
||||
newConfigs := []network.FrontendIPConfiguration{}
|
||||
if lb.Properties.FrontendIPConfigurations != nil {
|
||||
newConfigs = *lb.Properties.FrontendIPConfigurations
|
||||
if lb.FrontendIPConfigurations != nil {
|
||||
newConfigs = *lb.FrontendIPConfigurations
|
||||
}
|
||||
if !wantLb {
|
||||
for i := len(newConfigs) - 1; i >= 0; i-- {
|
||||
@ -325,7 +325,7 @@ func (az *Cloud) reconcileLoadBalancer(lb network.LoadBalancer, pip *network.Pub
|
||||
newConfigs = append(newConfigs,
|
||||
network.FrontendIPConfiguration{
|
||||
Name: to.StringPtr(lbFrontendIPConfigName),
|
||||
Properties: &network.FrontendIPConfigurationPropertiesFormat{
|
||||
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &network.PublicIPAddress{
|
||||
ID: pip.ID,
|
||||
},
|
||||
@ -337,7 +337,7 @@ func (az *Cloud) reconcileLoadBalancer(lb network.LoadBalancer, pip *network.Pub
|
||||
}
|
||||
if dirtyConfigs {
|
||||
dirtyLb = true
|
||||
lb.Properties.FrontendIPConfigurations = &newConfigs
|
||||
lb.FrontendIPConfigurations = &newConfigs
|
||||
}
|
||||
|
||||
// update probes/rules
|
||||
@ -356,7 +356,7 @@ func (az *Cloud) reconcileLoadBalancer(lb network.LoadBalancer, pip *network.Pub
|
||||
|
||||
expectedProbes[i] = network.Probe{
|
||||
Name: &lbRuleName,
|
||||
Properties: &network.ProbePropertiesFormat{
|
||||
ProbePropertiesFormat: &network.ProbePropertiesFormat{
|
||||
RequestPath: to.StringPtr(podPresencePath),
|
||||
Protocol: network.ProbeProtocolHTTP,
|
||||
Port: to.Int32Ptr(podPresencePort),
|
||||
@ -367,7 +367,7 @@ func (az *Cloud) reconcileLoadBalancer(lb network.LoadBalancer, pip *network.Pub
|
||||
} else {
|
||||
expectedProbes[i] = network.Probe{
|
||||
Name: &lbRuleName,
|
||||
Properties: &network.ProbePropertiesFormat{
|
||||
ProbePropertiesFormat: &network.ProbePropertiesFormat{
|
||||
Protocol: probeProto,
|
||||
Port: to.Int32Ptr(port.NodePort),
|
||||
IntervalInSeconds: to.Int32Ptr(5),
|
||||
@ -378,7 +378,7 @@ func (az *Cloud) reconcileLoadBalancer(lb network.LoadBalancer, pip *network.Pub
|
||||
|
||||
expectedRules[i] = network.LoadBalancingRule{
|
||||
Name: &lbRuleName,
|
||||
Properties: &network.LoadBalancingRulePropertiesFormat{
|
||||
LoadBalancingRulePropertiesFormat: &network.LoadBalancingRulePropertiesFormat{
|
||||
Protocol: transportProto,
|
||||
FrontendIPConfiguration: &network.SubResource{
|
||||
ID: to.StringPtr(lbFrontendIPConfigID),
|
||||
@ -399,8 +399,8 @@ func (az *Cloud) reconcileLoadBalancer(lb network.LoadBalancer, pip *network.Pub
|
||||
// remove unwanted probes
|
||||
dirtyProbes := false
|
||||
var updatedProbes []network.Probe
|
||||
if lb.Properties.Probes != nil {
|
||||
updatedProbes = *lb.Properties.Probes
|
||||
if lb.Probes != nil {
|
||||
updatedProbes = *lb.Probes
|
||||
}
|
||||
for i := len(updatedProbes) - 1; i >= 0; i-- {
|
||||
existingProbe := updatedProbes[i]
|
||||
@ -433,14 +433,14 @@ func (az *Cloud) reconcileLoadBalancer(lb network.LoadBalancer, pip *network.Pub
|
||||
}
|
||||
if dirtyProbes {
|
||||
dirtyLb = true
|
||||
lb.Properties.Probes = &updatedProbes
|
||||
lb.Probes = &updatedProbes
|
||||
}
|
||||
|
||||
// update rules
|
||||
dirtyRules := false
|
||||
var updatedRules []network.LoadBalancingRule
|
||||
if lb.Properties.LoadBalancingRules != nil {
|
||||
updatedRules = *lb.Properties.LoadBalancingRules
|
||||
if lb.LoadBalancingRules != nil {
|
||||
updatedRules = *lb.LoadBalancingRules
|
||||
}
|
||||
// update rules: remove unwanted
|
||||
for i := len(updatedRules) - 1; i >= 0; i-- {
|
||||
@ -474,7 +474,7 @@ func (az *Cloud) reconcileLoadBalancer(lb network.LoadBalancer, pip *network.Pub
|
||||
}
|
||||
if dirtyRules {
|
||||
dirtyLb = true
|
||||
lb.Properties.LoadBalancingRules = &updatedRules
|
||||
lb.LoadBalancingRules = &updatedRules
|
||||
}
|
||||
|
||||
return lb, dirtyLb, nil
|
||||
@ -510,7 +510,7 @@ func (az *Cloud) reconcileSecurityGroup(sg network.SecurityGroup, clusterName st
|
||||
ix := i*len(sourceAddressPrefixes) + j
|
||||
expectedSecurityRules[ix] = network.SecurityRule{
|
||||
Name: to.StringPtr(securityRuleName),
|
||||
Properties: &network.SecurityRulePropertiesFormat{
|
||||
SecurityRulePropertiesFormat: &network.SecurityRulePropertiesFormat{
|
||||
Protocol: securityProto,
|
||||
SourcePortRange: to.StringPtr("*"),
|
||||
DestinationPortRange: to.StringPtr(strconv.Itoa(int(port.Port))),
|
||||
@ -526,8 +526,8 @@ func (az *Cloud) reconcileSecurityGroup(sg network.SecurityGroup, clusterName st
|
||||
// update security rules
|
||||
dirtySg := false
|
||||
var updatedRules []network.SecurityRule
|
||||
if sg.Properties.SecurityRules != nil {
|
||||
updatedRules = *sg.Properties.SecurityRules
|
||||
if sg.SecurityRules != nil {
|
||||
updatedRules = *sg.SecurityRules
|
||||
}
|
||||
// update security rules: remove unwanted
|
||||
for i := len(updatedRules) - 1; i >= 0; i-- {
|
||||
@ -561,13 +561,13 @@ func (az *Cloud) reconcileSecurityGroup(sg network.SecurityGroup, clusterName st
|
||||
return sg, false, err
|
||||
}
|
||||
|
||||
expectedRule.Properties.Priority = to.Int32Ptr(nextAvailablePriority)
|
||||
expectedRule.Priority = to.Int32Ptr(nextAvailablePriority)
|
||||
updatedRules = append(updatedRules, expectedRule)
|
||||
dirtySg = true
|
||||
}
|
||||
}
|
||||
if dirtySg {
|
||||
sg.Properties.SecurityRules = &updatedRules
|
||||
sg.SecurityRules = &updatedRules
|
||||
}
|
||||
return sg, dirtySg, nil
|
||||
}
|
||||
@ -620,7 +620,7 @@ func (az *Cloud) ensureHostInPool(serviceName string, nodeName types.NodeName, b
|
||||
// Check availability set
|
||||
if az.PrimaryAvailabilitySetName != "" {
|
||||
expectedAvailabilitySetName := az.getAvailabilitySetID(az.PrimaryAvailabilitySetName)
|
||||
if !strings.EqualFold(*machine.Properties.AvailabilitySet.ID, expectedAvailabilitySetName) {
|
||||
if !strings.EqualFold(*machine.AvailabilitySet.ID, expectedAvailabilitySetName) {
|
||||
glog.V(3).Infof(
|
||||
"nicupdate(%s): skipping nic (%s) since it is not in the primaryAvailabilitSet(%s)",
|
||||
serviceName, nicName, az.PrimaryAvailabilitySetName)
|
||||
@ -641,8 +641,8 @@ func (az *Cloud) ensureHostInPool(serviceName string, nodeName types.NodeName, b
|
||||
|
||||
foundPool := false
|
||||
newBackendPools := []network.BackendAddressPool{}
|
||||
if primaryIPConfig.Properties.LoadBalancerBackendAddressPools != nil {
|
||||
newBackendPools = *primaryIPConfig.Properties.LoadBalancerBackendAddressPools
|
||||
if primaryIPConfig.LoadBalancerBackendAddressPools != nil {
|
||||
newBackendPools = *primaryIPConfig.LoadBalancerBackendAddressPools
|
||||
}
|
||||
for _, existingPool := range newBackendPools {
|
||||
if strings.EqualFold(backendPoolID, *existingPool.ID) {
|
||||
@ -656,7 +656,7 @@ func (az *Cloud) ensureHostInPool(serviceName string, nodeName types.NodeName, b
|
||||
ID: to.StringPtr(backendPoolID),
|
||||
})
|
||||
|
||||
primaryIPConfig.Properties.LoadBalancerBackendAddressPools = &newBackendPools
|
||||
primaryIPConfig.LoadBalancerBackendAddressPools = &newBackendPools
|
||||
|
||||
glog.V(3).Infof("nicupdate(%s): nic(%s) - updating", serviceName, nicName)
|
||||
_, err := az.InterfacesClient.CreateOrUpdate(az.ResourceGroup, *nic.Name, nic, nil)
|
||||
|
@ -39,11 +39,11 @@ func (az *Cloud) ListRoutes(clusterName string) (routes []*cloudprovider.Route,
|
||||
}
|
||||
|
||||
var kubeRoutes []*cloudprovider.Route
|
||||
if routeTable.Properties.Routes != nil {
|
||||
kubeRoutes = make([]*cloudprovider.Route, len(*routeTable.Properties.Routes))
|
||||
for i, route := range *routeTable.Properties.Routes {
|
||||
if routeTable.Routes != nil {
|
||||
kubeRoutes = make([]*cloudprovider.Route, len(*routeTable.Routes))
|
||||
for i, route := range *routeTable.Routes {
|
||||
instance := mapRouteNameToNodeName(*route.Name)
|
||||
cidr := *route.Properties.AddressPrefix
|
||||
cidr := *route.AddressPrefix
|
||||
glog.V(10).Infof("list: * instance=%q, cidr=%q", instance, cidr)
|
||||
|
||||
kubeRoutes[i] = &cloudprovider.Route{
|
||||
@ -70,9 +70,9 @@ func (az *Cloud) CreateRoute(clusterName string, nameHint string, kubeRoute *clo
|
||||
}
|
||||
if !existsRouteTable {
|
||||
routeTable = network.RouteTable{
|
||||
Name: to.StringPtr(az.RouteTableName),
|
||||
Location: to.StringPtr(az.Location),
|
||||
Properties: &network.RouteTablePropertiesFormat{},
|
||||
Name: to.StringPtr(az.RouteTableName),
|
||||
Location: to.StringPtr(az.Location),
|
||||
RouteTablePropertiesFormat: &network.RouteTablePropertiesFormat{},
|
||||
}
|
||||
|
||||
glog.V(3).Infof("create: creating routetable. routeTableName=%q", az.RouteTableName)
|
||||
@ -93,12 +93,12 @@ func (az *Cloud) CreateRoute(clusterName string, nameHint string, kubeRoute *clo
|
||||
// 404 is fatal here
|
||||
return err
|
||||
}
|
||||
if subnet.Properties.RouteTable != nil {
|
||||
if *subnet.Properties.RouteTable.ID != *routeTable.ID {
|
||||
return fmt.Errorf("The subnet has a route table, but it was unrecognized. Refusing to modify it. active_routetable=%q expected_routetable=%q", *subnet.Properties.RouteTable.ID, *routeTable.ID)
|
||||
if subnet.RouteTable != nil {
|
||||
if *subnet.RouteTable.ID != *routeTable.ID {
|
||||
return fmt.Errorf("The subnet has a route table, but it was unrecognized. Refusing to modify it. active_routetable=%q expected_routetable=%q", *subnet.RouteTable.ID, *routeTable.ID)
|
||||
}
|
||||
} else {
|
||||
subnet.Properties.RouteTable = &network.RouteTable{
|
||||
subnet.RouteTable = &network.RouteTable{
|
||||
ID: routeTable.ID,
|
||||
}
|
||||
glog.V(3).Info("create: updating subnet")
|
||||
@ -116,7 +116,7 @@ func (az *Cloud) CreateRoute(clusterName string, nameHint string, kubeRoute *clo
|
||||
routeName := mapNodeNameToRouteName(kubeRoute.TargetNode)
|
||||
route := network.Route{
|
||||
Name: to.StringPtr(routeName),
|
||||
Properties: &network.RoutePropertiesFormat{
|
||||
RoutePropertiesFormat: &network.RoutePropertiesFormat{
|
||||
AddressPrefix: to.StringPtr(kubeRoute.DestinationCIDR),
|
||||
NextHopType: network.RouteNextHopTypeVirtualAppliance,
|
||||
NextHopIPAddress: to.StringPtr(targetIP),
|
||||
|
@ -39,7 +39,7 @@ func (az *Cloud) AttachDisk(diskName, diskURI string, nodeName types.NodeName, l
|
||||
} else if !exists {
|
||||
return cloudprovider.InstanceNotFound
|
||||
}
|
||||
disks := *vm.Properties.StorageProfile.DataDisks
|
||||
disks := *vm.StorageProfile.DataDisks
|
||||
disks = append(disks,
|
||||
compute.DataDisk{
|
||||
Name: &diskName,
|
||||
@ -53,7 +53,7 @@ func (az *Cloud) AttachDisk(diskName, diskURI string, nodeName types.NodeName, l
|
||||
|
||||
newVM := compute.VirtualMachine{
|
||||
Location: vm.Location,
|
||||
Properties: &compute.VirtualMachineProperties{
|
||||
VirtualMachineProperties: &compute.VirtualMachineProperties{
|
||||
StorageProfile: &compute.StorageProfile{
|
||||
DataDisks: &disks,
|
||||
},
|
||||
@ -91,7 +91,7 @@ func (az *Cloud) DisksAreAttached(diskNames []string, nodeName types.NodeName) (
|
||||
return attached, err
|
||||
}
|
||||
|
||||
disks := *vm.Properties.StorageProfile.DataDisks
|
||||
disks := *vm.StorageProfile.DataDisks
|
||||
for _, disk := range disks {
|
||||
for _, diskName := range diskNames {
|
||||
if disk.Name != nil && diskName != "" && *disk.Name == diskName {
|
||||
@ -113,7 +113,7 @@ func (az *Cloud) DetachDiskByName(diskName, diskURI string, nodeName types.NodeN
|
||||
return nil
|
||||
}
|
||||
|
||||
disks := *vm.Properties.StorageProfile.DataDisks
|
||||
disks := *vm.StorageProfile.DataDisks
|
||||
for i, disk := range disks {
|
||||
if (disk.Name != nil && diskName != "" && *disk.Name == diskName) || (disk.Vhd.URI != nil && diskURI != "" && *disk.Vhd.URI == diskURI) {
|
||||
// found the disk
|
||||
@ -124,7 +124,7 @@ func (az *Cloud) DetachDiskByName(diskName, diskURI string, nodeName types.NodeN
|
||||
}
|
||||
newVM := compute.VirtualMachine{
|
||||
Location: vm.Location,
|
||||
Properties: &compute.VirtualMachineProperties{
|
||||
VirtualMachineProperties: &compute.VirtualMachineProperties{
|
||||
StorageProfile: &compute.StorageProfile{
|
||||
DataDisks: &disks,
|
||||
},
|
||||
@ -148,7 +148,7 @@ func (az *Cloud) GetDiskLun(diskName, diskURI string, nodeName types.NodeName) (
|
||||
} else if !exists {
|
||||
return -1, cloudprovider.InstanceNotFound
|
||||
}
|
||||
disks := *vm.Properties.StorageProfile.DataDisks
|
||||
disks := *vm.StorageProfile.DataDisks
|
||||
for _, disk := range disks {
|
||||
if disk.Lun != nil && (disk.Name != nil && diskName != "" && *disk.Name == diskName) || (disk.Vhd.URI != nil && diskURI != "" && *disk.Vhd.URI == diskURI) {
|
||||
// found the disk
|
||||
@ -169,7 +169,7 @@ func (az *Cloud) GetNextDiskLun(nodeName types.NodeName) (int32, error) {
|
||||
return -1, cloudprovider.InstanceNotFound
|
||||
}
|
||||
used := make([]bool, maxLUN)
|
||||
disks := *vm.Properties.StorageProfile.DataDisks
|
||||
disks := *vm.StorageProfile.DataDisks
|
||||
for _, disk := range disks {
|
||||
if disk.Lun != nil {
|
||||
used[*disk.Lun] = true
|
||||
|
@ -133,12 +133,12 @@ func getProtocolsFromKubernetesProtocol(protocol v1.Protocol) (network.Transport
|
||||
|
||||
// This returns the full identifier of the primary NIC for the given VM.
|
||||
func getPrimaryInterfaceID(machine compute.VirtualMachine) (string, error) {
|
||||
if len(*machine.Properties.NetworkProfile.NetworkInterfaces) == 1 {
|
||||
return *(*machine.Properties.NetworkProfile.NetworkInterfaces)[0].ID, nil
|
||||
if len(*machine.NetworkProfile.NetworkInterfaces) == 1 {
|
||||
return *(*machine.NetworkProfile.NetworkInterfaces)[0].ID, nil
|
||||
}
|
||||
|
||||
for _, ref := range *machine.Properties.NetworkProfile.NetworkInterfaces {
|
||||
if *ref.Properties.Primary {
|
||||
for _, ref := range *machine.NetworkProfile.NetworkInterfaces {
|
||||
if *ref.Primary {
|
||||
return *ref.ID, nil
|
||||
}
|
||||
}
|
||||
@ -147,12 +147,12 @@ func getPrimaryInterfaceID(machine compute.VirtualMachine) (string, error) {
|
||||
}
|
||||
|
||||
func getPrimaryIPConfig(nic network.Interface) (*network.InterfaceIPConfiguration, error) {
|
||||
if len(*nic.Properties.IPConfigurations) == 1 {
|
||||
return &((*nic.Properties.IPConfigurations)[0]), nil
|
||||
if len(*nic.IPConfigurations) == 1 {
|
||||
return &((*nic.IPConfigurations)[0]), nil
|
||||
}
|
||||
|
||||
for _, ref := range *nic.Properties.IPConfigurations {
|
||||
if *ref.Properties.Primary {
|
||||
for _, ref := range *nic.IPConfigurations {
|
||||
if *ref.Primary {
|
||||
return &ref, nil
|
||||
}
|
||||
}
|
||||
@ -204,7 +204,7 @@ func getNextAvailablePriority(rules []network.SecurityRule) (int32, error) {
|
||||
outer:
|
||||
for smallest < loadBalancerMaximumPriority {
|
||||
for _, rule := range rules {
|
||||
if *rule.Properties.Priority == smallest {
|
||||
if *rule.Priority == smallest {
|
||||
smallest += spread
|
||||
continue outer
|
||||
}
|
||||
@ -245,6 +245,6 @@ func (az *Cloud) getIPForMachine(nodeName types.NodeName) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
targetIP := *ipConfig.Properties.PrivateIPAddress
|
||||
targetIP := *ipConfig.PrivateIPAddress
|
||||
return targetIP, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user