@@ -492,41 +492,52 @@ func (az *Cloud) ensurePublicIPExists(service *v1.Service, pipName string, domai
492
492
if err != nil {
493
493
return nil , err
494
494
}
495
- if existsPip {
496
- return & pip , nil
497
- }
498
495
499
496
serviceName := getServiceName (service )
500
497
501
- if shouldPIPExisted {
502
- return nil , fmt .Errorf ("PublicIP from annotation azure-pip-name=%s for service %s doesn't exist" , pipName , serviceName )
503
- }
504
-
505
- pip .Name = to .StringPtr (pipName )
506
- pip .Location = to .StringPtr (az .Location )
507
- pip .PublicIPAddressPropertiesFormat = & network.PublicIPAddressPropertiesFormat {
508
- PublicIPAllocationMethod : network .Static ,
498
+ if existsPip {
499
+ // return if pip exist and dns label is the same
500
+ if getDomainNameLabel (& pip ) == domainNameLabel {
501
+ return & pip , nil
502
+ }
503
+ klog .V (2 ).Infof ("ensurePublicIPExists for service(%s): pip(%s) - updating" , serviceName , * pip .Name )
504
+ if pip .PublicIPAddressPropertiesFormat == nil {
505
+ pip .PublicIPAddressPropertiesFormat = & network.PublicIPAddressPropertiesFormat {
506
+ PublicIPAllocationMethod : network .Static ,
507
+ }
508
+ }
509
+ } else {
510
+ if shouldPIPExisted {
511
+ return nil , fmt .Errorf ("PublicIP from annotation azure-pip-name=%s for service %s doesn't exist" , pipName , serviceName )
512
+ }
513
+ pip .Name = to .StringPtr (pipName )
514
+ pip .Location = to .StringPtr (az .Location )
515
+ pip .PublicIPAddressPropertiesFormat = & network.PublicIPAddressPropertiesFormat {
516
+ PublicIPAllocationMethod : network .Static ,
517
+ }
518
+ pip .Tags = map [string ]* string {
519
+ serviceTagKey : & serviceName ,
520
+ clusterNameKey : & clusterName ,
521
+ }
522
+ if az .useStandardLoadBalancer () {
523
+ pip .Sku = & network.PublicIPAddressSku {
524
+ Name : network .PublicIPAddressSkuNameStandard ,
525
+ }
526
+ }
527
+ klog .V (2 ).Infof ("ensurePublicIPExists for service(%s): pip(%s) - creating" , serviceName , * pip .Name )
509
528
}
510
- if len (domainNameLabel ) > 0 {
529
+ if len (domainNameLabel ) == 0 {
530
+ pip .PublicIPAddressPropertiesFormat .DNSSettings = nil
531
+ } else {
511
532
pip .PublicIPAddressPropertiesFormat .DNSSettings = & network.PublicIPAddressDNSSettings {
512
533
DomainNameLabel : & domainNameLabel ,
513
534
}
514
535
}
515
- pip .Tags = map [string ]* string {
516
- serviceTagKey : & serviceName ,
517
- clusterNameKey : & clusterName ,
518
- }
519
- if az .useStandardLoadBalancer () {
520
- pip .Sku = & network.PublicIPAddressSku {
521
- Name : network .PublicIPAddressSkuNameStandard ,
522
- }
523
- }
524
536
525
- klog .V (2 ).Infof ("ensurePublicIPExists for service(%s): pip(%s) - creating" , serviceName , * pip .Name )
526
537
klog .V (10 ).Infof ("CreateOrUpdatePIP(%s, %q): start" , pipResourceGroup , * pip .Name )
527
538
err = az .CreateOrUpdatePIP (service , pipResourceGroup , pip )
528
539
if err != nil {
529
- klog .V (2 ).Infof ("ensure(%s) abort backoff: pip(%s) - creating " , serviceName , * pip .Name )
540
+ klog .V (2 ).Infof ("ensure(%s) abort backoff: pip(%s)" , serviceName , * pip .Name )
530
541
return nil , err
531
542
}
532
543
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
540
551
return & pip , nil
541
552
}
542
553
554
+ func getDomainNameLabel (pip * network.PublicIPAddress ) string {
555
+ if pip == nil || pip .PublicIPAddressPropertiesFormat == nil || pip .PublicIPAddressPropertiesFormat .DNSSettings == nil {
556
+ return ""
557
+ }
558
+ return to .String (pip .PublicIPAddressPropertiesFormat .DNSSettings .DomainNameLabel )
559
+ }
560
+
543
561
func getIdleTimeout (s * v1.Service ) (* int32 , error ) {
544
562
const (
545
563
min = 4
0 commit comments