diff --git a/.codespell.ignorewords b/.codespell.ignorewords new file mode 100644 index 000000000..78cf86273 --- /dev/null +++ b/.codespell.ignorewords @@ -0,0 +1 @@ +ue diff --git a/.codespell.skip b/.codespell.skip new file mode 100644 index 000000000..bfe99f180 --- /dev/null +++ b/.codespell.skip @@ -0,0 +1,4 @@ +./.git +./vendor +./bin +./go.sum diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 000000000..5871e2e5d --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,55 @@ +name: CI +on: + pull_request: + push: + branches: + - master + +jobs: + build: + name: Build + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + + - name: Set up Go + uses: actions/setup-go@v2.1.2 + with: + go-version: '1.15.3' + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v2.3.3 + + - name: Run CI checks + run: make ci + + lint: + name: Lint + runs-on: ubuntu-latest + container: golangci/golangci-lint:v1.32.2 + timeout-minutes: 10 + steps: + + - uses: actions/checkout@v2.3.3 + with: + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.sha }} + + - name: Run lint + run: make lint-bin + + codespell: + name: Codespell + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + + - uses: actions/checkout@v2.3.3 + - name: Codespell test + uses: codespell-project/actions-codespell@master + with: + skip: ./.git,./vendor,./bin,./go.sum + ignore_words_file: '.codespell.ignorewords' + check_filenames: true + check_hidden: true diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000..c744f47d4 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,70 @@ +run: + modules-download-mode: vendor + timeout: 5m + +issues: + exclude-use-default: false + max-same-issues: 0 + max-issues-per-linter: 0 + +# List for enabled linters can be generated for updates using the following command. +# golangci-lint linters | grep -E '^\S+:' | cut -d: -f1 | sort | sed 's/^/ - /g' | grep -v -E "($(grep '^ disable:' -A 100 .golangci.yml | grep -E ' - \S+$' | awk '{print $2}' | tr \\n '|' | sed 's/|$//g'))" +linters: + disable-all: false + enable: + - asciicheck + - bodyclose + - deadcode + - depguard + - dogsled + - dupl + - errcheck + - errorlint + - exhaustive + - exhaustivestruct + - exportloopref + - funlen + - gochecknoinits + - gocognit + - goconst + - gocritic + - gocyclo + - godot + - gofmt + - gofumpt + - goheader + - goimports + - golint + - gomnd + - gomodguard + - goprintffuncname + - ineffassign + - interfacer + - lll + - maligned + - misspell + - nakedret + - nestif + - nlreturn + - noctx + - nolintlint + - prealloc + - rowserrcheck + - scopelint + - sqlclosecheck + - structcheck + - stylecheck + - testpackage + - tparallel + - typecheck + - unconvert + - unparam + - varcheck + - whitespace + - wrapcheck + - wsl + disable: + - gci + - gochecknoglobals + - godox + - goerr113 diff --git a/Makefile b/Makefile index 7a0c961b0..ccf13e8b3 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all release-bin image clean test vendor +.PHONY: all release-bin image clean test vendor ci lint-bin codespell export CGO_ENABLED:=0 VERSION=$(shell ./build/git-version.sh) @@ -33,3 +33,15 @@ vendor: clean: rm -rf bin + +ci: all test + +lint-bin: + @if [ "$$(git config --get diff.noprefix)" = "true" ]; then printf "\n\ngolangci-lint has a bug and can't run with the current git configuration: 'diff.noprefix' is set to 'true'. To override this setting for this repository, run the following command:\n\n'git config diff.noprefix false'\n\nFor more details, see https://github.com/golangci/golangci-lint/issues/948.\n\n\n"; exit 1; fi + golangci-lint run --new-from-rev=$$(git merge-base $$(cat .git/resource/base_sha 2>/dev/null || echo "origin/master") HEAD) ./... + +codespell: CODESPELL_SKIP := $(shell cat .codespell.skip | tr \\n ',') +codespell: CODESPELL_BIN := codespell +codespell: + which $(CODESPELL_BIN) >/dev/null 2>&1 || (echo "$(CODESPELL_BIN) binary not found, skipping spell checking"; exit 0) + $(CODESPELL_BIN) --skip $(CODESPELL_SKIP) --ignore-words .codespell.ignorewords --check-filenames --check-hidden diff --git a/doc/labels-and-annotations.md b/doc/labels-and-annotations.md index d9114c946..0785051bf 100644 --- a/doc/labels-and-annotations.md +++ b/doc/labels-and-annotations.md @@ -10,7 +10,7 @@ A few labels may be set directly by admins to customize behavior. These are call | name | example | setter | description | |-------|------------|--------|---------------| -| agent | true/false | admin, update-operator | When the `auto-label-flatcar-linux` compatability mode is enabled (via flag), the `update-operator` sets agent true on Flatcar Container Linux nodes. This is a convenient label that users may node selector upon, if desired. | +| agent | true/false | admin, update-operator | When the `auto-label-flatcar-linux` compatibility mode is enabled (via flag), the `update-operator` sets agent true on Flatcar Container Linux nodes. This is a convenient label that users may node selector upon, if desired. | | before-reboot | true | update-operator | The `update-operator` sets the `before-reboot` label when a machine want to reboot. It signifies that the before-reboot checks should run on the node, if there are any. | | after-reboot | true | update-operator | The `update-operator` sets the `after-reboot` label when a machine has completed it's reboot. It signifies that the after-reboot checks should run on the node, if there are any. | diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index fc6bca1a3..acb9627e4 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -52,11 +52,12 @@ const ( // It is an opaque string, but might be semver. AnnotationNewVersion = Prefix + "new-version" - // Ket set by update-agent to indicate it was responsible for making node unschedulable + // AnnotationAgentMadeUnschedulable is a key set by update-agent to indicate + // it was responsible for making node unschedulable. AnnotationAgentMadeUnschedulable = Prefix + "agent-made-unschedulable" // Keys set to true when the operator is waiting for configured annotation - // before and after the reboot repectively + // before and after the reboot respectively. LabelBeforeReboot = Prefix + "before-reboot" LabelAfterReboot = Prefix + "after-reboot" diff --git a/pkg/k8sutil/selector.go b/pkg/k8sutil/selector.go index 9c29e9de6..1cc756cf2 100644 --- a/pkg/k8sutil/selector.go +++ b/pkg/k8sutil/selector.go @@ -9,7 +9,7 @@ import ( "k8s.io/apimachinery/pkg/selection" ) -// NewRequirementOrDie wraps a call to NewRequirement and panics if the Requirment +// NewRequirementOrDie wraps a call to NewRequirement and panics if the Requirement // cannot be created. It is intended for use in variable initializations only. func NewRequirementOrDie(key string, op selection.Operator, vals []string) *labels.Requirement { req, err := labels.NewRequirement(key, op, vals) diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index 9a9238aae..823800f30 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -101,7 +101,7 @@ type Kontroller struct { // It will be set to the namespace the operator is running in automatically. namespace string - // auto-label Flatcar Container Linux nodes for migration compatability + // auto-label Flatcar Container Linux nodes for migration compatibility autoLabelContainerLinux bool // reboot window @@ -116,7 +116,7 @@ type Kontroller struct { type Config struct { // Kubernetesc client Client kubernetes.Interface - // migration compatability + // migration compatibility AutoLabelContainerLinux bool // annotations to look for before and after reboots BeforeRebootAnnotations []string @@ -193,7 +193,7 @@ func New(config Config) (*Kontroller, error) { }, nil } -// Run starts the operator reconcilitation proces and runs until the stop +// Run starts the operator reconcilitation process and runs until the stop // channel is closed. func (k *Kontroller) Run(stop <-chan struct{}) error { err := k.withLeaderElection() @@ -206,7 +206,7 @@ func (k *Kontroller) Run(stop <-chan struct{}) error { go wait.Until(k.legacyLabeler, reconciliationPeriod, stop) } - // Before doing anytihng else, make sure the associated agent daemonset is + // Before doing anything else, make sure the associated agent daemonset is // ready if it's our responsibility. if k.manageAgent && k.agentImageRepo != "" { // create or update the update-agent daemonset diff --git a/pkg/version/version.go b/pkg/version/version.go index 7ace3b4ab..726c02a66 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -23,7 +23,8 @@ var Semver semver.Version func init() { v, err := semver.Parse(Version) if err != nil { - glog.Fatalf("invalid build of update operator; version.Version must be set at compiletime to a valid semver value. %v could not parse: %v", Version, err) + glog.Fatalf("invalid build of update operator; version.Version must be set at compile "+ + "time to a valid semver value. %v could not parse: %v", Version, err) } Semver = v }