From 21cb414c205fda68d7ff52e7bb3ef66d7417c79b Mon Sep 17 00:00:00 2001 From: Tarun Chinmai Sekar Date: Thu, 18 Jan 2024 23:55:04 +0000 Subject: [PATCH 1/2] Replace helper --- cloud/linode/loadbalancers.go | 40 ++++++++++++++--------------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/cloud/linode/loadbalancers.go b/cloud/linode/loadbalancers.go index e9293fbf..e4fbb191 100644 --- a/cloud/linode/loadbalancers.go +++ b/cloud/linode/loadbalancers.go @@ -64,7 +64,7 @@ func newLoadbalancers(client Client, zone string) cloudprovider.LoadBalancer { } func (l *loadbalancers) getNodeBalancerForService(ctx context.Context, service *v1.Service) (*linodego.NodeBalancer, error) { - rawID, _ := getServiceAnnotation(service, annLinodeNodeBalancerID) + rawID, _ := service.GetAnnotations()[annLinodeNodeBalancerID] id, idErr := strconv.Atoi(rawID) hasIDAnn := idErr == nil && id != 0 @@ -120,7 +120,7 @@ func (l *loadbalancers) getNodeBalancerByStatus(ctx context.Context, service *v1 func (l *loadbalancers) cleanupOldNodeBalancer(ctx context.Context, service *v1.Service) error { // unless there's an annotation, we can never get a past and current NB to differ, // because they're looked up the same way - if _, ok := getServiceAnnotation(service, annLinodeNodeBalancerID); !ok { + if _, ok := service.GetAnnotations()[annLinodeNodeBalancerID]; !ok { return nil } @@ -474,7 +474,7 @@ func (l *loadbalancers) getNodeBalancerByID(ctx context.Context, service *v1.Ser func (l *loadbalancers) getLoadBalancerTags(_ context.Context, clusterName string, service *v1.Service) []string { tags := []string{clusterName} - tagStr, ok := getServiceAnnotation(service, annLinodeLoadBalancerTags) + tagStr, ok := service.GetAnnotations()[annLinodeLoadBalancerTags] if ok { return append(tags, strings.Split(tagStr, ",")...) } @@ -494,7 +494,7 @@ func (l *loadbalancers) createNodeBalancer(ctx context.Context, clusterName stri Tags: tags, } - fwid, ok := getServiceAnnotation(service, annLinodeCloudFirewallID) + fwid, ok := service.GetAnnotations()[annLinodeCloudFirewallID] if ok { firewallID, err := strconv.Atoi(fwid) if err != nil { @@ -525,7 +525,7 @@ func (l *loadbalancers) buildNodeBalancerConfig(ctx context.Context, service *v1 } if health == linodego.CheckHTTP || health == linodego.CheckHTTPBody { - path := service.Annotations[annLinodeCheckPath] + path := service.GetAnnotations()[annLinodeCheckPath] if path == "" { path = "/" } @@ -533,14 +533,14 @@ func (l *loadbalancers) buildNodeBalancerConfig(ctx context.Context, service *v1 } if health == linodego.CheckHTTPBody { - body := service.Annotations[annLinodeCheckBody] + body := service.GetAnnotations()[annLinodeCheckBody] if body == "" { return config, fmt.Errorf("for health check type http_body need body regex annotation %v", annLinodeCheckBody) } config.CheckBody = body } checkInterval := 5 - if ci, ok := service.Annotations[annLinodeHealthCheckInterval]; ok { + if ci, ok := service.GetAnnotations()[annLinodeHealthCheckInterval]; ok { if checkInterval, err = strconv.Atoi(ci); err != nil { return config, err } @@ -548,7 +548,7 @@ func (l *loadbalancers) buildNodeBalancerConfig(ctx context.Context, service *v1 config.CheckInterval = checkInterval checkTimeout := 3 - if ct, ok := service.Annotations[annLinodeHealthCheckTimeout]; ok { + if ct, ok := service.GetAnnotations()[annLinodeHealthCheckTimeout]; ok { if checkTimeout, err = strconv.Atoi(ct); err != nil { return config, err } @@ -556,7 +556,7 @@ func (l *loadbalancers) buildNodeBalancerConfig(ctx context.Context, service *v1 config.CheckTimeout = checkTimeout checkAttempts := 2 - if ca, ok := service.Annotations[annLinodeHealthCheckAttempts]; ok { + if ca, ok := service.GetAnnotations()[annLinodeHealthCheckAttempts]; ok { if checkAttempts, err = strconv.Atoi(ca); err != nil { return config, err } @@ -564,7 +564,7 @@ func (l *loadbalancers) buildNodeBalancerConfig(ctx context.Context, service *v1 config.CheckAttempts = checkAttempts checkPassive := true - if cp, ok := service.Annotations[annLinodeHealthCheckPassive]; ok { + if cp, ok := service.GetAnnotations()[annLinodeHealthCheckPassive]; ok { if checkPassive, err = strconv.ParseBool(cp); err != nil { return config, err } @@ -685,7 +685,7 @@ func getPortConfig(service *v1.Service, port int) (portConfig, error) { protocol := portConfigAnnotation.Protocol if protocol == "" { protocol = "tcp" - if p, ok := service.Annotations[annLinodeDefaultProtocol]; ok { + if p, ok := service.GetAnnotations()[annLinodeDefaultProtocol]; ok { protocol = p } } @@ -695,7 +695,7 @@ func getPortConfig(service *v1.Service, port int) (portConfig, error) { if proxyProtocol == "" { proxyProtocol = string(linodego.ProxyProtocolNone) for _, ann := range []string{annLinodeDefaultProxyProtocol, annLinodeProxyProtocolDeprecated} { - if pp, ok := service.Annotations[ann]; ok { + if pp, ok := service.GetAnnotations()[ann]; ok { proxyProtocol = pp break } @@ -722,7 +722,7 @@ func getPortConfig(service *v1.Service, port int) (portConfig, error) { } func getHealthCheckType(service *v1.Service) (linodego.ConfigCheck, error) { - hType, ok := service.Annotations[annLinodeHealthCheckType] + hType, ok := service.GetAnnotations()[annLinodeHealthCheckType] if !ok { return linodego.CheckConnection, nil } @@ -735,7 +735,7 @@ func getHealthCheckType(service *v1.Service) (linodego.ConfigCheck, error) { func getPortConfigAnnotation(service *v1.Service, port int) (portConfigAnnotation, error) { annotation := portConfigAnnotation{} annotationKey := annLinodePortConfigPrefix + strconv.Itoa(port) - annotationJSON, ok := service.Annotations[annotationKey] + annotationJSON, ok := service.GetAnnotations()[annotationKey] if !ok { return annotation, nil @@ -789,7 +789,7 @@ func getTLSCertInfo(ctx context.Context, kubeClient kubernetes.Interface, namesp func getConnectionThrottle(service *v1.Service) int { connThrottle := 20 - if connThrottleString := service.Annotations[annLinodeThrottle]; connThrottleString != "" { + if connThrottleString := service.GetAnnotations()[annLinodeThrottle]; connThrottleString != "" { parsed, err := strconv.Atoi(connThrottleString) if err == nil { if parsed < 0 { @@ -836,16 +836,8 @@ func getServiceNn(service *v1.Service) string { return fmt.Sprintf("%s/%s", service.Namespace, service.Name) } -func getServiceAnnotation(service *v1.Service, name string) (string, bool) { - if service.Annotations == nil { - return "", false - } - val, ok := service.Annotations[name] - return val, ok -} - func getServiceBoolAnnotation(service *v1.Service, name string) bool { - value, ok := getServiceAnnotation(service, name) + value, ok := service.GetAnnotations()[name] if !ok { return false } From ec24cd3edf0c1c749e38e76360e710db80d9d447 Mon Sep 17 00:00:00 2001 From: Tarun Chinmai Sekar Date: Fri, 19 Jan 2024 02:29:21 +0000 Subject: [PATCH 2/2] lint --- cloud/linode/loadbalancers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud/linode/loadbalancers.go b/cloud/linode/loadbalancers.go index e4fbb191..d2088b62 100644 --- a/cloud/linode/loadbalancers.go +++ b/cloud/linode/loadbalancers.go @@ -64,7 +64,7 @@ func newLoadbalancers(client Client, zone string) cloudprovider.LoadBalancer { } func (l *loadbalancers) getNodeBalancerForService(ctx context.Context, service *v1.Service) (*linodego.NodeBalancer, error) { - rawID, _ := service.GetAnnotations()[annLinodeNodeBalancerID] + rawID := service.GetAnnotations()[annLinodeNodeBalancerID] id, idErr := strconv.Atoi(rawID) hasIDAnn := idErr == nil && id != 0