diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2b91e4b9..1f5c407d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,14 +57,16 @@ jobs: runs-on: ubuntu-latest steps: - name: Install Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v6 + with: + go-version: v1.23 - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v5 - name: Lint - run: | - docker run --rm -v `pwd`:/go/src/k8s.io/klog -w /go/src/k8s.io/klog \ - golangci/golangci-lint:v1.51.2 golangci-lint run --disable-all -v \ - -E govet -E misspell -E gofmt -E ineffassign -E golint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.60.1 + args: --disable-all -v -E govet -E misspell -E gofmt -E ineffassign apidiff: runs-on: ubuntu-latest if: github.base_ref diff --git a/exec/exec.go b/exec/exec.go index d9c91e3c..b7cde7fd 100644 --- a/exec/exec.go +++ b/exec/exec.go @@ -18,6 +18,7 @@ package exec import ( "context" + "errors" "io" "io/fs" osexec "os/exec" @@ -97,6 +98,21 @@ func New() Interface { return &executor{} } +// maskErrDotCmd reverts the behavior of osexec.Cmd to what it was before go1.19 +// specifically set the Err field to nil (LookPath returns a new error when the file +// is resolved to the current directory. +func maskErrDotCmd(cmd *osexec.Cmd) *osexec.Cmd { + cmd.Err = maskErrDot(cmd.Err) + return cmd +} + +func maskErrDot(err error) error { + if err != nil && errors.Is(err, osexec.ErrDot) { + return nil + } + return err +} + // Command is part of the Interface interface. func (executor *executor) Command(cmd string, args ...string) Cmd { return (*cmdWrapper)(maskErrDotCmd(osexec.Command(cmd, args...))) diff --git a/exec/fixup_go118.go b/exec/fixup_go118.go deleted file mode 100644 index acf45f1c..00000000 --- a/exec/fixup_go118.go +++ /dev/null @@ -1,32 +0,0 @@ -//go:build !go1.19 -// +build !go1.19 - -/* -Copyright 2022 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package exec - -import ( - osexec "os/exec" -) - -func maskErrDotCmd(cmd *osexec.Cmd) *osexec.Cmd { - return cmd -} - -func maskErrDot(err error) error { - return err -} diff --git a/exec/fixup_go119.go b/exec/fixup_go119.go deleted file mode 100644 index 55874c92..00000000 --- a/exec/fixup_go119.go +++ /dev/null @@ -1,40 +0,0 @@ -//go:build go1.19 -// +build go1.19 - -/* -Copyright 2022 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package exec - -import ( - "errors" - osexec "os/exec" -) - -// maskErrDotCmd reverts the behavior of osexec.Cmd to what it was before go1.19 -// specifically set the Err field to nil (LookPath returns a new error when the file -// is resolved to the current directory. -func maskErrDotCmd(cmd *osexec.Cmd) *osexec.Cmd { - cmd.Err = maskErrDot(cmd.Err) - return cmd -} - -func maskErrDot(err error) error { - if err != nil && errors.Is(err, osexec.ErrDot) { - return nil - } - return err -} diff --git a/mount/mount_linux.go b/mount/mount_linux.go index fbce6d43..28812634 100644 --- a/mount/mount_linux.go +++ b/mount/mount_linux.go @@ -371,7 +371,7 @@ func (mounter *SafeFormatAndMount) formatAndMountSensitive(source string, target sensitiveOptionsLog := sanitizedOptionsForLogging(options, sensitiveOptions) detailedErr := fmt.Sprintf("format of disk %q failed: type:(%q) target:(%q) options:(%q) errcode:(%v) output:(%v) ", source, fstype, target, sensitiveOptionsLog, err, string(output)) klog.Error(detailedErr) - return NewMountError(FormatFailed, detailedErr) + return NewMountError(FormatFailed, "%s", detailedErr) } klog.Infof("Disk successfully formatted (mkfs): %s - %s %s", fstype, source, target) @@ -394,7 +394,7 @@ func (mounter *SafeFormatAndMount) formatAndMountSensitive(source string, target // Mount the disk klog.V(4).Infof("Attempting to mount disk %s in %s format at %s", source, fstype, target) if err := mounter.MountSensitive(source, target, fstype, options, sensitiveOptions); err != nil { - return NewMountError(mountErrorValue, err.Error()) + return NewMountError(mountErrorValue, "%s", err.Error()) } return nil diff --git a/set/set.go b/set/set.go index fc25b2fe..446c1373 100644 --- a/set/set.go +++ b/set/set.go @@ -34,6 +34,14 @@ func New[E ordered](items ...E) Set[E] { return ss } +// Clear empties the set. +// It is preferable to replace the set with a newly constructed set, +// but not all callers can do that (when there are other references to the map). +func (s Set[T]) Clear() Set[T] { + clear(s) + return s +} + // KeySet creates a Set[E] from a keys of a map[E](? extends interface{}). func KeySet[E ordered, A any](theMap map[E]A) Set[E] { ret := Set[E]{} diff --git a/set/set_go_1.20.go b/set/set_go_1.20.go deleted file mode 100644 index 6ab79682..00000000 --- a/set/set_go_1.20.go +++ /dev/null @@ -1,33 +0,0 @@ -//go:build !go1.21 - -/* -Copyright 2023 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package set - -// Clear empties the set. -// It is preferable to replace the set with a newly constructed set, -// but not all callers can do that (when there are other references to the map). -// In some cases the set *won't* be fully cleared, e.g. a Set[float32] containing NaN -// can't be cleared because NaN can't be removed. -// For sets containing items of a type that is reflexive for ==, -// this is optimized to a single call to runtime.mapclear(). -func (s Set[T]) Clear() Set[T] { - for key := range s { - delete(s, key) - } - return s -} diff --git a/set/set_go_1.21.go b/set/set_go_1.21.go deleted file mode 100644 index e95a3687..00000000 --- a/set/set_go_1.21.go +++ /dev/null @@ -1,27 +0,0 @@ -//go:build go1.21 - -/* -Copyright 2023 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package set - -// Clear empties the set. -// It is preferable to replace the set with a newly constructed set, -// but not all callers can do that (when there are other references to the map). -func (s Set[T]) Clear() Set[T] { - clear(s) - return s -}