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

Run 'lint-install', address lint issues #14

Merged
merged 3 commits into from
Sep 10, 2021
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
202 changes: 202 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
# NOTE: This file is populated by the lint-install tool. Local adjustments may be overwritten.
linters-settings:
cyclop:
# NOTE: This is a very high transitional threshold
max-complexity: 37
package-average: 34.0
skip-tests: true

gocognit:
# NOTE: This is a very high transitional threshold
min-complexity: 98

dupl:
threshold: 200

goconst:
min-len: 4
min-occurrences: 5
ignore-tests: true

gosec:
excludes:
- G107 # Potential HTTP request made with variable url
- G204 # Subprocess launched with function call as argument or cmd arguments
- G404 # Use of weak random number generator (math/rand instead of crypto/rand

errorlint:
# these are still common in Go: for instance, exit errors.
asserts: false

exhaustive:
default-signifies-exhaustive: true

nestif:
min-complexity: 8

nolintlint:
require-explanation: true
allow-unused: false
require-specific: true

revive:
ignore-generated-header: true
severity: warning
rules:
- name: atomic
- name: blank-imports
- name: bool-literal-in-expr
- name: confusing-naming
- name: constant-logical-expr
- name: context-as-argument
- name: context-keys-type
- name: deep-exit
- name: defer
- name: range-val-in-closure
- name: range-val-address
- name: dot-imports
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: exported
- name: identical-branches
- name: if-return
- name: import-shadowing
- name: increment-decrement
- name: indent-error-flow
- name: indent-error-flow
- name: package-comments
- name: range
- name: receiver-naming
- name: redefines-builtin-id
- name: superfluous-else
- name: struct-tag
- name: time-naming
- name: unexported-naming
- name: unexported-return
- name: unnecessary-stmt
- name: unreachable-code
- name: unused-parameter
- name: var-declaration
- name: var-naming
- name: unconditional-recursion
- name: waitgroup-by-value

staticcheck:
go: "1.16"

unused:
go: "1.16"

output:
sort-results: true

linters:
disable-all: true
enable:
- asciicheck
- bodyclose
- cyclop
- deadcode
- dogsled
- dupl
- durationcheck
- errcheck
# errname is only available in golangci-lint v1.42.0+ - wait until v1.43 is available to settle
#- errname
- errorlint
- exhaustive
- exportloopref
- forcetypeassert
- gocognit
- goconst
- gocritic
- godot
- gofmt
- gofumpt
- gosec
- goheader
- goimports
- goprintffuncname
- gosimple
- govet
- ifshort
- importas
- ineffassign
- makezero
- misspell
- nakedret
- nestif
- nilerr
- noctx
- nolintlint
- predeclared
# disabling for the initial iteration of the linting tool
#- promlinter
- revive
- rowserrcheck
- sqlclosecheck
- staticcheck
- structcheck
- stylecheck
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- varcheck
- wastedassign
- whitespace

# Disabled linters, due to being misaligned with Go practices
# - exhaustivestruct
# - gochecknoglobals
# - gochecknoinits
# - goconst
# - godox
# - goerr113
# - gomnd
# - lll
# - nlreturn
# - testpackage
# - wsl
# Disabled linters, due to not being relevant to our code base:
# - maligned
# - prealloc "For most programs usage of prealloc will be a premature optimization."
# Disabled linters due to bad error messages or bugs
# - tagliatelle

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- gocyclo
- errcheck
- dupl
- gosec

- path: cmd.*
linters:
- noctx

- path: main\.go
linters:
- noctx

- path: cmd.*
text: "deep-exit"

- path: main\.go
text: "deep-exit"

# This check is of questionable value
- linters:
- tparallel
text: "call t.Parallel on the top level as well as its subtests"

# Don't hide lint issues just because there are many of them
max-same-issues: 0
max-issues-per-linter: 0
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

# BEGIN: lint-install ../infrastructure/
# http://github.com/tinkerbell/lint-install

GOLINT_VERSION ?= v1.42.0


LINT_OS := $(shell uname)
LINT_ARCH := $(shell uname -m)

# shellcheck and hadolint lack arm64 native binaries: rely on x86-64 emulation
ifeq ($(LINT_OS),Darwin)
ifeq ($(LINT_ARCH),arm64)
LINT_ARCH=x86_64
endif
endif


GOLINT_CONFIG:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))/.golangci.yml

lint: out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH)
find . -name go.mod | xargs -n1 dirname | xargs -n1 -I{} sh -c "cd {} && golangci-lint run -c $(GOLINT_CONFIG)"

out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH):
mkdir -p out/linters
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b out/linters $(GOLINT_VERSION)
mv out/linters/golangci-lint out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH)

# END: lint-install ../infrastructure/
12 changes: 5 additions & 7 deletions pulumi/src/assets/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"github.com/tinkerbell/infrastructure/src/internal"
)

type AssetsDns struct {
type DNS struct {
Cname *ns1.Record
}

func CreateAssetsDns(ctx *pulumi.Context, infrastructure internal.Infrastructure) (AssetsDns, error) {
func CreateDNS(ctx *pulumi.Context, infrastructure internal.Infrastructure) (DNS, error) {
// This verification record is required for Cloudflare to issue a certificate for this domain
_, err := ns1.NewRecord(ctx, "assets-cname-verification", &ns1.RecordArgs{
Zone: pulumi.String(infrastructure.Zone.Zone),
Expand All @@ -22,9 +22,8 @@ func CreateAssetsDns(ctx *pulumi.Context, infrastructure internal.Infrastructure
},
},
})

if err != nil {
return AssetsDns{}, err
return DNS{}, err
}

// assets.tinkerbell.org
Expand All @@ -41,12 +40,11 @@ func CreateAssetsDns(ctx *pulumi.Context, infrastructure internal.Infrastructure
},
},
})

if err != nil {
return AssetsDns{}, err
return DNS{}, err
}

return AssetsDns{
return DNS{
Cname: cname,
}, nil
}
3 changes: 1 addition & 2 deletions pulumi/src/dns/tinkerbell.org/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import (
"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)

func ManageDns(ctx *pulumi.Context) (ns1.LookupZoneResult, error) {
func ManageDNS(ctx *pulumi.Context) (ns1.LookupZoneResult, error) {
zone, err := ns1.LookupZone(ctx, &ns1.LookupZoneArgs{
Zone: "tinkerbell.org",
})

if err != nil {
return ns1.LookupZoneResult{}, err
}
Expand Down
11 changes: 4 additions & 7 deletions pulumi/src/github-actions/cloud-init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import (
)

type MinionConfig struct {
MasterIp string
MasterIP string
States []string
}

func cloudInitConfig(config *MinionConfig) string {
c, err := cloudinit.New("focal")

if err != nil {
panic(err)
}
Expand All @@ -32,27 +31,25 @@ schedule:
minutes: 15

grains:
role: github-action-runner`, 0644)
role: github-action-runner`, 0o644)

// I'm really trying to avoid bringing in any templating library to
// write this configuration, so I'm going to write each requested state to its
// own conf, which Salt will merge when the minion starts
// Sorry
for _, state := range config.States {
c.AddRunTextFile(fmt.Sprintf("/etc/salt/minion.d/gha_runner_state_%s.conf", state), fmt.Sprintf("grains:\n gha_runner_states:\n - %s", state), 0644)
c.AddRunTextFile(fmt.Sprintf("/etc/salt/minion.d/gha_runner_state_%s.conf", state), fmt.Sprintf("grains:\n gha_runner_states:\n - %s", state), 0o644)
}

c.AddRunCmd(fmt.Sprintf("echo master: %s > /etc/salt/minion.d/master.conf", config.MasterIp))
c.AddRunCmd(fmt.Sprintf("echo master: %s > /etc/salt/minion.d/master.conf", config.MasterIP))
c.AddRunCmd("systemctl daemon-reload")
c.AddRunCmd("systemctl enable salt-minion.service")
c.AddRunCmd("systemctl restart --no-block salt-minion.service")

script, err := c.RenderScript()

if err != nil {
panic(err)
}

return script

}
11 changes: 5 additions & 6 deletions pulumi/src/github-actions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ type GitHubConfig struct {
}

// GitHubActionRunnerConfig is the struct we allow in the stack configuration
// to describe the GitHubActionRunner we provision
// to describe the GitHubActionRunner we provision.
type GitHubActionRunnerConfig struct {
Facility equinix.Facility
Plan equinix.Plan
States []string
}

// GitHubActionRunner is the return struct for CreateSaltMaster
// GitHubActionRunner is the return struct for CreateSaltMaster.
type GitHubActionRunners struct {
Devices []equinix.Device
}

// CreateGitHubActionRunner Provisions a GitHub Action Runner
// CreateGitHubActionRunner Provisions a GitHub Action Runner.
func CreateGitHubActionRunners(ctx *pulumi.Context, infrastructure internal.Infrastructure) (GitHubActionRunners, error) {
metalConfig := config.New(ctx, "equinix-metal")
projectID := metalConfig.Require("projectId")
Expand All @@ -50,16 +50,15 @@ func CreateGitHubActionRunners(ctx *pulumi.Context, infrastructure internal.Infr
pulumi.String("role:github-action-runner"),
},
BillingCycle: equinix.BillingCycleHourly,
UserData: pulumi.All(infrastructure.SaltMasterIp, runner.States).ApplyT(func(args []interface{}) string {
UserData: pulumi.All(infrastructure.SaltMasterIP, runner.States).ApplyT(func(args []interface{}) string {
return cloudInitConfig(&MinionConfig{
MasterIp: args[0].(string),
MasterIP: args[0].(string),
States: args[1].([]string),
})
}).(pulumi.StringOutput),
}

device, err := equinix.NewDevice(ctx, fmt.Sprintf("github-action-runner-%d", i), &deviceArgs)

if err != nil {
return GitHubActionRunners{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion pulumi/src/internal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import (
// with DNS zone being the first use-case.
type Infrastructure struct {
Zone ns1.LookupZoneResult
SaltMasterIp pulumi.StringOutput
SaltMasterIP pulumi.StringOutput
}
Loading