Skip to content

Commit d314c27

Browse files
committed
update makefile and improve lint
Signed-off-by: Markus Blaschke <mblaschke82@gmail.com>
1 parent 4eecfc2 commit d314c27

File tree

4 files changed

+19
-26
lines changed

4 files changed

+19
-26
lines changed

Makefile

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,45 @@
1-
.PHONY: all build clean image check vendor dependencies
2-
3-
NAME := kube-bootstrap-token-manager
1+
PROJECT_NAME := kube-bootstrap-token-manager
42
GIT_TAG := $(shell git describe --dirty --tags --always)
53
GIT_COMMIT := $(shell git rev-parse --short HEAD)
6-
LDFLAGS := -X "main.gitTag=$(GIT_TAG)" -X "main.gitCommit=$(GIT_COMMIT)" -extldflags "-static"
7-
8-
PKGS := $(shell go list ./... | grep -v -E '/vendor/|/test')
9-
FIRST_GOPATH := $(firstword $(subst :, ,$(shell go env GOPATH)))
10-
GOLANGCI_LINT_BIN := $(FIRST_GOPATH)/bin/golangci-lint
4+
LDFLAGS := -X "main.gitTag=$(GIT_TAG)" -X "main.gitCommit=$(GIT_COMMIT)" -extldflags "-static"
115

6+
FIRST_GOPATH := $(firstword $(subst :, ,$(shell go env GOPATH)))
7+
GOLANGCI_LINT_BIN := $(FIRST_GOPATH)/bin/golangci-lint
128

9+
.PHONY: all
1310
all: build
1411

12+
.PHONY: clean
1513
clean:
1614
git clean -Xfd .
1715

16+
.PHONY: build
1817
build:
19-
CGO_ENABLED=0 go build -a -ldflags '$(LDFLAGS)' -o $(NAME) .
18+
CGO_ENABLED=0 go build -a -ldflags '$(LDFLAGS)' -o $(PROJECT_NAME) .
2019

20+
.PHONY: vendor
2121
vendor:
2222
go mod tidy
2323
go mod vendor
2424
go mod verify
2525

26+
.PHONY: image
2627
image: build
27-
docker build -t $(NAME):$(TAG) .
28+
docker build -t $(PROJECT_NAME):$(GIT_TAG) .
2829

2930
build-push-development:
30-
docker build -t webdevops/$(NAME):development . && docker push webdevops/$(NAME):development
31+
docker build -t webdevops/$(PROJECT_NAME):development . && docker push webdevops/$(PROJECT_NAME):development
3132

33+
.PHONY: test
3234
test:
3335
go test ./...
3436

3537
.PHONY: lint
3638
lint: $(GOLANGCI_LINT_BIN)
37-
# megacheck fails to respect build flags, causing compilation failure during linting.
38-
# instead, use the unused, gosimple, and staticcheck linters directly
39-
$(GOLANGCI_LINT_BIN) run -D megacheck -E unused,gosimple,staticcheck --timeout=10m
39+
$(GOLANGCI_LINT_BIN) run -E exportloopref,gofmt --timeout=10m
4040

41+
.PHONY: dependencies
4142
dependencies: $(GOLANGCI_LINT_BIN)
42-
go mod download
4343

4444
$(GOLANGCI_LINT_BIN):
45-
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(FIRST_GOPATH)/bin v1.30.0
46-
45+
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(FIRST_GOPATH)/bin v1.32.2

bootstraptoken/token.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (t *BootstrapToken) ExpirationString() (expiration string) {
4747
expiration = fmt.Sprintf(
4848
"%s (%s)",
4949
t.expirationTime.Format(time.RFC3339),
50-
t.expirationTime.Sub(time.Now()),
50+
time.Until(*t.expirationTime),
5151
)
5252
}
5353

cloudprovider/azure.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (m *CloudProviderAzure) FetchTokens() (tokens []*bootstraptoken.BootstrapTo
128128
}
129129

130130
// ignore not enabled
131-
if secret.Attributes.Enabled != nil && *secret.Attributes.Enabled == false {
131+
if secret.Attributes.Enabled != nil && !*secret.Attributes.Enabled {
132132
secretLogger.Debug("ignoring, secret is disabled")
133133
continue
134134
}
@@ -223,11 +223,9 @@ func (m *CloudProviderAzure) handleKeyvaultError(err error, logger *log.Entry) e
223223
case "SecretNotFound":
224224
// no secret found, need to create new token
225225
logger.Warn("no secret found, assuming non existing token")
226-
break
227226
case "SecretDisabled":
228227
// disabled secret, continue as there would be no token
229228
logger.Warn("current secret is disabled, assuming non existing token")
230-
break
231229
case "ForbiddenByPolicy":
232230
// access is forbidden
233231
logger.Error("unable to access Azure KeyVault, please check access")

manager/manager.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,5 @@ func (m *KubeBootstrapTokenManager) checkTokenRenewal(token *bootstraptoken.Boot
357357
}
358358

359359
renewalTime := time.Now().Add(m.Opts.Sync.RecreateBefore)
360-
if token.ExpirationTime().Before(renewalTime) {
361-
return true
362-
}
363-
364-
return false
360+
return token.ExpirationTime().Before(renewalTime)
365361
}

0 commit comments

Comments
 (0)