Fix linting issues and update make lint target.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff
2022-09-26 20:16:30 +00:00
parent 70848cfdae
commit 2c4442b17f
6 changed files with 34 additions and 8 deletions

View File

@@ -2,3 +2,5 @@
private.env private.env
*.private.* *.private.*
providers/azurebatch/deployment/ providers/azurebatch/deployment/
Dockerfile
.dockerignore

View File

@@ -2,6 +2,8 @@ linter-settings:
lll: lll:
line-length: 200 line-length: 200
timeout: 10m
run: run:
skip-dirs: skip-dirs:
# This directory contains copy code from upstream kubernetes/kubernetes, skip it. # This directory contains copy code from upstream kubernetes/kubernetes, skip it.

View File

@@ -1,3 +1,5 @@
ARG GOLANG_CI_LINT_VERSION
FROM golang:1.18 as builder FROM golang:1.18 as builder
ENV PATH /go/bin:/usr/local/go/bin:$PATH ENV PATH /go/bin:/usr/local/go/bin:$PATH
ENV GOPATH /go ENV GOPATH /go
@@ -7,6 +9,22 @@ ARG BUILD_TAGS=""
RUN make VK_BUILD_TAGS="${BUILD_TAGS}" build RUN make VK_BUILD_TAGS="${BUILD_TAGS}" build
RUN cp bin/virtual-kubelet /usr/bin/virtual-kubelet RUN cp bin/virtual-kubelet /usr/bin/virtual-kubelet
FROM golangci/golangci-lint:${GOLANG_CI_LINT_VERSION} as lint
WORKDIR /app
COPY go.mod ./
COPY go.sum ./
RUN \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
go mod download
COPY . .
ARG OUT_FORMAT
RUN \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/golangci-lint \
golangci-lint run -v $(if [ -n "${OUT_FORMAT}" ]; then echo "--out-format=${OUT_FORMAT}"; fi)
FROM scratch FROM scratch
COPY --from=builder /usr/bin/virtual-kubelet /usr/bin/virtual-kubelet COPY --from=builder /usr/bin/virtual-kubelet /usr/bin/virtual-kubelet
COPY --from=builder /etc/ssl/certs/ /etc/ssl/certs COPY --from=builder /etc/ssl/certs/ /etc/ssl/certs

View File

@@ -183,6 +183,10 @@ envtest: kubebuilder_2.3.1_${TEST_OS}_${TEST_ARCH}
fmt: fmt:
goimports -w $(shell go list -f '{{.Dir}}' ./...) goimports -w $(shell go list -f '{{.Dir}}' ./...)
export GOLANG_CI_LINT_VERSION ?= v1.48.0
DOCKER_BUILD ?= docker buildx build
.PHONY: lint .PHONY: lint
lint: $(gobin_tool) lint:
gobin -run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.33.0 run ./... $(DOCKER_BUILD) --target=lint --build-arg GOLANG_CI_LINT_VERSION --build-arg OUT_FORMAT .

View File

@@ -5,8 +5,8 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math/rand" "math/rand"
"os"
"strings" "strings"
"time" "time"
@@ -97,7 +97,7 @@ func NewMockProvider(providerConfig, nodeName, operatingSystem string, internalI
// loadConfig loads the given json configuration files. // loadConfig loads the given json configuration files.
func loadConfig(providerConfig, nodeName string) (config MockConfig, err error) { func loadConfig(providerConfig, nodeName string) (config MockConfig, err error) {
data, err := ioutil.ReadFile(providerConfig) data, err := os.ReadFile(providerConfig)
if err != nil { if err != nil {
return config, err return config, err
} }
@@ -283,7 +283,7 @@ func (p *MockProvider) GetContainerLogs(ctx context.Context, namespace, podName,
ctx = addAttributes(ctx, span, namespaceKey, namespace, nameKey, podName, containerNameKey, containerName) ctx = addAttributes(ctx, span, namespaceKey, namespace, nameKey, podName, containerNameKey, containerName)
log.G(ctx).Infof("receive GetContainerLogs %q", podName) log.G(ctx).Infof("receive GetContainerLogs %q", podName)
return ioutil.NopCloser(strings.NewReader("")), nil return io.NopCloser(strings.NewReader("")), nil
} }
// RunInContainer executes a command in a container in the pod, copying data // RunInContainer executes a command in a container in the pod, copying data

View File

@@ -4,7 +4,7 @@ import (
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"fmt" "fmt"
"io/ioutil" "os"
) )
// WithTLSConfig returns a NodeOpt which creates a base TLSConfig with the default cipher suites and tls min verions. // WithTLSConfig returns a NodeOpt which creates a base TLSConfig with the default cipher suites and tls min verions.
@@ -31,7 +31,7 @@ func WithTLSConfig(opts ...func(*tls.Config) error) NodeOpt {
// WithCAFromPath makes a TLS config option to set up client auth using the path to a PEM encoded CA cert. // WithCAFromPath makes a TLS config option to set up client auth using the path to a PEM encoded CA cert.
func WithCAFromPath(p string) func(*tls.Config) error { func WithCAFromPath(p string) func(*tls.Config) error {
return func(cfg *tls.Config) error { return func(cfg *tls.Config) error {
pem, err := ioutil.ReadFile(p) pem, err := os.ReadFile(p)
if err != nil { if err != nil {
return fmt.Errorf("error reading ca cert pem: %w", err) return fmt.Errorf("error reading ca cert pem: %w", err)
} }