From 707ef06124e0f48bf87c41ba6c5fec9a32e6ed39 Mon Sep 17 00:00:00 2001 From: Kevin Joiner Date: Tue, 14 Feb 2023 16:21:32 -0500 Subject: [PATCH] Fix golangci-lint errors --- pkg/apply/desiredset.go | 1 - pkg/apply/desiredset_apply.go | 2 +- pkg/condition/condition.go | 1 - pkg/controller-gen/args/groupversion_test.go | 2 +- pkg/controller-gen/main.go | 7 +++---- pkg/data/convert/convert.go | 5 ++++- pkg/generic/factory.go | 2 +- pkg/git/git.go | 2 +- pkg/kubeconfig/loader.go | 3 +-- pkg/schemas/mappers/move.go | 2 +- pkg/schemas/reflection.go | 4 +--- pkg/summary/summarized.go | 2 -- pkg/webhook/router.go | 5 ++++- 13 files changed, 18 insertions(+), 20 deletions(-) diff --git a/pkg/apply/desiredset.go b/pkg/apply/desiredset.go index ecdaa918..054d058c 100644 --- a/pkg/apply/desiredset.go +++ b/pkg/apply/desiredset.go @@ -39,7 +39,6 @@ type desiredSet struct { noDeleteGVK map[schema.GroupVersionKind]struct{} setID string objs *objectset.ObjectSet - codeVersion string owner runtime.Object injectors []injectors.ConfigInjector ratelimitingQps float32 diff --git a/pkg/apply/desiredset_apply.go b/pkg/apply/desiredset_apply.go index b478f12c..cf4ee232 100644 --- a/pkg/apply/desiredset_apply.go +++ b/pkg/apply/desiredset_apply.go @@ -144,7 +144,7 @@ func (o *desiredSet) debugID() string { func (o *desiredSet) collect(objList []runtime.Object) objectset.ObjectByGVK { result := objectset.ObjectByGVK{} for _, obj := range objList { - result.Add(obj) + _, _ = result.Add(obj) } return result } diff --git a/pkg/condition/condition.go b/pkg/condition/condition.go index 65c5b0bc..ace8dea3 100644 --- a/pkg/condition/condition.go +++ b/pkg/condition/condition.go @@ -223,7 +223,6 @@ func getValue(obj interface{}, name ...string) reflect.Value { t := v.Type() if t.Kind() == reflect.Ptr { v = v.Elem() - t = v.Type() } field := v.FieldByName(name[0]) diff --git a/pkg/controller-gen/args/groupversion_test.go b/pkg/controller-gen/args/groupversion_test.go index 0bd54c00..1e5719bd 100644 --- a/pkg/controller-gen/args/groupversion_test.go +++ b/pkg/controller-gen/args/groupversion_test.go @@ -9,5 +9,5 @@ import ( func TestScan(t *testing.T) { cwd, _ := os.Getwd() fmt.Println(cwd) - ScanDirectory("./testdata") + _, _ = ScanDirectory("./testdata") } diff --git a/pkg/controller-gen/main.go b/pkg/controller-gen/main.go index f74f509c..beea92a0 100644 --- a/pkg/controller-gen/main.go +++ b/pkg/controller-gen/main.go @@ -3,7 +3,6 @@ package controllergen import ( "fmt" "io" - "io/ioutil" "os" "path/filepath" "sort" @@ -46,7 +45,7 @@ func Run(opts cgargs.Options) { genericArgs.InputDirs = parseTypes(customArgs) if genericArgs.OutputBase == "./" { //go modules - tempDir, err := ioutil.TempDir("", "") + tempDir, err := os.MkdirTemp("", "") if err != nil { return } @@ -123,7 +122,7 @@ func sourcePackagePath(customArgs *cgargs.CustomArgs, pkgName string) string { return pkg } -//until k8s code-gen supports gopath +// until k8s code-gen supports gopath func copyGoPathToModules(customArgs *cgargs.CustomArgs) error { pathsToCopy := map[string]bool{} @@ -137,7 +136,7 @@ func copyGoPathToModules(customArgs *cgargs.CustomArgs) error { pkg := sourcePackagePath(customArgs, customArgs.Package) pathsToCopy[pkg] = true - for pkg, _ := range pathsToCopy { + for pkg := range pathsToCopy { if _, err := os.Stat(pkg); os.IsNotExist(err) { continue } diff --git a/pkg/data/convert/convert.go b/pkg/data/convert/convert.go index c87f8b21..ff67f049 100644 --- a/pkg/data/convert/convert.go +++ b/pkg/data/convert/convert.go @@ -10,6 +10,8 @@ import ( "time" "unicode" + "golang.org/x/text/cases" + "golang.org/x/text/language" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) @@ -235,7 +237,8 @@ func EncodeToMap(obj interface{}) (map[string]interface{}, error) { func ToJSONKey(str string) string { parts := strings.Split(str, "_") for i := 1; i < len(parts); i++ { - parts[i] = strings.Title(parts[i]) + caser := cases.Title(language.English) + parts[i] = caser.String(parts[i]) } return strings.Join(parts, "") diff --git a/pkg/generic/factory.go b/pkg/generic/factory.go index 946af865..ce4370d9 100644 --- a/pkg/generic/factory.go +++ b/pkg/generic/factory.go @@ -103,7 +103,7 @@ func (c *Factory) setControllerFactoryWithLock() error { func (c *Factory) Sync(ctx context.Context) error { if c.cacheFactory != nil { - c.cacheFactory.Start(ctx) + _ = c.cacheFactory.Start(ctx) c.cacheFactory.WaitForCacheSync(ctx) } return nil diff --git a/pkg/git/git.go b/pkg/git/git.go index 3309de02..d1227a67 100644 --- a/pkg/git/git.go +++ b/pkg/git/git.go @@ -349,7 +349,7 @@ func (g *Git) gitCmd(output io.Writer, args ...string) error { cmd.Env = append(cmd.Env, "GIT_SSH_COMMAND="+fmt.Sprintf("ssh -o UserKnownHostsFile=%s", f.Name())) } else { - cmd.Env = append(cmd.Env, "GIT_SSH_COMMAND="+fmt.Sprintf("ssh -o StrictHostKeyChecking=accept-new")) + cmd.Env = append(cmd.Env, "GIT_SSH_COMMAND="+"ssh -o StrictHostKeyChecking=accept-new") } cmd.Env = append(cmd.Env, "GIT_TERMINAL_PROMPT=0") diff --git a/pkg/kubeconfig/loader.go b/pkg/kubeconfig/loader.go index 16902a42..8e4112b8 100644 --- a/pkg/kubeconfig/loader.go +++ b/pkg/kubeconfig/loader.go @@ -2,7 +2,6 @@ package kubeconfig import ( "io" - "io/ioutil" "os" "path/filepath" @@ -51,7 +50,7 @@ func GetLoadingRules(kubeConfig string) *clientcmd.ClientConfigLoadingRules { func canRead(files []string) (result []string) { for _, f := range files { - _, err := ioutil.ReadFile(f) + _, err := os.ReadFile(f) if err == nil { result = append(result, f) } diff --git a/pkg/schemas/mappers/move.go b/pkg/schemas/mappers/move.go index 06f1e88b..b426e455 100644 --- a/pkg/schemas/mappers/move.go +++ b/pkg/schemas/mappers/move.go @@ -42,7 +42,7 @@ func (m Move) ModifySchema(s *types.Schema, schemas *types.Schemas) error { return fmt.Errorf("failed to find field %s on schema %s", m.From, s.ID) } - toSchema, toFieldName, _, ok, err := getField(s, schemas, m.To) + toSchema, toFieldName, _, _, err := getField(s, schemas, m.To) if err != nil { return err } diff --git a/pkg/schemas/reflection.go b/pkg/schemas/reflection.go index b32c8b01..970dd6dc 100644 --- a/pkg/schemas/reflection.go +++ b/pkg/schemas/reflection.go @@ -345,9 +345,7 @@ func (s *Schemas) processFieldsMappers(t reflect.Type, fieldName string, schema parts := strings.SplitN(fieldMapper, "=", 2) name = parts[0] if len(parts) == 2 { - for _, opt := range strings.Split(parts[1], "|") { - opts = append(opts, opt) - } + opts = append(opts, strings.Split(parts[1], "|")...) } factory, ok := s.fieldMappers[name] diff --git a/pkg/summary/summarized.go b/pkg/summary/summarized.go index 346efb3e..7526dde7 100644 --- a/pkg/summary/summarized.go +++ b/pkg/summary/summarized.go @@ -54,7 +54,6 @@ func (in *SummarizedObjectList) DeepCopyInto(out *SummarizedObjectList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - return } func (in *SummarizedObjectList) DeepCopy() *SummarizedObjectList { @@ -78,7 +77,6 @@ func (in *SummarizedObject) DeepCopyInto(out *SummarizedObject) { out.TypeMeta = in.TypeMeta out.ObjectMeta = *in.ObjectMeta.DeepCopy() out.Summary = *in.Summary.DeepCopy() - return } func (in *SummarizedObject) DeepCopy() *SummarizedObject { diff --git a/pkg/webhook/router.go b/pkg/webhook/router.go index 1d7c70dc..7c53d403 100644 --- a/pkg/webhook/router.go +++ b/pkg/webhook/router.go @@ -42,7 +42,10 @@ func (r *Router) sendError(rw http.ResponseWriter, review *v1.AdmissionReview, e func writeResponse(rw http.ResponseWriter, review *v1.AdmissionReview) { rw.Header().Set("Content-Type", "application/json") - json.NewEncoder(rw).Encode(review) + err := json.NewEncoder(rw).Encode(review) + if err != nil { + logrus.Errorf("Failed to write response: %s", err) + } } // ServeHTTP inspects the http.Request and calls the Admit function on all matching handlers.