Skip to content

Commit

Permalink
Merge branch 'main' into aerfio/tracing-k8s-client
Browse files Browse the repository at this point in the history
  • Loading branch information
aerfio committed Mar 29, 2024
2 parents bab06ea + a7fc8a3 commit 7ca5c02
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54.2
version: v1.57.1
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ linters-settings:
- hugeParam
- paramTypeCombine # automatically fixed by gofumpt
- typeDefFirst
- whyNoLint
revive:
rules:
- name: indent-error-flow
Expand Down
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,20 @@ fmt: ${GOFUMPT} ${GCI}
$(GOFUMPT) -w -extra .
$(GCI) write . --skip-generated -s standard -s default -s localmodule -s blank -s dot --custom-order --skip-vendor


.PHONY: test
test:
go test ./... -race -v

bin/golangci-lint-install.sh:
mkdir -p "bin"
curl -fL "https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh" -o "$@"
chmod +x "$@"

GOLANGCI_LINT_VERSION = v1.57.1
GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint-${GOLANGCI_LINT_VERSION}
${GOLANGCI_LINT}: bin/golangci-lint-install.sh
./bin/golangci-lint-install.sh -b $(abspath bin) ${GOLANGCI_LINT_VERSION}
mv ./bin/golangci-lint ${GOLANGCI_LINT}

lint: ${GOLANGCI_LINT}
$(GOLANGCI_LINT) run --config ${PWD}/.golangci.yml
15 changes: 6 additions & 9 deletions cmd/cmwv/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"io"
"os"
Expand All @@ -19,10 +20,7 @@ func main() {
}
}

var (
newlineSpaceNewlineRegexp = regexp.MustCompile(`. +\n|\t`)
tabRegexp = regexp.MustCompile(`\t`)
)
var newlineSpaceNewlineRegexp = regexp.MustCompile(`. +\n|\t`)

func run() error {
content, helpRequested, err := getInput(os.Args)
Expand All @@ -49,7 +47,6 @@ There are 2 main reasons for this behaviour: tab (\t) characters and the trailin

keysWithInvalidValues := []string{}
for key, value := range configMap.Data {
// fmt.Println(strings.NewReplacer(" ", ".").Replace(value))
val, foundInvalidParts := highlightInvalidParts(value)
if foundInvalidParts {
color.HiGreen("key: %s", key)
Expand All @@ -62,9 +59,9 @@ There are 2 main reasons for this behaviour: tab (\t) characters and the trailin
case 0:
return nil
case 1:
return fmt.Errorf(color.RedString("data key %s contains characters that make configMap unreadable, they are highlighted in red color. For more info run `cmwv help`", keysWithInvalidValues[0]))
return errors.New(color.RedString("data key %s contains characters that make configMap unreadable, they are highlighted in red color. For more info run `cmwv help`", keysWithInvalidValues[0]))
default:
return fmt.Errorf(color.RedString("data keys %s contain characters that make configMap unreadable, they are highlighted in red color. For more info run `cmwv help`", strings.Join(keysWithInvalidValues, ",")))
return errors.New(color.RedString("data keys %s contain characters that make configMap unreadable, they are highlighted in red color. For more info run `cmwv help`", strings.Join(keysWithInvalidValues, ",")))
}
}

Expand All @@ -86,10 +83,10 @@ func highlightInvalidParts(input string) (string, bool) {
func getInput(osArgs []string) ([]byte, bool, error) {
switch l := len(osArgs); l {
case 1:
return nil, false, fmt.Errorf("Please specify path to file with configMap as a first argument, or a \"-\" to read configMap from stdin")
return nil, false, fmt.Errorf("Please specify path to file with configMap as a first argument, or a \"-\" to read configMap from stdin") //nolint:stylecheck
case 2: // nothing
default:
return nil, false, fmt.Errorf(`Provided %d arguments, please provide only 1, either a path to a file with Kubernetes configMap or "-" for stdin`, l-1)
return nil, false, fmt.Errorf(`Provided %d arguments, please provide only 1, either a path to a file with Kubernetes configMap or "-" for stdin`, l-1) //nolint:stylecheck
}

inputArg := os.Args[1]
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func GetConfig() (config *rest.Config, configErr error) {
// If the recommended kubeconfig env variable is not specified,
// try the in-cluster config.
kubeconfigPath := os.Getenv(clientcmd.RecommendedConfigPathEnvVar)
if len(kubeconfigPath) == 0 {
if kubeconfigPath == "" {
c, err := rest.InClusterConfig()
if err == nil {
return c, nil
Expand Down
7 changes: 4 additions & 3 deletions internal/cmd/gvk-dirs-generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,10 @@ func groupObjAndList(knownTypes map[string]reflect.Type) []string {
sort.Strings(nonLists)
for _, elem := range nonLists {
out = append(out, elem)
if slices.Contains(lists, elem+"List") {
out = append(out, elem+"List")
idx := slices.Index(lists, elem+"List")

if listElem := fmt.Sprintf("%sList", elem); slices.Contains(lists, listElem) {
out = append(out, listElem)
idx := slices.Index(lists, listElem)
lists = append(lists[:idx], lists[idx+1:]...)
}
}
Expand Down

0 comments on commit 7ca5c02

Please sign in to comment.