Skip to content

Commit

Permalink
Update Go to 1.24 (#196)
Browse files Browse the repository at this point in the history
* Update Go to 1.24

* Format strings earlier due to added check

* Update comment to reflect change
  • Loading branch information
andyasp authored Feb 12, 2025
1 parent e5d5b19 commit 5f472d4
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 43 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
45 changes: 27 additions & 18 deletions pkg/admission/prep_downscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,21 @@ 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,
),
)
}

path := annotations[config.PrepareDownscalePathAnnotationKey]
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,
),
)
}

Expand All @@ -122,38 +126,39 @@ 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)
if err != nil {
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)
}
}
Expand All @@ -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,
),
)
}

Expand All @@ -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,
),
)
}

Expand All @@ -197,12 +206,12 @@ 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 {
// deny returns a *v1.AdmissionResponse with Allowed: false and the message provided
func deny(msg string) *v1.AdmissionResponse {
return &v1.AdmissionResponse{
Allowed: false,
Result: &metav1.Status{
Message: fmt.Sprintf(msg, args...),
Message: msg,
},
}
}
Expand Down
45 changes: 28 additions & 17 deletions pkg/admission/zone_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,21 @@ 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,
),
)
}

path := annotations[config.PrepareDownscalePathAnnotationKey]
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,
),
)
}

Expand All @@ -102,46 +106,49 @@ 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.
foundSts, err := zt.findDownscalesDoneMinTimeAgo(stsList, ar.Request.Name)
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)
if err != nil {
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)
}
}
Expand All @@ -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,
),
)
}

Expand All @@ -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,
),
)
}

Expand Down

0 comments on commit 5f472d4

Please sign in to comment.