From a4d1df737baa5704a98bdd1b1806ce9a5de54d0a Mon Sep 17 00:00:00 2001 From: Andy Asp Date: Wed, 12 Feb 2025 12:26:16 -0500 Subject: [PATCH 1/3] Update Go to 1.24 --- .github/workflows/ci.yaml | 12 ++++++------ Dockerfile | 2 +- go.mod | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f61149fb3..2a5162b61 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -10,7 +10,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.23' + go-version: '1.24' check-latest: true - run: make rollout-operator @@ -20,7 +20,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.23' + go-version: '1.24' check-latest: true - run: make test - run: make test-boringcrypto @@ -31,7 +31,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.23' + go-version: '1.24' check-latest: true - run: make build-image - run: make integration @@ -42,7 +42,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.23' + go-version: '1.24' check-latest: true - run: make build-image-boringcrypto - run: make integration @@ -53,9 +53,9 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.23' + go-version: '1.24' check-latest: true - uses: golangci/golangci-lint-action@v6 with: - version: v1.60.1 + version: v1.64.2 args: --timeout=5m diff --git a/Dockerfile b/Dockerfile index 647321119..bd1636980 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ ARG BASEIMAGE=gcr.io/distroless/static-debian12:nonroot -FROM golang:1.23-bookworm AS build +FROM golang:1.24-bookworm AS build ARG TARGETOS ARG TARGETARCH diff --git a/go.mod b/go.mod index 079815585..fc34579e1 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/grafana/rollout-operator -go 1.23.0 +go 1.24.0 require ( github.com/facette/natsort v0.0.0-20181210072756-2cd4dd1e2dcb From bdc668d8f279d0e89f13e7add4f65166b6d488b7 Mon Sep 17 00:00:00 2001 From: Andy Asp Date: Wed, 12 Feb 2025 12:56:27 -0500 Subject: [PATCH 2/3] Format strings earlier due to added check --- pkg/admission/prep_downscale.go | 43 ++++++++++++++++++------------- pkg/admission/zone_tracker.go | 45 ++++++++++++++++++++------------- 2 files changed, 54 insertions(+), 34 deletions(-) diff --git a/pkg/admission/prep_downscale.go b/pkg/admission/prep_downscale.go index c48882e76..c092edb2f 100644 --- a/pkg/admission/prep_downscale.go +++ b/pkg/admission/prep_downscale.go @@ -102,8 +102,10 @@ func prepareDownscale(ctx context.Context, l log.Logger, ar v1.AdmissionReview, if port == "" { level.Warn(logger).Log("msg", fmt.Sprintf("downscale not allowed because the %v annotation is not set or empty", config.PrepareDownscalePortAnnotationKey)) return deny( - "downscale of %s/%s in %s from %d to %d replicas is not allowed because the %v annotation is not set or empty.", - ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, config.PrepareDownscalePortAnnotationKey, + fmt.Sprintf( + "downscale of %s/%s in %s from %d to %d replicas is not allowed because the %v annotation is not set or empty.", + ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, config.PrepareDownscalePortAnnotationKey, + ), ) } @@ -111,8 +113,10 @@ func prepareDownscale(ctx context.Context, l log.Logger, ar v1.AdmissionReview, if path == "" { level.Warn(logger).Log("msg", fmt.Sprintf("downscale not allowed because the %v annotation is not set or empty", config.PrepareDownscalePathAnnotationKey)) return deny( - "downscale of %s/%s in %s from %d to %d replicas is not allowed because the %v annotation is not set or empty.", - ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, config.PrepareDownscalePathAnnotationKey, + fmt.Sprintf( + "downscale of %s/%s in %s from %d to %d replicas is not allowed because the %v annotation is not set or empty.", + ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, config.PrepareDownscalePathAnnotationKey, + ), ) } @@ -122,23 +126,26 @@ func prepareDownscale(ctx context.Context, l log.Logger, ar v1.AdmissionReview, if err != nil { level.Warn(logger).Log("msg", "downscale not allowed due to error while finding other statefulsets", "err", err) return deny( - "downscale of %s/%s in %s from %d to %d replicas is not allowed because finding other statefulsets failed.", - ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, + fmt.Sprintf( + "downscale of %s/%s in %s from %d to %d replicas is not allowed because finding other statefulsets failed.", + ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, + ), ) } foundSts, err := findDownscalesDoneMinTimeAgo(stsList, ar.Request.Name) if err != nil { level.Warn(logger).Log("msg", "downscale not allowed due to error while parsing downscale annotations", "err", err) return deny( - "downscale of %s/%s in %s from %d to %d replicas is not allowed because parsing downscale annotations failed.", - ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, + fmt.Sprintf( + "downscale of %s/%s in %s from %d to %d replicas is not allowed because parsing downscale annotations failed.", + ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, + ), ) } if foundSts != nil { msg := fmt.Sprintf("downscale of %s/%s in %s from %d to %d replicas is not allowed because statefulset %v was downscaled at %v and is labelled to wait %s between zone downscales", ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, foundSts.name, foundSts.lastDownscaleTime, foundSts.waitTime) level.Warn(logger).Log("msg", msg, "err", err) - //nolint:govet return deny(msg) } foundSts, err = findStatefulSetWithNonUpdatedReplicas(ctx, api, ar.Request.Namespace, stsList, ar.Request.Name) @@ -146,14 +153,12 @@ func prepareDownscale(ctx context.Context, l log.Logger, ar v1.AdmissionReview, msg := fmt.Sprintf("downscale of %s/%s in %s from %d to %d replicas is not allowed because an error occurred while checking whether StatefulSets have non-updated replicas", ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas) level.Warn(logger).Log("msg", msg, "err", err) - //nolint:govet return deny(msg) } if foundSts != nil { msg := fmt.Sprintf("downscale of %s/%s in %s from %d to %d replicas is not allowed because statefulset %v has %d non-updated replicas and %d non-ready replicas", ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, foundSts.name, foundSts.nonUpdatedReplicas, foundSts.nonReadyReplicas) level.Warn(logger).Log("msg", msg) - //nolint:govet return deny(msg) } } @@ -170,8 +175,10 @@ func prepareDownscale(ctx context.Context, l log.Logger, ar v1.AdmissionReview, undoPrepareShutdownRequests(ctx, logger, client, eps) return deny( - "downscale of %s/%s in %s from %d to %d replicas is not allowed because one or more pods failed to prepare for shutdown.", - ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, + fmt.Sprintf( + "downscale of %s/%s in %s from %d to %d replicas is not allowed because one or more pods failed to prepare for shutdown.", + ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, + ), ) } @@ -182,8 +189,10 @@ func prepareDownscale(ctx context.Context, l log.Logger, ar v1.AdmissionReview, undoPrepareShutdownRequests(ctx, logger, client, eps) return deny( - "downscale of %s/%s in %s from %d to %d replicas is not allowed because adding an annotation to the statefulset failed.", - ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, + fmt.Sprintf( + "downscale of %s/%s in %s from %d to %d replicas is not allowed because adding an annotation to the statefulset failed.", + ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, + ), ) } @@ -198,11 +207,11 @@ func prepareDownscale(ctx context.Context, l log.Logger, ar v1.AdmissionReview, } // deny returns a *v1.AdmissionResponse with Allowed: false and the message provided formatted with as in fmt.Sprintf. -func deny(msg string, args ...any) *v1.AdmissionResponse { +func deny(msg string) *v1.AdmissionResponse { return &v1.AdmissionResponse{ Allowed: false, Result: &metav1.Status{ - Message: fmt.Sprintf(msg, args...), + Message: msg, }, } } diff --git a/pkg/admission/zone_tracker.go b/pkg/admission/zone_tracker.go index aaaaf6d1f..6129a1b83 100644 --- a/pkg/admission/zone_tracker.go +++ b/pkg/admission/zone_tracker.go @@ -82,8 +82,10 @@ func (zt *zoneTracker) prepareDownscale(ctx context.Context, l log.Logger, ar v1 if port == "" { level.Warn(logger).Log("msg", fmt.Sprintf("downscale not allowed because the %v annotation is not set or empty", config.PrepareDownscalePortAnnotationKey)) return deny( - "downscale of %s/%s in %s from %d to %d replicas is not allowed because the %v annotation is not set or empty.", - ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, config.PrepareDownscalePortAnnotationKey, + fmt.Sprintf( + "downscale of %s/%s in %s from %d to %d replicas is not allowed because the %v annotation is not set or empty.", + ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, config.PrepareDownscalePortAnnotationKey, + ), ) } @@ -91,8 +93,10 @@ func (zt *zoneTracker) prepareDownscale(ctx context.Context, l log.Logger, ar v1 if path == "" { level.Warn(logger).Log("msg", fmt.Sprintf("downscale not allowed because the %v annotation is not set or empty", config.PrepareDownscalePathAnnotationKey)) return deny( - "downscale of %s/%s in %s from %d to %d replicas is not allowed because the %v annotation is not set or empty.", - ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, config.PrepareDownscalePathAnnotationKey, + fmt.Sprintf( + "downscale of %s/%s in %s from %d to %d replicas is not allowed because the %v annotation is not set or empty.", + ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, config.PrepareDownscalePathAnnotationKey, + ), ) } @@ -102,15 +106,19 @@ func (zt *zoneTracker) prepareDownscale(ctx context.Context, l log.Logger, ar v1 if err != nil { level.Warn(logger).Log("msg", "downscale not allowed due to error while finding other statefulsets", "err", err) return deny( - "downscale of %s/%s in %s from %d to %d replicas is not allowed because finding other statefulsets failed.", - ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, + fmt.Sprintf( + "downscale of %s/%s in %s from %d to %d replicas is not allowed because finding other statefulsets failed.", + ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, + ), ) } if err := zt.loadZones(ctx, stsList); err != nil { level.Warn(logger).Log("msg", "downscale not allowed due to error while loading zones", "err", err) return deny( - "downscale of %s/%s in %s from %d to %d replicas is not allowed because loading zones failed.", - ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, + fmt.Sprintf( + "downscale of %s/%s in %s from %d to %d replicas is not allowed because loading zones failed.", + ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, + ), ) } // Check if the zone has been downscaled recently. @@ -118,15 +126,16 @@ func (zt *zoneTracker) prepareDownscale(ctx context.Context, l log.Logger, ar v1 if err != nil { level.Warn(logger).Log("msg", "downscale not allowed due to error while parsing downscale timestamps from the zone ConfigMap", "err", err) return deny( - "downscale of %s/%s in %s from %d to %d replicas is not allowed because parsing parsing downscale timestamps from the zone ConfigMap failed.", - ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, + fmt.Sprintf( + "downscale of %s/%s in %s from %d to %d replicas is not allowed because parsing parsing downscale timestamps from the zone ConfigMap failed.", + ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, + ), ) } if foundSts != nil { msg := fmt.Sprintf("downscale of %s/%s in %s from %d to %d replicas is not allowed because statefulset %v was downscaled at %v and is labelled to wait %s between zone downscales", ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, foundSts.name, foundSts.lastDownscaleTime, foundSts.waitTime) level.Warn(logger).Log("msg", msg, "err", err) - //nolint:govet return deny(msg) } foundSts, err = findStatefulSetWithNonUpdatedReplicas(ctx, api, ar.Request.Namespace, stsList, ar.Request.Name) @@ -134,14 +143,12 @@ func (zt *zoneTracker) prepareDownscale(ctx context.Context, l log.Logger, ar v1 msg := fmt.Sprintf("downscale of %s/%s in %s from %d to %d replicas is not allowed because an error occurred while checking whether StatefulSets have non-updated replicas", ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas) level.Warn(logger).Log("msg", msg, "err", err) - //nolint:govet return deny(msg) } if foundSts != nil { msg := fmt.Sprintf("downscale of %s/%s in %s from %d to %d replicas is not allowed because statefulset %v has %d non-updated replicas and %d non-ready replicas", ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, foundSts.name, foundSts.nonUpdatedReplicas, foundSts.nonReadyReplicas) level.Warn(logger).Log("msg", msg) - //nolint:govet return deny(msg) } } @@ -159,8 +166,10 @@ func (zt *zoneTracker) prepareDownscale(ctx context.Context, l log.Logger, ar v1 undoPrepareShutdownRequests(ctx, logger, client, eps) return deny( - "downscale of %s/%s in %s from %d to %d replicas is not allowed because one or more pods failed to prepare for shutdown.", - ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, + fmt.Sprintf( + "downscale of %s/%s in %s from %d to %d replicas is not allowed because one or more pods failed to prepare for shutdown.", + ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, + ), ) } @@ -170,8 +179,10 @@ func (zt *zoneTracker) prepareDownscale(ctx context.Context, l log.Logger, ar v1 level.Error(logger).Log("msg", "downscale not allowed due to error while adding annotation. unpreparing...", "err", err) undoPrepareShutdownRequests(ctx, logger, client, eps) return deny( - "downscale of %s/%s in %s from %d to %d replicas is not allowed because setting downscale timestamp in the zone ConfigMap failed.", - ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, + fmt.Sprintf( + "downscale of %s/%s in %s from %d to %d replicas is not allowed because setting downscale timestamp in the zone ConfigMap failed.", + ar.Request.Resource.Resource, ar.Request.Name, ar.Request.Namespace, *oldInfo.replicas, *newInfo.replicas, + ), ) } From e88a17b406dd02217340076b4a5dbc22f3017f89 Mon Sep 17 00:00:00 2001 From: Andy Asp Date: Wed, 12 Feb 2025 13:19:56 -0500 Subject: [PATCH 3/3] Update comment to reflect change --- pkg/admission/prep_downscale.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/admission/prep_downscale.go b/pkg/admission/prep_downscale.go index c092edb2f..eba01ed33 100644 --- a/pkg/admission/prep_downscale.go +++ b/pkg/admission/prep_downscale.go @@ -206,7 +206,7 @@ func prepareDownscale(ctx context.Context, l log.Logger, ar v1.AdmissionReview, } } -// deny returns a *v1.AdmissionResponse with Allowed: false and the message provided formatted with as in fmt.Sprintf. +// deny returns a *v1.AdmissionResponse with Allowed: false and the message provided func deny(msg string) *v1.AdmissionResponse { return &v1.AdmissionResponse{ Allowed: false,