Skip to content

Commit b4b6444

Browse files
committed
updates
- switch to golang 1.25 - update dependencies - switch from zap logging to slog Signed-off-by: Markus Blaschke <[email protected]>
1 parent e4d5ede commit b4b6444

File tree

17 files changed

+315
-310
lines changed

17 files changed

+315
-310
lines changed

.github/workflows/build-docker.yaml

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,16 @@ jobs:
1111
lint:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v4
14+
- uses: actions/checkout@v6
1515

16-
- name: Set Swap Space
17-
uses: pierotofy/set-swap-space@49819abfb41bd9b44fb781159c033dba90353a7c
18-
with:
19-
swap-size-gb: 12
16+
- name: Setup runner
17+
uses: webdevops/setup-runner@main
2018

21-
- uses: actions/setup-go@v5
22-
with:
23-
go-version-file: 'go.mod'
24-
cache-dependency-path: "go.sum"
25-
check-latest: true
19+
- name: Setup go
20+
uses: webdevops/setup-go@main
2621

2722
- name: Run Golangci lint
28-
uses: golangci/golangci-lint-action@v7
23+
uses: golangci/golangci-lint-action@v9
2924
with:
3025
version: latest
3126
args: --print-resources-usage
@@ -44,18 +39,13 @@ jobs:
4439

4540
runs-on: ubuntu-latest
4641
steps:
47-
- uses: actions/checkout@v4
42+
- uses: actions/checkout@v6
4843

49-
- name: Set Swap Space
50-
uses: pierotofy/set-swap-space@49819abfb41bd9b44fb781159c033dba90353a7c
51-
with:
52-
swap-size-gb: 12
44+
- name: Setup runner
45+
uses: webdevops/setup-runner@main
5346

54-
- uses: actions/setup-go@v5
55-
with:
56-
go-version-file: 'go.mod'
57-
cache-dependency-path: "go.sum"
58-
check-latest: true
47+
- name: Setup go
48+
uses: webdevops/setup-go@main
5949

6050
- name: Docker meta
6151
id: docker_meta

.github/workflows/ci-docker.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ name: "ci/docker"
22

33
on: [pull_request, workflow_dispatch]
44

5+
concurrency:
6+
group: ${{ github.workflow }}-${{ github.ref }}
7+
cancel-in-progress: true
8+
59
jobs:
610
build:
711
uses: ./.github/workflows/build-docker.yaml

.github/workflows/release-assets.yaml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,34 @@ on:
44
release:
55
types: [created]
66

7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: false
10+
11+
env:
12+
RELEASE_TAG: ${{ github.ref_name }}
13+
714
jobs:
8-
release:
15+
build:
16+
name: "${{ matrix.task }}"
917
runs-on: ubuntu-latest
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
include:
22+
- task: release-assets
1023
steps:
11-
- uses: actions/checkout@v4
24+
- uses: actions/checkout@v6
1225

13-
- name: Set Swap Space
14-
uses: pierotofy/set-swap-space@49819abfb41bd9b44fb781159c033dba90353a7c
15-
with:
16-
swap-size-gb: 12
26+
- name: Setup runner
27+
uses: webdevops/setup-runner@main
1728

18-
- uses: actions/setup-go@v5
19-
with:
20-
go-version-file: 'go.mod'
21-
cache-dependency-path: "go.sum"
22-
check-latest: true
29+
- name: Setup go
30+
uses: webdevops/setup-go@main
2331

2432
- name: Build
2533
run: |
26-
make release-assets
34+
make "${{ matrix.task }}"
2735
2836
- name: Upload assets to release
2937
uses: svenstaro/upload-release-action@v2
@@ -33,3 +41,4 @@ jobs:
3341
tag: ${{ github.ref }}
3442
overwrite: true
3543
file_glob: true
44+
promote: false

.github/workflows/release-docker.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: "release/docker"
22

33
on:
4+
workflow_dispatch: {}
45
push:
56
branches:
67
- 'main'
@@ -9,6 +10,10 @@ on:
910
tags:
1011
- '*.*.*'
1112

13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
1217
jobs:
1318
release:
1419
uses: ./.github/workflows/build-docker.yaml

.github/workflows/schedule-docker.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ on:
44
schedule:
55
- cron: '45 6 * * 1'
66

7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
711
jobs:
812
schedule:
913
uses: ./.github/workflows/build-docker.yaml

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#############################################
22
# Build
33
#############################################
4-
FROM --platform=$BUILDPLATFORM golang:1.24-alpine AS build
4+
FROM --platform=$BUILDPLATFORM golang:1.25-alpine AS build
55

66
RUN apk upgrade --no-cache --force
77
RUN apk add --update build-base make git
@@ -15,6 +15,7 @@ RUN go mod download
1515
# Compile
1616
COPY . .
1717
RUN make test
18+
RUN make build # warmup
1819
ARG TARGETOS TARGETARCH
1920
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} make build
2021

Makefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
PROJECT_NAME := $(shell basename $(CURDIR))
22
GIT_TAG := $(shell git describe --dirty --tags --always)
33
GIT_COMMIT := $(shell git rev-parse --short HEAD)
4-
LDFLAGS := -X "main.gitTag=$(GIT_TAG)" -X "main.gitCommit=$(GIT_COMMIT)" -extldflags "-static" -s -w
4+
BUILD_DATE := $(shell TZ=UTC date '+%Y-%m-%dT%H:%M:%SZ')
5+
LDFLAGS := -X "main.gitTag=$(GIT_TAG)" -X "main.gitCommit=$(GIT_COMMIT)" -X "main.buildDate=$(BUILD_DATE)" -extldflags "-static" -s -w
6+
BUILDFLAGS := -trimpath
57

68
FIRST_GOPATH := $(firstword $(subst :, ,$(shell go env GOPATH)))
79
GOLANGCI_LINT_BIN := $(FIRST_GOPATH)/bin/golangci-lint
@@ -25,13 +27,13 @@ vendor:
2527

2628
.PHONY: build-all
2729
build-all:
28-
GOOS=linux GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o '$(PROJECT_NAME)' .
29-
GOOS=darwin GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o '$(PROJECT_NAME).darwin' .
30-
GOOS=windows GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o '$(PROJECT_NAME).exe' .
30+
GOOS=linux GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' $(BUILDFLAGS) -o '$(PROJECT_NAME)' .
31+
GOOS=darwin GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' $(BUILDFLAGS) -o '$(PROJECT_NAME).darwin' .
32+
GOOS=windows GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' $(BUILDFLAGS) -o '$(PROJECT_NAME).exe' .
3133

3234
.PHONY: build
3335
build:
34-
GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o $(PROJECT_NAME) .
36+
GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' $(BUILDFLAGS) -o $(PROJECT_NAME) .
3537

3638
.PHONY: image
3739
image: image

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,22 @@ Usage:
2121
kube-bootstrap-token-manager [OPTIONS]
2222
2323
Application Options:
24-
--log.debug debug mode [$LOG_DEBUG]
25-
--log.devel development mode [$LOG_DEVEL]
26-
--log.json Switch log output to json format [$LOG_JSON]
24+
--log.level=[trace|debug|info|warning|error] Log level (default: info) [$LOG_LEVEL]
25+
--log.format=[logfmt|json] Log format (default: logfmt) [$LOG_FORMAT]
26+
--log.source=[|short|file|full] Show source for every log message (useful for debugging and bug reports) [$LOG_SOURCE]
27+
--log.color=[|auto|yes|no] Enable color for logs [$LOG_COLOR]
28+
--log.time Show log time [$LOG_TIME]
2729
--bootstraptoken.id-template= Template for token ID for bootstrap tokens (default: {{.Date}}) [$BOOTSTRAPTOKEN_ID_TEMPLATE]
2830
--bootstraptoken.name= Name for bootstrap tokens (default: bootstrap-token-%s) [$BOOTSTRAPTOKEN_NAME]
29-
--bootstraptoken.label= Label for bootstrap tokens (default: webdevops.kubernetes.io/bootstraptoken-managed) [$BOOTSTRAPTOKEN_LABEL]
31+
--bootstraptoken.label= Label for bootstrap tokens (default: bootstraptoken.webdevops.io/managed) [$BOOTSTRAPTOKEN_LABEL]
3032
--bootstraptoken.namespace= Namespace for bootstrap tokens (default: kube-system) [$BOOTSTRAPTOKEN_NAMESPACE]
3133
--bootstraptoken.type= Type for bootstrap tokens (default: bootstrap.kubernetes.io/token) [$BOOTSTRAPTOKEN_TYPE]
3234
--bootstraptoken.usage-bootstrap-authentication= Usage bootstrap authentication for bootstrap tokens (default: true) [$BOOTSTRAPTOKEN_USAGE_BOOTSTRAP_AUTHENTICATION]
3335
--bootstraptoken.usage-bootstrap-signing= usage bootstrap signing for bootstrap tokens (default: true) [$BOOTSTRAPTOKEN_USAGE_BOOTSTRAP_SIGNING]
3436
--bootstraptoken.auth-extra-groups= Auth extra groups for bootstrap tokens (default: system:bootstrappers:worker,system:bootstrappers:ingress) [$BOOTSTRAPTOKEN_AUTH_EXTRA_GROUPS]
3537
--bootstraptoken.expiration= Expiration (time.Duration) for bootstrap tokens (default: 8760h) [$BOOTSTRAPTOKEN_EXPIRATION]
3638
--bootstraptoken.token-length= Length of the random token string for bootstrap tokens (default: 16) [$BOOTSTRAPTOKEN_TOKEN_LENGTH]
37-
--bootstraptoken.token-runes= Runes which should be used for the random token string for bootstrap tokens (default: abcdefghijklmnopqrstuvwxyz0123456789)
38-
[$BOOTSTRAPTOKEN_TOKEN_RUNES]
39+
--bootstraptoken.token-runes= Runes which should be used for the random token string for bootstrap tokens (default: abcdefghijklmnopqrstuvwxyz0123456789) [$BOOTSTRAPTOKEN_TOKEN_RUNES]
3940
--sync.time= Sync time (time.Duration) (default: 1h) [$SYNC_TIME]
4041
--sync.recreate-before= Time duration (time.Duration) when token should be recreated (default: 2190h) [$SYNC_RECREATE_BEFORE]
4142
--sync.full Sync also previous tokens (full sync) [$SYNC_FULL]

cloudprovider/azure.go

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ package cloudprovider
33
import (
44
"context"
55
"errors"
6+
"log/slog"
67
"sort"
78
"time"
89

910
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
10-
"go.uber.org/zap"
11-
1211
"github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azsecrets"
1312
"github.com/webdevops/go-common/azuresdk/armclient"
13+
"github.com/webdevops/go-common/log/slogger"
1414

1515
"github.com/webdevops/kube-bootstrap-token-manager/bootstraptoken"
1616
"github.com/webdevops/kube-bootstrap-token-manager/config"
@@ -27,22 +27,22 @@ type (
2727
opts config.Opts
2828
ctx context.Context
2929

30-
logger *zap.SugaredLogger
30+
logger *slogger.Logger
3131
client *armclient.ArmClient
3232

3333
keyvaultClient *azsecrets.Client
3434
}
3535
)
3636

37-
func (m *CloudProviderAzure) Init(ctx context.Context, opts config.Opts, logger *zap.SugaredLogger, userAgent string) {
37+
func (m *CloudProviderAzure) Init(ctx context.Context, opts config.Opts, logger *slogger.Logger, userAgent string) {
3838
var err error
3939
m.ctx = ctx
4040
m.opts = opts
4141
m.logger = logger.With(
42-
zap.String("cloudprovider", "azure"),
42+
slog.String("cloudprovider", "azure"),
4343
)
4444

45-
m.client, err = armclient.NewArmClientFromEnvironment(logger)
45+
m.client, err = armclient.NewArmClientFromEnvironment(logger.Slog())
4646
if err != nil {
4747
logger.Fatal(err.Error())
4848
}
@@ -62,20 +62,20 @@ func (m *CloudProviderAzure) Init(ctx context.Context, opts config.Opts, logger
6262
}
6363
m.keyvaultClient, err = azsecrets.NewClient(*m.opts.CloudProvider.Azure.KeyVaultUrl, m.client.GetCred(), &secretOpts)
6464
if err != nil {
65-
m.logger.Panic(err)
65+
m.logger.Panic(err.Error())
6666
}
6767
}
6868

6969
func (m *CloudProviderAzure) FetchToken() (token *bootstraptoken.BootstrapToken) {
7070
vaultUrl := *m.opts.CloudProvider.Azure.KeyVaultUrl
7171
secretName := *m.opts.CloudProvider.Azure.KeyVaultSecretName
7272

73-
contextLogger := m.logger.With(zap.String("keyVault", vaultUrl), zap.String("secretName", secretName))
73+
contextLogger := m.logger.With(slog.String("keyVault", vaultUrl), slog.String("secretName", secretName))
7474

75-
contextLogger.Infof("fetching current token from Azure KeyVault \"%s\" secret \"%s\"", vaultUrl, secretName)
75+
contextLogger.Info("fetching current token from Azure KeyVault")
7676
secret, err := m.keyvaultClient.GetSecret(m.ctx, secretName, "", nil)
7777
if m.handleKeyvaultError(contextLogger, err) != nil {
78-
contextLogger.Panic(err)
78+
contextLogger.Panic(err.Error())
7979
}
8080

8181
if secret.Value != nil {
@@ -106,17 +106,16 @@ func (m *CloudProviderAzure) FetchTokens() (tokens []*bootstraptoken.BootstrapTo
106106
vaultUrl := *m.opts.CloudProvider.Azure.KeyVaultUrl
107107
secretName := *m.opts.CloudProvider.Azure.KeyVaultSecretName
108108

109-
contextLogger := m.logger.With(zap.String("keyVault", vaultUrl), zap.String("secretName", secretName))
110-
111-
contextLogger.Infof("fetching all tokens from Azure KeyVault \"%s\" secret \"%s\"", vaultUrl, secretName)
109+
contextLogger := m.logger.With(slog.String("keyVault", vaultUrl), slog.String("secretName", secretName))
110+
contextLogger.Info("fetching all tokens from Azure KeyVault")
112111

113112
pager := m.keyvaultClient.NewListSecretPropertiesVersionsPager(secretName, nil)
114113
// get secrets first
115114
secretCandidateList := []*azsecrets.SecretProperties{}
116115
for pager.More() {
117116
result, err := pager.NextPage(m.ctx)
118117
if err != nil {
119-
m.logger.Panic(err)
118+
m.logger.Panic(err.Error())
120119
}
121120

122121
for _, secretVersion := range result.Value {
@@ -146,11 +145,11 @@ func (m *CloudProviderAzure) FetchTokens() (tokens []*bootstraptoken.BootstrapTo
146145
// process list
147146
secretCounter := 0
148147
for _, secretVersion := range secretCandidateList {
149-
secretLogger := contextLogger.With(zap.String("secretVersion", secretVersion.ID.Version()))
148+
secretLogger := contextLogger.With(slog.String("secretVersion", secretVersion.ID.Version()))
150149

151150
secret, err := m.keyvaultClient.GetSecret(m.ctx, secretVersion.ID.Name(), secretVersion.ID.Version(), nil)
152151
if err != nil {
153-
secretLogger.Warn(`unable to fetch secret "%[2]v" with version "%[3]v" from vault "%[1]v": %[4]w`, vaultUrl, secretVersion.ID.Name(), secretVersion.ID.Version(), err)
152+
secretLogger.Warn(`unable to fetch secret`, slog.Any("error", err))
154153
continue
155154
}
156155

@@ -183,11 +182,15 @@ func (m *CloudProviderAzure) FetchTokens() (tokens []*bootstraptoken.BootstrapTo
183182
}
184183

185184
func (m *CloudProviderAzure) StoreToken(token *bootstraptoken.BootstrapToken) {
186-
contextLogger := m.logger.With(zap.String("token", token.Id()))
187185
vaultUrl := *m.opts.CloudProvider.Azure.KeyVaultUrl
188186
secretName := *m.opts.CloudProvider.Azure.KeyVaultSecretName
189187

190-
contextLogger.Infof("storing token to Azure KeyVault \"%s\" secret \"%s\" with expiration %s", vaultUrl, secretName, token.ExpirationString())
188+
contextLogger := m.logger.With(
189+
slog.String("token", token.Id()),
190+
slog.String("keyVault", vaultUrl),
191+
slog.String("secretName", secretName),
192+
)
193+
contextLogger.Info("storing token to Azure KeyVault", slog.String("expiration", token.ExpirationString()))
191194

192195
secretParameters := azsecrets.SetSecretParameters{
193196
Value: stringPtr(token.FullToken()),
@@ -204,7 +207,7 @@ func (m *CloudProviderAzure) StoreToken(token *bootstraptoken.BootstrapToken) {
204207

205208
_, err := m.keyvaultClient.SetSecret(m.ctx, secretName, secretParameters, nil)
206209
if err != nil {
207-
m.logger.Panic(err)
210+
m.logger.Panic(err.Error())
208211
}
209212
}
210213

@@ -227,7 +230,7 @@ func (m *CloudProviderAzure) updateTokenMeta(token *bootstraptoken.BootstrapToke
227230
}
228231
}
229232

230-
func (m *CloudProviderAzure) handleKeyvaultError(logger *zap.SugaredLogger, err error) error {
233+
func (m *CloudProviderAzure) handleKeyvaultError(logger *slogger.Logger, err error) error {
231234
if err != nil {
232235
switch m.parseAzCoreResponseError(err) {
233236
case "SecretNotFound":

cloudprovider/base.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import (
55
"fmt"
66
"strings"
77

8-
"go.uber.org/zap"
8+
"github.com/webdevops/go-common/log/slogger"
99

1010
"github.com/webdevops/kube-bootstrap-token-manager/bootstraptoken"
1111
"github.com/webdevops/kube-bootstrap-token-manager/config"
1212
)
1313

1414
type (
1515
CloudProvider interface {
16-
Init(ctx context.Context, opts config.Opts, logger *zap.SugaredLogger, userAgent string)
16+
Init(ctx context.Context, opts config.Opts, logger *slogger.Logger, userAgent string)
1717
FetchToken() (token *bootstraptoken.BootstrapToken)
1818
FetchTokens() (token []*bootstraptoken.BootstrapToken)
1919
StoreToken(token *bootstraptoken.BootstrapToken)
@@ -26,5 +26,5 @@ func NewCloudProvider(provider string) CloudProvider {
2626
return &CloudProviderAzure{}
2727
}
2828

29-
panic(fmt.Sprintf("Cloud provider \"%s\" not available", provider))
29+
panic(fmt.Sprintf("cloud provider \"%s\" not available", provider))
3030
}

0 commit comments

Comments
 (0)