-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prior to this commit the operator was unaware of its release version and other such build information. This made tracking down issues across fleets of instances a bit difficult. This commit add the `version` subcommand to allow interrogating a binary and the `redpanda_operator_build_info` metric which reports the same information via labels on a gauge.
- Loading branch information
1 parent
881aba8
commit 0868b61
Showing
4 changed files
with
63 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2024 Redpanda Data, Inc. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.md | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0 | ||
|
||
package version | ||
|
||
import ( | ||
"runtime" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/spf13/cobra" | ||
"sigs.k8s.io/controller-runtime/pkg/metrics" | ||
) | ||
|
||
var ( | ||
// these variables are set via ldflags in our goreleaser build. | ||
|
||
version string | ||
commit string | ||
buildDate string | ||
) | ||
|
||
func init() { | ||
buildInfoGauge := prometheus.NewGauge(prometheus.GaugeOpts{ | ||
Namespace: "redpanda_operator", | ||
Name: "build_info", | ||
Help: "A gauge always set to 1 that provides build information as labels.", | ||
ConstLabels: prometheus.Labels{ | ||
"version": version, | ||
"commit": commit, | ||
"go_version": runtime.Version(), | ||
}, | ||
}) | ||
|
||
buildInfoGauge.Set(1) | ||
|
||
metrics.Registry.MustRegister(buildInfoGauge) | ||
} | ||
|
||
func Command() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "version", | ||
Short: "print build information", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cmd.Printf("Version: %s\n", version) | ||
cmd.Printf("Commit: %s\n", commit) | ||
cmd.Printf("Go Version: %s\n", runtime.Version()) | ||
cmd.Printf("Build Date: %s\n", buildDate) | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,8 @@ | ||
version: '3' | ||
|
||
tasks: | ||
release: | ||
dir: '{{.SRC_DIR}}' | ||
desc: release go binaries using the .goreleaser.yml file in given directory | ||
deps: | ||
- task: :k8s:generate | ||
env: | ||
GORELEASER_CURRENT_TAG: '{{.TAG_NAME}}' | ||
GITHUB_TOKEN: | ||
sh: echo "${GITHUB_TOKEN:-$GITHUB_API_TOKEN}" | ||
cmds: | ||
- | | ||
EMPTY_NOTES="/tmp/empty_notes" | ||
mkdir -p /tmp | ||
echo "" >> "$EMPTY_NOTES" | ||
goreleaser release --clean --release-notes "$EMPTY_NOTES" | ||
preconditions: | ||
- test -n "$GITHUB_API_TOKEN" || test -n "$GITHUB_TOKEN" | ||
- test -n "{{.TAG_NAME}}" | ||
|
||
build: | ||
dir: '{{.SRC_DIR}}' | ||
# A .goreleaser.yml file is required at the GO_SRC_DIR | ||
desc: build go binaries with goreleaser and a given id | ||
deps: | ||
- task: :k8s:generate | ||
env: | ||
GORELEASER_CURRENT_TAG: '{{.TAG_NAME}}' | ||
cmds: | ||
- | | ||
export PATH="{{.GORELEASER_INSTALL_DIR}}:$PATH" | ||
goreleaser build --clean --id {{.GORELEASER_BUILD_ID}} {{.CLI_ARGS}} | ||
preconditions: | ||
- test -n "{{.GORELEASER_BUILD_ID}}" | ||
- test -n "{{.TAG_NAME}}" | ||
|
||
build-operator-binaries: | ||
deps: | ||
- task: :k8s:generate | ||
cmds: | ||
- go version | ||
- 'goreleaser build --snapshot --clean' | ||
- 'goreleaser build --snapshot --clean {{.CLI_ARGS}}' |