Repository: metallb/metallb
Pull request #2095 (2023-09-25 18:56:04)

Update to golang 1.20
Updates to 1.20 since 1.19 is no longer supported. Latest 1.20.x version used for docker builds.

Closes https://github.com/metallb/metallb/issues/2094

mjnagel: @fedepaol I think I fixed the linting issues with rand.Seed deprecations - hopefully g2g on CI now?
fedepaol: Mind squashing the commits too?

Patch:
diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml
index 599caf3b..17145f0b 100644
--- a/.github/workflows/publish.yaml
+++ b/.github/workflows/publish.yaml
@@ -59,7 +59,7 @@ jobs:
         image: [speaker, controller, configmaptocrs]
     steps:
       - name: Set up QEMU
-        uses: docker/setup-qemu-action@v2
+        uses: docker/setup-qemu-action@v3
 
       - name: Install Cosign
         uses: sigstore/cosign-installer@main
@@ -73,7 +73,7 @@ jobs:
         uses: docker/setup-buildx-action@v2
 
       - name: Log into Quay
-        uses: docker/login-action@v2
+        uses: docker/login-action@v3
         with:
           registry: quay.io
           username: ${{ secrets.QUAY_USER }}
diff --git a/configmaptocrs/Dockerfile b/configmaptocrs/Dockerfile
index 57b408f3..cf7e1fab 100644
--- a/configmaptocrs/Dockerfile
+++ b/configmaptocrs/Dockerfile
@@ -1,6 +1,6 @@
 # syntax=docker/dockerfile:1.2
 
-FROM --platform=$BUILDPLATFORM docker.io/golang:1.19.5 AS builder
+FROM --platform=$BUILDPLATFORM docker.io/golang:1.20.8 AS builder
 ARG GIT_COMMIT=dev
 ARG GIT_BRANCH=dev
 WORKDIR $GOPATH/go.universe.tf/metallb
diff --git a/controller/Dockerfile b/controller/Dockerfile
index f1f1a30e..1a1b70e5 100644
--- a/controller/Dockerfile
+++ b/controller/Dockerfile
@@ -1,6 +1,6 @@
 # syntax=docker/dockerfile:1.2
 
-FROM --platform=$BUILDPLATFORM docker.io/golang:1.19.5 AS builder
+FROM --platform=$BUILDPLATFORM docker.io/golang:1.20.8 AS builder
 ARG GIT_COMMIT=dev
 ARG GIT_BRANCH=dev
 
diff --git a/controller/main.go b/controller/main.go
index 3385b1b0..abbf9441 100644
--- a/controller/main.go
+++ b/controller/main.go
@@ -143,6 +143,7 @@ func main() {
 		certServiceName     = flag.String("cert-service-name", "webhook-service", "The service name used to generate the TLS cert's hostname")
 		loadBalancerClass   = flag.String("lb-class", "", "load balancer class. When enabled, metallb will handle only services whose spec.loadBalancerClass matches the given lb class")
 		webhookMode         = flag.String("webhook-mode", "enabled", "webhook mode: can be enabled, disabled or only webhook if we want the controller to act as webhook endpoint only")
+		webhookSecretName   = flag.String("webhook-secret", "webhook-server-cert", "webhook secret: the name of webhook secret, default is webhook-server-cert")
 	)
 	flag.Parse()
 
@@ -189,6 +190,7 @@ func main() {
 		ValidateConfig:      validation,
 		EnableWebhook:       true,
 		DisableCertRotation: *disableCertRotation,
+		WebhookSecretName:   *webhookSecretName,
 		CertDir:             *certDir,
 		CertServiceName:     *certServiceName,
 		LoadBalancerClass:   *loadBalancerClass,
diff --git a/controller/service.go b/controller/service.go
index b48393ba..dd02632d 100644
--- a/controller/service.go
+++ b/controller/service.go
@@ -30,9 +30,10 @@ import (
 )
 
 const (
-	annotationAddressPool        = "metallb.universe.tf/address-pool"
-	annotationLoadBalancerIPs    = "metallb.universe.tf/loadBalancerIPs"
-	annotationIPAllocateFromPool = "metallb.universe.tf/ip-allocated-from-pool"
+	AnnotationPrefix             = "metallb.universe.tf"
+	AnnotationAddressPool        = AnnotationPrefix + "/" + "address-pool"
+	AnnotationLoadBalancerIPs    = AnnotationPrefix + "/" + "loadBalancerIPs"
+	AnnotationIPAllocateFromPool = AnnotationPrefix + "/" + "ip-allocated-from-pool"
 )
 
 var ErrConverge = fmt.Errorf("failed to converge")
@@ -106,7 +107,7 @@ func (c *controller) convergeBalancer(l log.Logger, key string, svc *v1.Service)
 		// The user might also have changed the pool annotation, and
 		// requested a different pool than the one that is currently
 		// allocated.
-		desiredPool := svc.Annotations[annotationAddressPool]
+		desiredPool := svc.Annotations[AnnotationAddressPool]
 		if len(lbIPs) != 0 && desiredPool != "" && c.ips.Pool(key) != desiredPool {
 			level.Info(l).Log("event", "clearAssignment", "reason", "differentPoolRequested", "msg", "user requested a different pool than the one currently assigned")
 			c.clearServiceState(key, svc)
@@ -168,7 +169,7 @@ func (c *controller) convergeBalancer(l log.Logger, key string, svc *v1.Service)
 	if svc.Annotations == nil {
 		svc.Annotations = make(map[string]string)
 	}
-	svc.Annotations[annotationIPAllocateFromPool] = pool
+	svc.Annotations[AnnotationIPAllocateFromPool] = pool
 
 	return nil
 }
@@ -177,7 +178,7 @@ func (c *controller) convergeBalancer(l log.Logger, key string, svc *v1.Service)
 // this controller.
 func (c *controller) clearServiceState(key string, svc *v1.Service) {
 	c.ips.Unassign(key)
-	delete(svc.Annotations, annotationIPAllocateFromPool)
+	delete(svc.Annotations, AnnotationIPAllocateFromPool)
 	svc.Status.LoadBalancer = v1.LoadBalancerStatus{}
 }
 
@@ -197,7 +198,7 @@ func (c *controller) allocateIPs(key string, svc *v1.Service) ([]net.IP, error)
 		return nil, err
 	}
 
-	desiredPool := svc.Annotations[annotationAddressPool]
+	desiredPool := svc.Annotations[AnnotationAddressPool]
 
 	// If the user asked for a specific IPs, try that.
 	if len(desiredLbIPs) > 0 {
@@ -236,12 +237,12 @@ func (c *controller) isServiceAllocated(key string) bool {
 
 func getDesiredLbIPs(svc *v1.Service) ([]net.IP, ipfamily.Family, error) {
 	var desiredLbIPs []net.IP
-	desiredLbIPsStr := svc.Annotations[annotationLoadBalancerIPs]
+	desiredLbIPsStr := svc.Annotations[AnnotationLoadBalancerIPs]
 
 	if desiredLbIPsStr == "" && svc.Spec.LoadBalancerIP == "" {
 		return nil, "", nil
 	} else if desiredLbIPsStr != "" && svc.Spec.LoadBalancerIP != "" {
-		return nil, "", fmt.Errorf("service can not have both %s and svc.Spec.LoadBalancerIP", annotationLoadBalancerIPs)
+		return nil, "", fmt.Errorf("service can not have both %s and svc.Spec.LoadBalancerIP", AnnotationLoadBalancerIPs)
 	}
 
 	if desiredLbIPsStr != "" {
@@ -249,7 +250,7 @@ func getDesiredLbIPs(svc *v1.Service) ([]net.IP, ipfamily.Family, error) {
 		for _, desiredLbIPStr := range desiredLbIPsSlice {
 			desiredLbIP := net.ParseIP(strings.TrimSpace(desiredLbIPStr))
 			if desiredLbIP == nil {
-				return nil, "", fmt.Errorf("invalid %s: %q", annotationLoadBalancerIPs, desiredLbIPsStr)
+				return nil, "", fmt.Errorf("invalid %s: %q", AnnotationLoadBalancerIPs, desiredLbIPsStr)
 			}
 			desiredLbIPs = append(desiredLbIPs, desiredLbIP)
 		}
diff --git a/go.mod b/go.mod
index 04778ccf..90a7c474 100644
--- a/go.mod
+++ b/go.mod
@@ -1,6 +1,6 @@
 module go.universe.tf/metallb
 
-go 1.19
+go 1.20
 
 require (
 	github.com/davecgh/go-spew v1.1.1
diff --git a/internal/k8s/k8s.go b/internal/k8s/k8s.go
index 10ed5ca9..bddffe6e 100644
--- a/internal/k8s/k8s.go
+++ b/internal/k8s/k8s.go
@@ -61,7 +61,6 @@ var (
 	validatingWebhookName           = "metallb-webhook-configuration"
 	addresspoolConvertingWebhookCRD = "addresspools.metallb.io"
 	bgppeerConvertingWebhookCRD     = "bgppeers.metallb.io"
-	webhookSecretName               = "webhook-server-cert" //#nosec G101
 )
 
 func init() {
@@ -108,6 +107,7 @@ type Config struct {
 	ValidateConfig      config.Validate
 	EnableWebhook       bool
 	DisableCertRotation bool
+	WebhookSecretName   string
 	CertDir             string
 	CertServiceName     string
 	LoadBalancerClass   string
diff --git a/internal/k8s/webhook.go b/internal/k8s/webhook.go
index d4a99fcc..9dc194f4 100644
--- a/internal/k8s/webhook.go
+++ b/internal/k8s/webhook.go
@@ -35,7 +35,7 @@ func enableCertRotation(notifyFinished chan struct{}, cfg *Config, mgr manager.M
 	err := rotator.AddRotator(mgr, &rotator.CertRotator{
 		SecretKey: types.NamespacedName{
 			Namespace: cfg.Namespace,
-			Name:      webhookSecretName,
+			Name:      cfg.WebhookSecretName,
 		},
 		CertDir:        cfg.CertDir,
 		CAName:         caName,
diff --git a/speaker/Dockerfile b/speaker/Dockerfile
index bd39c7b7..0992d450 100644
--- a/speaker/Dockerfile
+++ b/speaker/Dockerfile
@@ -1,6 +1,6 @@
 # syntax=docker/dockerfile:1.2
 
-FROM --platform=$BUILDPLATFORM docker.io/golang:1.19.5 AS builder
+FROM --platform=$BUILDPLATFORM docker.io/golang:1.20.8 AS builder
 ARG GIT_COMMIT=dev
 ARG GIT_BRANCH=dev
 WORKDIR $GOPATH/go.universe.tf/metallb


Test patch:
diff --git a/controller/controller_test.go b/controller/controller_test.go
index dbbc3a07..106be5e7 100644
--- a/controller/controller_test.go
+++ b/controller/controller_test.go
@@ -269,7 +269,7 @@ func TestControllerMutation(t *testing.T) {
 			in: &v1.Service{
 				ObjectMeta: metav1.ObjectMeta{
 					Annotations: map[string]string{
-						annotationLoadBalancerIPs: "1.2.3.1",
+						AnnotationLoadBalancerIPs: "1.2.3.1",
 					},
 				},
 				Spec: v1.ServiceSpec{
@@ -280,7 +280,7 @@ func TestControllerMutation(t *testing.T) {
 			want: &v1.Service{
 				ObjectMeta: metav1.ObjectMeta{
 					Annotations: map[string]string{
-						annotationLoadBalancerIPs: "1.2.3.1",
+						AnnotationLoadBalancerIPs: "1.2.3.1",
 					},
 				},
 				Spec: v1.ServiceSpec{
@@ -296,7 +296,7 @@ func TestControllerMutation(t *testing.T) {
 			in: &v1.Service{
 				ObjectMeta: metav1.ObjectMeta{
 					Annotations: map[string]string{
-						annotationLoadBalancerIPs: "1.2.3.1",
+						AnnotationLoadBalancerIPs: "1.2.3.1",
 					},
 				},
 				Spec: v1.ServiceSpec{
@@ -325,8 +325,8 @@ func TestControllerMutation(t *testing.T) {
 			in: &v1.Service{
 				ObjectMeta: metav1.ObjectMeta{
 					Annotations: map[string]string{
-						annotationLoadBalancerIPs: "1.2.3.1",
-						annotationAddressPool:     "pool2",
+						AnnotationLoadBalancerIPs: "1.2.3.1",
+						AnnotationAddressPool:     "pool2",
 					},
 				},
 				Spec: v1.ServiceSpec{
@@ -342,7 +342,7 @@ func TestControllerMutation(t *testing.T) {
 			in: &v1.Service{
 				ObjectMeta: metav1.ObjectMeta{
 					Annotations: map[string]string{
-						annotationLoadBalancerIPs: "please sir may I have an IP address thank you",
+						AnnotationLoadBalancerIPs: "please sir may I have an IP address thank you",
 					},
 				},
 				Spec: v1.ServiceSpec{
@@ -358,7 +358,7 @@ func TestControllerMutation(t *testing.T) {
 			in: &v1.Service{
 				ObjectMeta: metav1.ObjectMeta{
 					Annotations: map[string]string{
-						annotationLoadBalancerIPs: "1.2.3.1,1.2.3.2",
+						AnnotationLoadBalancerIPs: "1.2.3.1,1.2.3.2",
 					},
 				},
 				Spec: v1.ServiceSpec{
@@ -394,7 +394,7 @@ func TestControllerMutation(t *testing.T) {
 			in: &v1.Service{
 				ObjectMeta: metav1.ObjectMeta{
 					Annotations: map[string]string{
-						annotationAddressPool: "pool1",
+						AnnotationAddressPool: "pool1",
 					},
 				},
 				Spec: v1.ServiceSpec{
@@ -405,7 +405,7 @@ func TestControllerMutation(t *testing.T) {
 			want: &v1.Service{
 				ObjectMeta: metav1.ObjectMeta{
 					Annotations: map[string]string{
-						annotationAddressPool: "pool1",
+						AnnotationAddressPool: "pool1",
 					},
 				},
 				Spec: v1.ServiceSpec{
@@ -421,7 +421,7 @@ func TestControllerMutation(t *testing.T) {
 			in: &v1.Service{
 				ObjectMeta: metav1.ObjectMeta{
 					Annotations: map[string]string{
-						annotationAddressPool: "pool2",
+						AnnotationAddressPool: "pool2",
 					},
 				},
 				Spec: v1.ServiceSpec{
@@ -433,7 +433,7 @@ func TestControllerMutation(t *testing.T) {
 			want: &v1.Service{
 				ObjectMeta: metav1.ObjectMeta{
 					Annotations: map[string]string{
-						annotationAddressPool: "pool2",
+						AnnotationAddressPool: "pool2",
 					},
 				},
 				Spec: v1.ServiceSpec{
@@ -449,7 +449,7 @@ func TestControllerMutation(t *testing.T) {
 			in: &v1.Service{
 				ObjectMeta: metav1.ObjectMeta{
 					Annotations: map[string]string{
-						annotationAddressPool: "does-not-exist",
+						AnnotationAddressPool: "does-not-exist",
 					},
 				},
 				Spec: v1.ServiceSpec{
@@ -591,7 +591,7 @@ func TestControllerMutation(t *testing.T) {
 			in: &v1.Service{
 				ObjectMeta: metav1.ObjectMeta{
 					Annotations: map[string]string{
-						annotationLoadBalancerIPs: "1.2.3.1",
+						AnnotationLoadBalancerIPs: "1.2.3.1",
 					},
 				},
 				Spec: v1.ServiceSpec{
@@ -619,7 +619,7 @@ func TestControllerMutation(t *testing.T) {
 			in: &v1.Service{
 				ObjectMeta: metav1.ObjectMeta{
 					Annotations: map[string]string{
-						annotationLoadBalancerIPs: "1000::",
+						AnnotationLoadBalancerIPs: "1000::",
 					},
 				},
 				Spec: v1.ServiceSpec{
@@ -690,7 +690,7 @@ func TestControllerMutation(t *testing.T) {
 			in: &v1.Service{
 				ObjectMeta: metav1.ObjectMeta{
 					Annotations: map[string]string{
-						annotationAddressPool: "pool5",
+						AnnotationAddressPool: "pool5",
 					},
 				},
 				Spec: v1.ServiceSpec{
@@ -701,7 +701,7 @@ func TestControllerMutation(t *testing.T) {
 			want: &v1.Service{
 				ObjectMeta: metav1.ObjectMeta{
 					Annotations: map[string]string{
-						annotationAddressPool: "pool5",
+						AnnotationAddressPool: "pool5",
 					},
 				},
 				Spec: v1.ServiceSpec{
@@ -727,7 +727,7 @@ func TestControllerMutation(t *testing.T) {
 			in: &v1.Service{
 				ObjectMeta: metav1.ObjectMeta{
 					Annotations: map[string]string{
-						annotationLoadBalancerIPs: "1.2.3.1",
+						AnnotationLoadBalancerIPs: "1.2.3.1",
 					},
 				},
 				Spec: v1.ServiceSpec{
@@ -742,7 +742,7 @@ func TestControllerMutation(t *testing.T) {
 			in: &v1.Service{
 				ObjectMeta: metav1.ObjectMeta{
 					Annotations: map[string]string{
-						annotationLoadBalancerIPs: "1.2.3.0,1000::",
+						AnnotationLoadBalancerIPs: "1.2.3.0,1000::",
 					},
 				},
 				Spec: v1.ServiceSpec{
@@ -753,7 +753,7 @@ func TestControllerMutation(t *testing.T) {
 			want: &v1.Service{
 				ObjectMeta: metav1.ObjectMeta{
 					Annotations: map[string]string{
-						annotationLoadBalancerIPs: "1.2.3.0,1000::",
+						AnnotationLoadBalancerIPs: "1.2.3.0,1000::",
 					},
 				},
 				Spec: v1.ServiceSpec{
@@ -796,7 +796,7 @@ func TestControllerMutation(t *testing.T) {
 			in: &v1.Service{
 				ObjectMeta: metav1.ObjectMeta{
 					Annotations: map[string]string{
-						annotationLoadBalancerIPs: "1.2.3.0,1000::",
+						AnnotationLoadBalancerIPs: "1.2.3.0,1000::",
 					},
 				},
 				Spec: v1.ServiceSpec{
diff --git a/e2etest/go.mod b/e2etest/go.mod
index 1b63149e..8272d25a 100644
--- a/e2etest/go.mod
+++ b/e2etest/go.mod
@@ -1,6 +1,6 @@
 module go.universe.tf/e2etest
 
-go 1.19
+go 1.20
 
 replace (
 	github.com/onsi/ginkgo/v2 => github.com/onsi/ginkgo/v2 v2.4.0
diff --git a/e2etest/go.work b/e2etest/go.work
index 8a9dca5c..125ff0b7 100644
--- a/e2etest/go.work
+++ b/e2etest/go.work
@@ -1,4 +1,4 @@
-go 1.19
+go 1.20
 
 use (
 	./
diff --git a/internal/bgp/frr/frr_test.go b/internal/bgp/frr/frr_test.go
index 16132249..bfda0913 100644
--- a/internal/bgp/frr/frr_test.go
+++ b/internal/bgp/frr/frr_test.go
@@ -859,7 +859,7 @@ func TestTwoAdvertisementsTwoSessions(t *testing.T) {
 					SessionName:   "test-peer1"},
 			}
 			seed := time.Now().UnixNano()
-			rand.Seed(seed)
+			rand.New(rand.NewSource(seed))
 
 			rand.Shuffle(len(sessionsParameters), func(i, j int) {
 				sessionsParameters[i], sessionsParameters[j] = sessionsParameters[j], sessionsParameters[i]
diff --git a/internal/k8s/controllers/config_conversion_test.go b/internal/k8s/controllers/config_conversion_test.go
index 73092c0e..63cb1e9a 100644
--- a/internal/k8s/controllers/config_conversion_test.go
+++ b/internal/k8s/controllers/config_conversion_test.go
@@ -222,7 +222,7 @@ func TestConversionIsStable(t *testing.T) {
 		t.Fatalf("conversion failed, err %v", err)
 	}
 	seed := time.Now().UnixNano()
-	rand.Seed(seed)
+	rand.New(rand.NewSource(seed))
 
 	// Here we check the stability of the conversion, by shuffling the
 	// order of the resources and checking that the output is the same.