Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix staticcheck failure in pkg/kubelet/cm/cpuset #103415

Merged
merged 1 commit into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion hack/.staticcheck_failures
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pkg/kubelet/cm/cpuset
pkg/util/flag
test/e2e/apimachinery
vendor/k8s.io/apimachinery/pkg/util/json
Expand Down
8 changes: 4 additions & 4 deletions pkg/kubelet/cm/cpuset/cpuset.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ type Builder struct {
}

// NewBuilder returns a mutable CPUSet builder.
func NewBuilder() Builder {
return Builder{
func NewBuilder() *Builder {
return &Builder{
result: CPUSet{
elems: map[int]struct{}{},
},
Expand All @@ -46,7 +46,7 @@ func NewBuilder() Builder {

// Add adds the supplied elements to the result. Calling Add after calling
// Result has no effect.
func (b Builder) Add(elems ...int) {
func (b *Builder) Add(elems ...int) {
if b.done {
return
}
Expand All @@ -57,7 +57,7 @@ func (b Builder) Add(elems ...int) {

// Result returns the result CPUSet containing all elements that were
// previously added to this builder. Subsequent calls to Add have no effect.
func (b Builder) Result() CPUSet {
func (b *Builder) Result() CPUSet {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tiloso static check is fixed by this PR
#103723

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this is the right thing to do here. I say this because when you look at the implementation of a consumer does not mix and match pointer types. Changing this would mean Builder.Add acts on an object, Builder.Result acts on a receiver to pointer.

https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/cm/cpumanager/topology/topology.go#L83-L89

Copy link
Contributor Author

@tiloso tiloso Aug 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your feedback @manugupt1! Changed the receiver of Add(...) to a pointer in 2b86541.

b.done = true
return b.result
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/kubelet/cm/cpuset/cpuset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package cpuset
import (
"reflect"
"testing"

"github.com/stretchr/testify/require"
)

func TestCPUSetBuilder(t *testing.T) {
Expand All @@ -36,6 +38,9 @@ func TestCPUSetBuilder(t *testing.T) {
if len(elems) != result.Size() {
t.Fatalf("expected cpuset %s to have the same size as %v", result, elems)
}

b.Add(6)
require.False(t, result.Contains(6), "expected calls to Add after calling Result() to have no effect")
}

func TestCPUSetSize(t *testing.T) {
Expand Down