Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Build with go 1.22 #2362

Merged
merged 3 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ env:
E2E_SETUP_KIND: yes
E2E_SETUP_KUBECTL: yes
SUDO: sudo
GO_VERSION: "^1.21"
GOLANGCI_LINT_VERSION: "v1.54.2"
GO_VERSION: "^1.22"
GOLANGCI_LINT_VERSION: "v1.56.2"

jobs:
ci-go-lint:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/govulncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- cron: '0 0 * * 1'

env:
GO_VERSION: "^1.21"
GO_VERSION: "^1.22"

permissions:
contents: read
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
run:
deadline: 5m
deadline: 10m

linters:
disable-all: true
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG GOVERSION=1.21
ARG GOVERSION=1.22
ARG GOARCH
FROM golang:${GOVERSION} as builder
ARG GOARCH
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
OS ?= $(shell uname -s | tr A-Z a-z)
ALL_ARCH = amd64 arm arm64 ppc64le s390x
PKG = github.com/prometheus/common
PROMETHEUS_VERSION = 2.46.0
GO_VERSION = 1.21.8
PROMETHEUS_VERSION = 2.51.1
GO_VERSION = 1.22.2
IMAGE = $(REGISTRY)/kube-state-metrics
MULTI_ARCH_IMG = $(IMAGE)-$(ARCH)
USER ?= $(shell id -u -n)
HOST ?= $(shell hostname)
MARKDOWNLINT_CLI2_VERSION = 0.9.2
MARKDOWNLINT_CLI2_VERSION = 0.13.0


export DOCKER_CLI_EXPERIMENTAL=enabled
Expand Down
6 changes: 3 additions & 3 deletions docs/metrics/workload/pod-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
| kube_pod_container_status_last_terminated_exitcode | Gauge | Describes the exit code for the last container in terminated state. | | `container`=&lt;container-name&gt; <br> `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL | - |
| kube_pod_container_status_last_terminated_timestamp | Gauge | Last terminated time for a pod container in unix timestamp. | | `container`=&lt;container-name&gt; <br> `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL | - |
| kube_pod_container_status_ready | Gauge | Describes whether the containers readiness check succeeded | | `container`=&lt;container-name&gt; <br> `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; | STABLE | - |
| kube_pod_status_initialized_time | Gauge | Time when the pod is initialized. | seconds | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL |
| kube_pod_status_ready_time | Gauge | Time when pod passed readiness probes. | seconds | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL |
| kube_pod_status_container_ready_time | Gauge | Time when the container of the pod entered Ready state. | seconds | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL |
| kube_pod_status_initialized_time | Gauge | Time when the pod is initialized. | seconds | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL | - |
| kube_pod_status_ready_time | Gauge | Time when pod passed readiness probes. | seconds | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL | - |
| kube_pod_status_container_ready_time | Gauge | Time when the container of the pod entered Ready state. | seconds | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL | - |
| kube_pod_container_status_restarts_total | Counter | The number of container restarts per container | | `container`=&lt;container-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `pod`=&lt;pod-name&gt; <br> `uid`=&lt;pod-uid&gt; | STABLE | - |
| kube_pod_container_resource_requests | Gauge | The number of requested request resource by a container. It is recommended to use the `kube_pod_resource_requests` metric exposed by kube-scheduler instead, as it is more precise. | `cpu`=&lt;core&gt; <br> `memory`=&lt;bytes&gt; | `resource`=&lt;resource-name&gt; <br> `unit`=&lt;resource-unit&gt; <br> `container`=&lt;container-name&gt; <br> `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `node`=&lt; node-name&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL | - |
| kube_pod_container_resource_limits | Gauge | The number of requested limit resource by a container. It is recommended to use the `kube_pod_resource_limits` metric exposed by kube-scheduler instead, as it is more precise. | `cpu`=&lt;core&gt; <br> `memory`=&lt;bytes&gt; | `resource`=&lt;resource-name&gt; <br> `unit`=&lt;resource-unit&gt; <br> `container`=&lt;container-name&gt; <br> `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `node`=&lt; node-name&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL | - |
Expand Down
2 changes: 1 addition & 1 deletion internal/store/clusterrole.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func clusterRoleMetricFamilies(allowAnnotationsList, allowLabelsList []string) [
metric.Gauge,
basemetrics.ALPHA,
"",
wrapClusterRoleFunc(func(r *rbacv1.ClusterRole) *metric.Family {
wrapClusterRoleFunc(func(_ *rbacv1.ClusterRole) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{{
LabelKeys: []string{},
Expand Down
2 changes: 1 addition & 1 deletion internal/store/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func configMapMetricFamilies(allowAnnotationsList, allowLabelsList []string) []g
metric.Gauge,
basemetrics.STABLE,
"",
wrapConfigMapFunc(func(c *v1.ConfigMap) *metric.Family {
wrapConfigMapFunc(func(_ *v1.ConfigMap) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{{
LabelKeys: []string{},
Expand Down
2 changes: 1 addition & 1 deletion internal/store/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func endpointMetricFamilies(allowAnnotationsList, allowLabelsList []string) []ge
metric.Gauge,
basemetrics.STABLE,
"",
wrapEndpointFunc(func(e *v1.Endpoints) *metric.Family {
wrapEndpointFunc(func(_ *v1.Endpoints) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand Down
2 changes: 1 addition & 1 deletion internal/store/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func jobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
metric.Gauge,
basemetrics.STABLE,
"",
wrapJobFunc(func(j *v1batch.Job) *metric.Family {
wrapJobFunc(func(_ *v1batch.Job) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand Down
2 changes: 1 addition & 1 deletion internal/store/mutatingwebhookconfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var (
metric.Gauge,
basemetrics.ALPHA,
"",
wrapMutatingWebhookConfigurationFunc(func(mwc *admissionregistrationv1.MutatingWebhookConfiguration) *metric.Family {
wrapMutatingWebhookConfigurationFunc(func(_ *admissionregistrationv1.MutatingWebhookConfiguration) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand Down
2 changes: 1 addition & 1 deletion internal/store/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func roleMetricFamilies(allowAnnotationsList, allowLabelsList []string) []genera
metric.Gauge,
basemetrics.ALPHA,
"",
wrapRoleFunc(func(r *rbacv1.Role) *metric.Family {
wrapRoleFunc(func(_ *rbacv1.Role) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{{
LabelKeys: []string{},
Expand Down
2 changes: 1 addition & 1 deletion internal/store/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func secretMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gene
metric.Gauge,
basemetrics.STABLE,
"",
wrapSecretFunc(func(s *v1.Secret) *metric.Family {
wrapSecretFunc(func(_ *v1.Secret) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand Down
2 changes: 1 addition & 1 deletion internal/store/validatingwebhookconfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var (
metric.Gauge,
basemetrics.ALPHA,
"",
wrapValidatingWebhookConfigurationFunc(func(vwc *admissionregistrationv1.ValidatingWebhookConfiguration) *metric.Family {
wrapValidatingWebhookConfigurationFunc(func(_ *admissionregistrationv1.ValidatingWebhookConfiguration) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
func main() {
opts := options.NewOptions()
cmd := options.InitCommand
cmd.Run = func(cmd *cobra.Command, args []string) {
cmd.Run = func(_ *cobra.Command, _ []string) {
internal.RunKubeStateMetricsWrapper(opts)
}
opts.AddFlags(cmd)
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func buildMetricsServer(m *metricshandler.MetricsHandler, durationObserver prome
mux.Handle(metricsPath, promhttp.InstrumentHandlerDuration(durationObserver, m))

// Add healthzPath
mux.HandleFunc(healthzPath, func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc(healthzPath, func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte(http.StatusText(http.StatusOK)))
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func BenchmarkKubeStateMetrics(b *testing.B) {
// This test is not suitable to be compared in terms of time, as it includes
// a one second wait. Use for memory allocation comparisons, profiling, ...
handler := metricshandler.New(&options.Options{}, kubeClient, builder, false)
b.Run("GenerateMetrics", func(b *testing.B) {
b.Run("GenerateMetrics", func(_ *testing.B) {
handler.ConfigureSharding(ctx, 0, 1)

// Wait for caches to fill
Expand Down
6 changes: 3 additions & 3 deletions pkg/metrics_store/metrics_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (f *metricFamily) ByteSlice() []byte {
}

func TestObjectsSameNameDifferentNamespaces(t *testing.T) {
serviceIDS := []string{"a", "b"}
serviceIDs := []string{"a", "b"}

genFunc := func(obj interface{}) []metric.FamilyInterface {
o, err := meta.Accessor(obj)
Expand All @@ -65,7 +65,7 @@ func TestObjectsSameNameDifferentNamespaces(t *testing.T) {

ms := NewMetricsStore([]string{"Information about service."}, genFunc)

for _, id := range serviceIDS {
for _, id := range serviceIDs {
s := v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "service",
Expand All @@ -88,7 +88,7 @@ func TestObjectsSameNameDifferentNamespaces(t *testing.T) {
}
m := w.String()

for _, id := range serviceIDS {
for _, id := range serviceIDs {
if !strings.Contains(m, fmt.Sprintf("uid=\"%v\"", id)) {
t.Fatalf("expected to find metric with uid %v", id)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/metrics_store/metrics_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func TestWriteAllWithMultipleStores(t *testing.T) {

// TestWriteAllWithEmptyStores checks that nothing is printed if no metrics exist for metric families.
func TestWriteAllWithEmptyStores(t *testing.T) {
genFunc := func(obj interface{}) []metric.FamilyInterface {
genFunc := func(_ interface{}) []metric.FamilyInterface {
mf1 := metric.Family{
Name: "kube_service_info_1",
Metrics: []*metric.Metric{},
Expand Down
4 changes: 2 additions & 2 deletions pkg/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func NewOptions() *Options {
func (o *Options) AddFlags(cmd *cobra.Command) {
o.cmd = cmd

completionCommand.SetHelpFunc(func(cmd *cobra.Command, args []string) {
completionCommand.SetHelpFunc(func(_ *cobra.Command, _ []string) {
if shellPath, ok := os.LookupEnv("SHELL"); ok {
shell := shellPath[strings.LastIndex(shellPath, "/")+1:]
fmt.Println(FetchLoadInstructions(shell))
Expand All @@ -97,7 +97,7 @@ func (o *Options) AddFlags(cmd *cobra.Command) {
versionCommand := &cobra.Command{
Use: "version",
Short: "Print version information.",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
fmt.Printf("%s\n", version.Print("kube-state-metrics"))
klog.FlushAndExit(klog.ExitFlushTimeout, 0)
},
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestVariableVKsDiscoveryAndResolution(t *testing.T) {
klog.InfoS("started KSM")

// Wait for port 8080 to come up.
err = wait.PollUntilContextTimeout(context.TODO(), 1*time.Second, 20*time.Second, true, func(ctx context.Context) (bool, error) {
err = wait.PollUntilContextTimeout(context.TODO(), 1*time.Second, 20*time.Second, true, func(_ context.Context) (bool, error) {
conn, err := net.Dial("tcp", "localhost:8080")
if err != nil {
return false, nil
Expand Down Expand Up @@ -140,7 +140,7 @@ func TestVariableVKsDiscoveryAndResolution(t *testing.T) {
// Wait for the metric to be available.
ch := make(chan bool, 1)
klog.InfoS("waiting for metrics to become available")
err = wait.PollUntilContextTimeout(context.TODO(), discovery.Interval, PopulateTimeout, true, func(ctx context.Context) (bool, error) {
err = wait.PollUntilContextTimeout(context.TODO(), discovery.Interval, PopulateTimeout, true, func(_ context.Context) (bool, error) {
out, err := exec.Command("curl", "localhost:8080/metrics").Output()
if err != nil {
return false, err
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/hot-reload-kubeconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestKubeConfigHotReload(t *testing.T) {
go internal.RunKubeStateMetricsWrapper(opts)

// Wait for port 8080 to come up.
err = wait.PollUntilContextTimeout(context.TODO(), 1*time.Second, 20*time.Second, true, func(ctx context.Context) (bool, error) {
err = wait.PollUntilContextTimeout(context.TODO(), 1*time.Second, 20*time.Second, true, func(_ context.Context) (bool, error) {
conn, err := net.Dial("tcp", "localhost:8080")
if err != nil {
return false, nil
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestKubeConfigHotReload(t *testing.T) {

// Wait for port 8080 to come up.
ch := make(chan bool, 1)
err = wait.PollUntilContextTimeout(context.TODO(), 1*time.Second, 20*time.Second, true, func(ctx context.Context) (bool, error) {
err = wait.PollUntilContextTimeout(context.TODO(), 1*time.Second, 20*time.Second, true, func(_ context.Context) (bool, error) {
conn, err := net.Dial("tcp", "localhost:8080")
if err != nil {
return false, nil
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/hot-reload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestConfigHotReload(t *testing.T) {
go internal.RunKubeStateMetricsWrapper(opts)

// Wait for port 8080 to come up.
err = wait.PollUntilContextTimeout(context.TODO(), 1*time.Second, 20*time.Second, true, func(ctx context.Context) (bool, error) {
err = wait.PollUntilContextTimeout(context.TODO(), 1*time.Second, 20*time.Second, true, func(_ context.Context) (bool, error) {
conn, err := net.Dial("tcp", "localhost:8080")
if err != nil {
return false, nil
Expand All @@ -89,7 +89,7 @@ func TestConfigHotReload(t *testing.T) {

// Wait for port 8080 to come up.
ch := make(chan bool, 1)
err = wait.PollUntilContextTimeout(context.TODO(), 1*time.Second, 20*time.Second, true, func(ctx context.Context) (bool, error) {
err = wait.PollUntilContextTimeout(context.TODO(), 1*time.Second, 20*time.Second, true, func(_ context.Context) (bool, error) {
conn, err := net.Dial("tcp", "localhost:8080")
if err != nil {
return false, nil
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func getLabelsDocumentation() (map[string][]string, error) {
// Match wildcard patterns for dynamic labels such as label_CRONJOB_LABEL
patternRe := regexp.MustCompile(`_[A-Z_]+`)

err := filepath.WalkDir("../../docs", func(p string, d fs.DirEntry, err error) error {
err := filepath.WalkDir("../../docs", func(p string, d fs.DirEntry, _ error) error {

if d.IsDir() || !fileRe.MatchString(d.Name()) {
// Ignore the entry
Expand Down