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

KUBE-553: add podname and enable linters #13

Merged
merged 14 commits into from
Sep 19, 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
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
CGO_ENABLED: 0

- name: Test
run: go test -race ./...
run: make test

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/fossa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: FOSSA
on:
push:
branches:
- main
jobs:
fossa-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: fossas/fossa-action@v1
with:
api-key: ${{ secrets.FOSSA_API_KEY }}
ValyaB marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 18 additions & 0 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: golangci-lint
on:
pull_request:
permissions:
contents: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
args: --timeout=5m
93 changes: 93 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
linters:
disable-all: true
enable:
- containedctx
- dogsled
- dupword
- durationcheck
- errcheck
- errname
- errorlint
- gci
- gocognit
- goconst
- gocritic
- godot
- gofmt
- gofumpt
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- paralleltest
- revive
- sqlclosecheck
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- whitespace

linters-settings:
gocritic:
enabled-all: true
disabled-checks:
- commentFormatting
godot:
scope: all
gofumpt:
module-path: cloud-proxy
extra-rules: true
goconst:
min-len: 2
min-occurrences: 5
golint:
min-confidence: 0
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: [argument,case,condition,return]
govet:
# shadow is marked as experimental feature, skip it for now.
check-shadowing: false
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
lll:
line-length: 200
maligned:
suggest-new: true
misspell:
locale: US
revive:
rules:
- name: redefines-builtin-id
disabled: true

# Allow code like:
# Items: binpacking.Items{
# {
# },
# }
- name: nested-structs
disabled: true
gci:
sections:
- standard
- default
- prefix(cloud-proxy)
issues:
exclude-dirs:
- mock
- internal/castai
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,14 @@ generate-grpc:
--go-grpc_out=proto/gen --go-grpc_opt paths=source_relative
.PHONY: generate-grpc

lint:
golangci-lint run ./...
.PHONY: lint

fix:
golangci-lint run --fix ./...
.PHONY: fix

test:
go test ./... -race
.PHONY: test
23 changes: 11 additions & 12 deletions cmd/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import (
"runtime"
"time"

"cloud-proxy/internal/cloud/gcp"
"cloud-proxy/internal/cloud/gcp/gcpauth"
"cloud-proxy/internal/config"
"cloud-proxy/internal/healthz"
"cloud-proxy/internal/proxy"

"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/backoff"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"

"cloud-proxy/internal/cloud/gcp"
"cloud-proxy/internal/cloud/gcp/gcpauth"
"cloud-proxy/internal/config"
"cloud-proxy/internal/healthz"
"cloud-proxy/internal/proxy"
)

var (
Expand All @@ -35,7 +35,7 @@ func main() {

dialOpts := make([]grpc.DialOption, 0)
if cfg.CastAI.DisableGRPCTLS {
// ONLY For testing purposes
// ONLY For testing purposes.
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
} else {
dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(nil)))
Expand Down Expand Up @@ -73,14 +73,13 @@ func main() {
}(conn)

ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(
"authorization", fmt.Sprintf("Token %s", cfg.CastAI.ApiKey),
"authorization", fmt.Sprintf("Token %s", cfg.CastAI.APIKey),
))

client := proxy.New(conn, gcp.New(gcpauth.NewCredentialsSource(), http.DefaultClient), logger,
cfg.ClusterID, GetVersion(), cfg.KeepAlive, cfg.KeepAliveTimeout)

go startHealthServer(logger, cfg.HealthAddress)

client := proxy.New(conn, gcp.New(gcpauth.NewCredentialsSource(), http.DefaultClient), logger,
cfg.GetPodName(), cfg.ClusterID, GetVersion(), cfg.KeepAlive, cfg.KeepAliveTimeout)
err = client.Run(ctx)
if err != nil {
logger.Panicf("Failed to run client: %v", err)
Expand All @@ -97,7 +96,7 @@ func setupLogger(cfg config.Config) *logrus.Logger {
logger.SetLevel(logrus.Level(cfg.Log.Level))
logger.SetReportCaller(true)
logger.Formatter = &logrus.TextFormatter{
CallerPrettyfier: func(f *runtime.Frame) (function string, file string) {
CallerPrettyfier: func(f *runtime.Frame) (function, file string) {
filename := path.Base(f.File)
return fmt.Sprintf("%s()", f.Function), fmt.Sprintf("%s:%d", filename, f.Line)
},
Expand Down
4 changes: 0 additions & 4 deletions e2e/Dockerfile

This file was deleted.

23 changes: 0 additions & 23 deletions e2e/chart/.helmignore

This file was deleted.

24 changes: 0 additions & 24 deletions e2e/chart/Chart.yaml

This file was deleted.

62 changes: 0 additions & 62 deletions e2e/chart/templates/_helpers.tpl

This file was deleted.

22 changes: 0 additions & 22 deletions e2e/chart/templates/job.yaml

This file was deleted.

15 changes: 0 additions & 15 deletions e2e/chart/templates/service.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions e2e/chart/values.yaml

This file was deleted.

Loading
Loading