mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #81262 from levimm/fixUpdateServiceDNSLabel
fix azure load balancer update dns label issue
This commit is contained in:
commit
b5d33fa9bd
@ -492,41 +492,52 @@ func (az *Cloud) ensurePublicIPExists(service *v1.Service, pipName string, domai
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if existsPip {
|
||||
return &pip, nil
|
||||
}
|
||||
|
||||
serviceName := getServiceName(service)
|
||||
|
||||
if shouldPIPExisted {
|
||||
return nil, fmt.Errorf("PublicIP from annotation azure-pip-name=%s for service %s doesn't exist", pipName, serviceName)
|
||||
if existsPip {
|
||||
// return if pip exist and dns label is the same
|
||||
if getDomainNameLabel(&pip) == domainNameLabel {
|
||||
return &pip, nil
|
||||
}
|
||||
klog.V(2).Infof("ensurePublicIPExists for service(%s): pip(%s) - updating", serviceName, *pip.Name)
|
||||
if pip.PublicIPAddressPropertiesFormat == nil {
|
||||
pip.PublicIPAddressPropertiesFormat = &network.PublicIPAddressPropertiesFormat{
|
||||
PublicIPAllocationMethod: network.Static,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if shouldPIPExisted {
|
||||
return nil, fmt.Errorf("PublicIP from annotation azure-pip-name=%s for service %s doesn't exist", pipName, serviceName)
|
||||
}
|
||||
pip.Name = to.StringPtr(pipName)
|
||||
pip.Location = to.StringPtr(az.Location)
|
||||
pip.PublicIPAddressPropertiesFormat = &network.PublicIPAddressPropertiesFormat{
|
||||
PublicIPAllocationMethod: network.Static,
|
||||
}
|
||||
pip.Tags = map[string]*string{
|
||||
serviceTagKey: &serviceName,
|
||||
clusterNameKey: &clusterName,
|
||||
}
|
||||
if az.useStandardLoadBalancer() {
|
||||
pip.Sku = &network.PublicIPAddressSku{
|
||||
Name: network.PublicIPAddressSkuNameStandard,
|
||||
}
|
||||
}
|
||||
klog.V(2).Infof("ensurePublicIPExists for service(%s): pip(%s) - creating", serviceName, *pip.Name)
|
||||
}
|
||||
|
||||
pip.Name = to.StringPtr(pipName)
|
||||
pip.Location = to.StringPtr(az.Location)
|
||||
pip.PublicIPAddressPropertiesFormat = &network.PublicIPAddressPropertiesFormat{
|
||||
PublicIPAllocationMethod: network.Static,
|
||||
}
|
||||
if len(domainNameLabel) > 0 {
|
||||
if len(domainNameLabel) == 0 {
|
||||
pip.PublicIPAddressPropertiesFormat.DNSSettings = nil
|
||||
} else {
|
||||
pip.PublicIPAddressPropertiesFormat.DNSSettings = &network.PublicIPAddressDNSSettings{
|
||||
DomainNameLabel: &domainNameLabel,
|
||||
}
|
||||
}
|
||||
pip.Tags = map[string]*string{
|
||||
serviceTagKey: &serviceName,
|
||||
clusterNameKey: &clusterName,
|
||||
}
|
||||
if az.useStandardLoadBalancer() {
|
||||
pip.Sku = &network.PublicIPAddressSku{
|
||||
Name: network.PublicIPAddressSkuNameStandard,
|
||||
}
|
||||
}
|
||||
|
||||
klog.V(2).Infof("ensurePublicIPExists for service(%s): pip(%s) - creating", serviceName, *pip.Name)
|
||||
klog.V(10).Infof("CreateOrUpdatePIP(%s, %q): start", pipResourceGroup, *pip.Name)
|
||||
err = az.CreateOrUpdatePIP(service, pipResourceGroup, pip)
|
||||
if err != nil {
|
||||
klog.V(2).Infof("ensure(%s) abort backoff: pip(%s) - creating", serviceName, *pip.Name)
|
||||
klog.V(2).Infof("ensure(%s) abort backoff: pip(%s)", serviceName, *pip.Name)
|
||||
return nil, err
|
||||
}
|
||||
klog.V(10).Infof("CreateOrUpdatePIP(%s, %q): end", pipResourceGroup, *pip.Name)
|
||||
@ -540,6 +551,13 @@ func (az *Cloud) ensurePublicIPExists(service *v1.Service, pipName string, domai
|
||||
return &pip, nil
|
||||
}
|
||||
|
||||
func getDomainNameLabel(pip *network.PublicIPAddress) string {
|
||||
if pip == nil || pip.PublicIPAddressPropertiesFormat == nil || pip.PublicIPAddressPropertiesFormat.DNSSettings == nil {
|
||||
return ""
|
||||
}
|
||||
return to.String(pip.PublicIPAddressPropertiesFormat.DNSSettings.DomainNameLabel)
|
||||
}
|
||||
|
||||
func getIdleTimeout(s *v1.Service) (*int32, error) {
|
||||
const (
|
||||
min = 4
|
||||
|
@ -1833,6 +1833,7 @@ func TestEnsurePublicIPExists(t *testing.T) {
|
||||
existingPIPs []network.PublicIPAddress
|
||||
expectedPIP *network.PublicIPAddress
|
||||
expectedID string
|
||||
expectedDNS string
|
||||
expectedError bool
|
||||
}{
|
||||
{
|
||||
@ -1849,6 +1850,28 @@ func TestEnsurePublicIPExists(t *testing.T) {
|
||||
expectedID: "/subscriptions/subscription/resourceGroups/rg/providers/" +
|
||||
"Microsoft.Network/publicIPAddresses/pip1",
|
||||
},
|
||||
{
|
||||
desc: "ensurePublicIPExists shall update existed PIP's dns label",
|
||||
existingPIPs: []network.PublicIPAddress{{
|
||||
Name: to.StringPtr("pip1"),
|
||||
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
|
||||
DNSSettings: &network.PublicIPAddressDNSSettings{
|
||||
DomainNameLabel: to.StringPtr("previousdns"),
|
||||
},
|
||||
},
|
||||
}},
|
||||
expectedPIP: &network.PublicIPAddress{
|
||||
Name: to.StringPtr("pip1"),
|
||||
ID: to.StringPtr("/subscriptions/subscription/resourceGroups/rg" +
|
||||
"/providers/Microsoft.Network/publicIPAddresses/pip1"),
|
||||
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
|
||||
DNSSettings: &network.PublicIPAddressDNSSettings{
|
||||
DomainNameLabel: to.StringPtr("newdns"),
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedDNS: "newdns",
|
||||
},
|
||||
}
|
||||
|
||||
for i, test := range testCases {
|
||||
@ -1860,7 +1883,7 @@ func TestEnsurePublicIPExists(t *testing.T) {
|
||||
t.Fatalf("TestCase[%d] meets unexpected error: %v", i, err)
|
||||
}
|
||||
}
|
||||
pip, err := az.ensurePublicIPExists(&service, "pip1", "", "", false)
|
||||
pip, err := az.ensurePublicIPExists(&service, "pip1", test.expectedDNS, "", false)
|
||||
if test.expectedID != "" {
|
||||
assert.Equal(t, test.expectedID, to.String(pip.ID), "TestCase[%d]: %s", i, test.desc)
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user