@@ -25,6 +25,7 @@ import (
2525 "k8s.io/client-go/tools/clientcmd"
2626 cloudprovider "k8s.io/cloud-provider"
2727 "k8s.io/klog/v2"
28+ "k8s.io/utils/ptr"
2829
2930 "github.com/linode/linode-cloud-controller-manager/cloud/annotations"
3031 "github.com/linode/linode-cloud-controller-manager/cloud/linode/client"
@@ -622,7 +623,8 @@ func (l *loadbalancers) deleteUnusedConfigs(ctx context.Context, nbConfigs []lin
622623// shouldPreserveNodeBalancer determines whether a NodeBalancer should be deleted based on the
623624// service's preserve annotation.
624625func (l * loadbalancers ) shouldPreserveNodeBalancer (service * v1.Service ) bool {
625- return getServiceBoolAnnotation (service , annotations .AnnLinodeLoadBalancerPreserve )
626+ shouldPreserve := getServiceBoolAnnotation (service , annotations .AnnLinodeLoadBalancerPreserve )
627+ return shouldPreserve != nil && * shouldPreserve
626628}
627629
628630// EnsureLoadBalancerDeleted deletes the specified loadbalancer if it exists.
@@ -1423,14 +1425,13 @@ func makeLoadBalancerStatus(service *v1.Service, nb *linodego.NodeBalancer) *v1.
14231425 }
14241426
14251427 // Return hostname-only if annotation is set or environment variable is set
1426- if getServiceBoolAnnotation (service , annotations .AnnLinodeHostnameOnlyIngress ) {
1427- return & v1.LoadBalancerStatus {
1428- Ingress : []v1.LoadBalancerIngress {ingress },
1429- }
1430- }
1431-
1432- if val := envBoolOptions ("LINODE_HOSTNAME_ONLY_INGRESS" ); val {
1428+ useHostnameOnly := getServiceBoolAnnotation (service , annotations .AnnLinodeHostnameOnlyIngress )
1429+ if useHostnameOnly == nil {
1430+ val := envBoolOptions ("LINODE_HOSTNAME_ONLY_INGRESS" )
14331431 klog .Infof ("LINODE_HOSTNAME_ONLY_INGRESS: (%v)" , val )
1432+ useHostnameOnly = ptr .To (envBoolOptions ("LINODE_HOSTNAME_ONLY_INGRESS" ))
1433+ }
1434+ if * useHostnameOnly {
14341435 return & v1.LoadBalancerStatus {
14351436 Ingress : []v1.LoadBalancerIngress {ingress },
14361437 }
@@ -1440,11 +1441,14 @@ func makeLoadBalancerStatus(service *v1.Service, nb *linodego.NodeBalancer) *v1.
14401441 klog .V (4 ).Infof ("NodeBalancer (%d) is using frontend VPC address type" , nb .ID )
14411442 }
14421443
1443- // Check for per-service IPv6 annotation first, then fall back to global setting
1444- useIPv6 := getServiceBoolAnnotation (service , annotations .AnnLinodeEnableIPv6Ingress ) || options .Options .EnableIPv6ForLoadBalancers
1444+ // Check for per-service IPv6 annotation first, then fall back to global setting if not set
1445+ useIPv6 := getServiceBoolAnnotation (service , annotations .AnnLinodeEnableIPv6Ingress )
1446+ if useIPv6 == nil {
1447+ useIPv6 = ptr .To (options .Options .EnableIPv6ForLoadBalancers )
1448+ }
14451449
14461450 // When IPv6 is enabled (either per-service or globally), include both IPv4 and IPv6
1447- if useIPv6 && nb .IPv6 != nil && * nb .IPv6 != "" {
1451+ if * useIPv6 && nb .IPv6 != nil && * nb .IPv6 != "" {
14481452 ingresses := []v1.LoadBalancerIngress {
14491453 {
14501454 Hostname : * nb .Hostname ,
@@ -1482,13 +1486,13 @@ func getServiceNn(service *v1.Service) string {
14821486 return fmt .Sprintf ("%s/%s" , service .Namespace , service .Name )
14831487}
14841488
1485- func getServiceBoolAnnotation (service * v1.Service , name string ) bool {
1489+ func getServiceBoolAnnotation (service * v1.Service , name string ) * bool {
14861490 value , ok := service .GetAnnotations ()[name ]
14871491 if ! ok {
1488- return false
1492+ return nil
14891493 }
14901494 boolValue , err := strconv .ParseBool (value )
1491- return err == nil && boolValue
1495+ return ptr . To ( err == nil && boolValue )
14921496}
14931497
14941498// validateNodeBalancerBackendIPv4Range validates the NodeBalancerBackendIPv4Range
0 commit comments