Skip to content
Open
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
52 changes: 52 additions & 0 deletions .github/workflows/pre-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Test Incoming Changes

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5

- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: true

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: latest
args: --timeout=5m

- name: Install shfmt
uses: mfinelli/setup-shfmt@v3

- name: Run shfmt
run: shfmt -d -i 4 -ci hack/

test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5

- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: true

- name: Run tests
run: make test

222 changes: 102 additions & 120 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,135 +1,117 @@
---
new: true
new-from-rev: 722af08
version: "2"
run:
concurrency: 6
timeout: 5m
linters:
disable-all: true
default: none
enable:
- depguard
- errorlint
- goconst
- gocritic
- revive
- gofmt
- goimports
- gocyclo
- gosec
- govet
- ineffassign
- loggercheck
- misspell
- revive
- staticcheck
- typecheck
- unconvert
- unparam
- gocyclo
- unused
- errorlint
- loggercheck
- gosec
- wrapcheck
linters-settings:
revive:
rules:
- name: if-return
severity: warning
disabled: true
- name: string-format
severity: warning
disabled: false
arguments:
- - 'core.WriteError[1].Message'
- '/^([^A-Z]|$)/'
- must not start with a capital letter
- - 'fmt.Errorf[0]'
- '/^([^A-Z]|$)/'
- must not start with a capital letter
- - 'fmt.Errorf[0]'
- '/(^|[^\.!?])$/'
- must not end in punctuation
- - panic
- '/^[^\n]*$/'
- must not contain line breaks
gocritic:
enabled-checks:
# Diagnostic
- commentedOutCode
- nilValReturn
- weakCond
- octalLiteral
- sloppyReassign

# Performance
- equalFold
- indexAlloc
- rangeExprCopy
- appendCombine

# Style
- boolExprSimplify
- commentedOutImport
- docStub
- emptyFallthrough
- emptyStringTest
- hexLiteral
- methodExprCall
- stringXbytes
- typeAssertChain
- unlabelStmt
- yodaStyleExpr

# Opinionated
- initClause
- nestingReduce
- ptrToRefParam
- typeUnparen
- unnecessaryBlock
- paramTypeCombine
depguard:
# Rules to apply.
#
# Variables:
# - File Variables
# you can still use and exclamation mark ! in front of a variable to say not to use it.
# Example !$test will match any file that is not a go test file.
#
# `$all` - matches all go files
# `$test` - matches all go test files
#
# - Package Variables
#
# `$gostd` - matches all of go's standard library (Pulled from `GOROOT`)
#
# Default: Only allow $gostd in all files.
rules:
# Name of a rule.
main:
# Used to determine the package matching priority.
# There are three different modes: `original`, `strict`, and `lax`.
# Default: "original"
list-mode: lax
# List of file globs that will match this list of settings to compare against.
# Default: $all
files:
- $all
# List of allowed packages.
# allow:
# - $gostd
# Packages that are not allowed where the value is a suggestion.
deny:
- pkg: "github.com/pkg/errors"
desc: Should be replaced by standard lib errors package
wrapcheck:
ignoreSigs:
# defaults
- .Errorf(
- errors.New(
- errors.Unwrap(
- errors.Join(
- .Wrap(
- .Wrapf(
- .WithMessage(
- .WithMessagef(
- .WithStack(
# from kyaml's errors package
- .WrapPrefixf(
# from kcmdutil
- .UsageErrorf(
settings:
depguard:
rules:
main:
list-mode: lax
files:
- $all
deny:
- pkg: github.com/pkg/errors
desc: Should be replaced by standard lib errors package
gocritic:
enabled-checks:
- commentedOutCode
- nilValReturn
- weakCond
- octalLiteral
- sloppyReassign
- equalFold
- indexAlloc
- rangeExprCopy
- appendCombine
- boolExprSimplify
- commentedOutImport
- docStub
- emptyFallthrough
- emptyStringTest
- hexLiteral
- methodExprCall
- stringXbytes
- typeAssertChain
- unlabelStmt
- yodaStyleExpr
- initClause
- nestingReduce
- ptrToRefParam
- typeUnparen
- unnecessaryBlock
- paramTypeCombine
revive:
rules:
- name: if-return
severity: warning
disabled: true
- name: string-format
arguments:
- - core.WriteError[1].Message
- /^([^A-Z]|$)/
- must not start with a capital letter
- - fmt.Errorf[0]
- /^([^A-Z]|$)/
- must not start with a capital letter
- - fmt.Errorf[0]
- /(^|[^\.!?])$/
- must not end in punctuation
- - panic
- /^[^\n]*$/
- must not contain line breaks
severity: warning
disabled: false
wrapcheck:
ignore-sigs:
- .Errorf(
- errors.New(
- errors.Unwrap(
- errors.Join(
- .Wrap(
- .Wrapf(
- .WithMessage(
- .WithMessagef(
- .WithStack(
- .WrapPrefixf(
- .UsageErrorf(
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- vendor$
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
- goimports
exclusions:
generated: lax
paths:
- vendor$
- third_party$
- builtin$
- examples$
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,19 @@ build-helm-convert:
test-helm-convert:
go test --race ./addon-tools/helm-convert/*/

.PHONY: lint
lint: golangci-lint shfmt ## Run all linters

.PHONY: golangci-lint
golangci-lint: ## Run golangci-lint against code.
@echo "Running golangci-lint"
hack/golangci-lint.sh

.PHONY: shfmt
shfmt: ## Run shfmt against shell scripts in hack/
@echo "Running shfmt"
shfmt -d -i 4 -ci hack/*.sh

# markdownlint rules, following: https://github.com/openshift/enhancements/blob/master/Makefile
.PHONY: markdownlint-image
markdownlint-image: ## Build local container markdownlint-image
Expand Down
3 changes: 0 additions & 3 deletions addon-tools/helm-convert/convert/expectedvaluesfinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ func (v *ExpectedValuesFinder) Visit() func(parse.Node) bool {
switch n := node.(type) {
case *parse.FieldNode:
v.expected = append(v.expected, getNodeField(n)...)
break
case *parse.RangeNode:
for _, fieldRangedOn := range getFieldsAccessInNode(n.Pipe) { // for complex range statements get the path of the map/slice to be ranged on
// in case of range, the minimum list length will be always in length 1, including only element with index 0:
Expand All @@ -33,10 +32,8 @@ func (v *ExpectedValuesFinder) Visit() func(parse.Node) bool {
switch node := n.Args[2].(type) { // n.Args[2] is the second argument for index function
case *parse.NumberNode:
text = node.Text
break
case *parse.StringNode:
text = node.Text
break
}
v.expected = append(v.expected, append(fieldRangedOn, text))
}
Expand Down
4 changes: 2 additions & 2 deletions hack/krew-bump.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash -e

TAG=$(gh release view --json name | jq -r .name)
checksums=$(gh release download --pattern '*_checksums.txt' -O -)
checksums=$(gh release download --pattern '*_checksums.txt' -O -)
echo "Creating krew bump for $TAG"

# Tmpdir for krew-index clone
Expand All @@ -26,7 +26,7 @@ done <<<"$checksums"
# Commit and push
git commit -asm "Version bump cluster-compare to $TAG"
git push -u origin "$BRANCH"
gh pr create --fill
gh pr create --fill

# Cleanup
popd && popd && rm -rf _release_tmp
2 changes: 1 addition & 1 deletion hack/markdownlint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function handle_exit {
# If the exit code we were given indicates an error, suggest that
# the author run the linter locally.
if [ "$1" != "0" ]; then
cat - <<EOF
cat - <<EOF

To run the linter on a Linux system with podman, run "make markdownlint"
after committing your changes locally.
Expand Down
2 changes: 1 addition & 1 deletion pkg/compare/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ func diffAgainstTemplate(temp ReferenceTemplate, clusterCR *unstructured.Unstruc
if err != nil {
return res, fmt.Errorf("error occurered during diff: %w", err)
}
err = differ.Run(&diff.DiffProgram{Exec: exec.New(), IOStreams: genericiooptions.IOStreams{In: o.IOStreams.In, Out: diffOutput, ErrOut: o.IOStreams.ErrOut}})
err = differ.Run(&diff.DiffProgram{Exec: exec.New(), IOStreams: genericiooptions.IOStreams{In: o.In, Out: diffOutput, ErrOut: o.ErrOut}})

// If the diff tool runs without issues and detects differences at this level of the code, we would like to report that there are no issues
var exitErr exec.ExitError
Expand Down
5 changes: 3 additions & 2 deletions pkg/compare/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,8 +790,9 @@ func setClient(t *testing.T, resources []*unstructured.Unstructured, tf *cmdtest
tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: resource.UnstructuredPlusDefaultContentConfig().NegotiatedSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case m == "GET":
switch m := req.Method; m {
case "GET":
p := req.URL.Path
a := unstructured.Unstructured{}
exampleResource := resourcesByKind[p][0]
a.SetKind(exampleResource.GetKind() + "List")
Expand Down
8 changes: 4 additions & 4 deletions pkg/compare/correlator.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ func (f *FieldCorrelator[T]) ValidateTemplates() error {
for _, values := range f.objects {
if len(values) > 1 {
errs = append(errs, fmt.Errorf(
"More than one template with same %s. By Default for each Cluster CR that is correlated "+
"to one of these templates the template with the least number of diffs will be used. "+
"To use a different template for a specific CR specify it in the diff-config (-c flag) "+
"Template names are: %s",
"more than one template with same %s: by default for each cluster CR that is correlated "+
"to one of these templates the template with the least number of diffs will be used; "+
"to use a different template for a specific CR specify it in the diff-config (-c flag); "+
"template names are: %s",
getFields(f.Fields), getTemplatesNames(values)),
)
}
Expand Down
Loading