mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #87246 from nilo19/qi-fix-dns-label
Fix the bug PIP's DNS is deleted if no DNS label service annotation isn't set.
This commit is contained in:
commit
6413f1ee2b
@ -137,11 +137,11 @@ func (az *Cloud) GetLoadBalancer(ctx context.Context, clusterName string, servic
|
|||||||
return status, true, nil
|
return status, true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPublicIPDomainNameLabel(service *v1.Service) string {
|
func getPublicIPDomainNameLabel(service *v1.Service) (string, bool) {
|
||||||
if labelName, found := service.Annotations[ServiceAnnotationDNSLabelName]; found {
|
if labelName, found := service.Annotations[ServiceAnnotationDNSLabelName]; found {
|
||||||
return labelName
|
return labelName, found
|
||||||
}
|
}
|
||||||
return ""
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnsureLoadBalancer creates a new load balancer 'name', or updates the existing one. Returns the status of the balancer
|
// EnsureLoadBalancer creates a new load balancer 'name', or updates the existing one. Returns the status of the balancer
|
||||||
@ -498,7 +498,7 @@ func (az *Cloud) findServiceIPAddress(ctx context.Context, clusterName string, s
|
|||||||
return lbStatus.Ingress[0].IP, nil
|
return lbStatus.Ingress[0].IP, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (az *Cloud) ensurePublicIPExists(service *v1.Service, pipName string, domainNameLabel, clusterName string, shouldPIPExisted bool) (*network.PublicIPAddress, error) {
|
func (az *Cloud) ensurePublicIPExists(service *v1.Service, pipName string, domainNameLabel, clusterName string, shouldPIPExisted, foundDNSLabelAnnotation bool) (*network.PublicIPAddress, error) {
|
||||||
pipResourceGroup := az.getPublicIPAddressResourceGroup(service)
|
pipResourceGroup := az.getPublicIPAddressResourceGroup(service)
|
||||||
pip, existsPip, err := az.getPublicIPAddress(pipResourceGroup, pipName)
|
pip, existsPip, err := az.getPublicIPAddress(pipResourceGroup, pipName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -538,6 +538,7 @@ func (az *Cloud) ensurePublicIPExists(service *v1.Service, pipName string, domai
|
|||||||
}
|
}
|
||||||
klog.V(2).Infof("ensurePublicIPExists for service(%s): pip(%s) - creating", serviceName, *pip.Name)
|
klog.V(2).Infof("ensurePublicIPExists for service(%s): pip(%s) - creating", serviceName, *pip.Name)
|
||||||
}
|
}
|
||||||
|
if foundDNSLabelAnnotation {
|
||||||
if len(domainNameLabel) == 0 {
|
if len(domainNameLabel) == 0 {
|
||||||
pip.PublicIPAddressPropertiesFormat.DNSSettings = nil
|
pip.PublicIPAddressPropertiesFormat.DNSSettings = nil
|
||||||
} else {
|
} else {
|
||||||
@ -545,6 +546,7 @@ func (az *Cloud) ensurePublicIPExists(service *v1.Service, pipName string, domai
|
|||||||
DomainNameLabel: &domainNameLabel,
|
DomainNameLabel: &domainNameLabel,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if az.ipv6DualStackEnabled {
|
if az.ipv6DualStackEnabled {
|
||||||
// TODO: (khenidak) if we ever enable IPv6 single stack, then we should
|
// TODO: (khenidak) if we ever enable IPv6 single stack, then we should
|
||||||
@ -807,8 +809,8 @@ func (az *Cloud) reconcileLoadBalancer(clusterName string, service *v1.Service,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
domainNameLabel := getPublicIPDomainNameLabel(service)
|
domainNameLabel, found := getPublicIPDomainNameLabel(service)
|
||||||
pip, err := az.ensurePublicIPExists(service, pipName, domainNameLabel, clusterName, shouldPIPExisted)
|
pip, err := az.ensurePublicIPExists(service, pipName, domainNameLabel, clusterName, shouldPIPExisted, found)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -1515,8 +1517,8 @@ func (az *Cloud) reconcilePublicIP(clusterName string, service *v1.Service, lbNa
|
|||||||
if !isInternal && wantLb {
|
if !isInternal && wantLb {
|
||||||
// Confirm desired public ip resource exists
|
// Confirm desired public ip resource exists
|
||||||
var pip *network.PublicIPAddress
|
var pip *network.PublicIPAddress
|
||||||
domainNameLabel := getPublicIPDomainNameLabel(service)
|
domainNameLabel, found := getPublicIPDomainNameLabel(service)
|
||||||
if pip, err = az.ensurePublicIPExists(service, desiredPipName, domainNameLabel, clusterName, shouldPIPExisted); err != nil {
|
if pip, err = az.ensurePublicIPExists(service, desiredPipName, domainNameLabel, clusterName, shouldPIPExisted, found); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return pip, nil
|
return pip, nil
|
||||||
|
@ -1983,8 +1983,8 @@ func TestReconcilePublicIP(t *testing.T) {
|
|||||||
pip, err := az.reconcilePublicIP("testCluster", &service, "", test.wantLb)
|
pip, err := az.reconcilePublicIP("testCluster", &service, "", test.wantLb)
|
||||||
if test.expectedID != "" {
|
if test.expectedID != "" {
|
||||||
assert.Equal(t, test.expectedID, to.String(pip.ID), "TestCase[%d]: %s", i, test.desc)
|
assert.Equal(t, test.expectedID, to.String(pip.ID), "TestCase[%d]: %s", i, test.desc)
|
||||||
} else {
|
} else if test.expectedPIP != nil && test.expectedPIP.Name != nil {
|
||||||
assert.Equal(t, test.expectedPIP, pip, "TestCase[%d]: %s", i, test.desc)
|
assert.Equal(t, *test.expectedPIP.Name, *pip.Name, "TestCase[%d]: %s", i, test.desc)
|
||||||
}
|
}
|
||||||
assert.Equal(t, test.expectedError, err != nil, "TestCase[%d]: %s", i, test.desc)
|
assert.Equal(t, test.expectedError, err != nil, "TestCase[%d]: %s", i, test.desc)
|
||||||
}
|
}
|
||||||
@ -1994,9 +1994,10 @@ func TestEnsurePublicIPExists(t *testing.T) {
|
|||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
existingPIPs []network.PublicIPAddress
|
existingPIPs []network.PublicIPAddress
|
||||||
|
inputDNSLabel string
|
||||||
|
foundDNSLabelAnnotation bool
|
||||||
expectedPIP *network.PublicIPAddress
|
expectedPIP *network.PublicIPAddress
|
||||||
expectedID string
|
expectedID string
|
||||||
expectedDNS string
|
|
||||||
expectedError bool
|
expectedError bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
@ -2015,6 +2016,8 @@ func TestEnsurePublicIPExists(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "ensurePublicIPExists shall update existed PIP's dns label",
|
desc: "ensurePublicIPExists shall update existed PIP's dns label",
|
||||||
|
inputDNSLabel: "newdns",
|
||||||
|
foundDNSLabelAnnotation: true,
|
||||||
existingPIPs: []network.PublicIPAddress{{
|
existingPIPs: []network.PublicIPAddress{{
|
||||||
Name: to.StringPtr("pip1"),
|
Name: to.StringPtr("pip1"),
|
||||||
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
|
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
|
||||||
@ -2033,7 +2036,48 @@ func TestEnsurePublicIPExists(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedDNS: "newdns",
|
},
|
||||||
|
{
|
||||||
|
desc: "ensurePublicIPExists shall delete DNS from PIP if DNS label is set empty",
|
||||||
|
foundDNSLabelAnnotation: true,
|
||||||
|
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: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "ensurePublicIPExists shall not delete DNS from PIP if DNS label annotation is not set",
|
||||||
|
foundDNSLabelAnnotation: false,
|
||||||
|
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("previousdns"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2046,7 +2090,7 @@ func TestEnsurePublicIPExists(t *testing.T) {
|
|||||||
t.Fatalf("TestCase[%d] meets unexpected error: %v", i, err)
|
t.Fatalf("TestCase[%d] meets unexpected error: %v", i, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pip, err := az.ensurePublicIPExists(&service, "pip1", test.expectedDNS, "", false)
|
pip, err := az.ensurePublicIPExists(&service, "pip1", test.inputDNSLabel, "", false, test.foundDNSLabelAnnotation)
|
||||||
if test.expectedID != "" {
|
if test.expectedID != "" {
|
||||||
assert.Equal(t, test.expectedID, to.String(pip.ID), "TestCase[%d]: %s", i, test.desc)
|
assert.Equal(t, test.expectedID, to.String(pip.ID), "TestCase[%d]: %s", i, test.desc)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user