Merge pull request #103415 from tiloso/staticcheck-kubelet

Fix staticcheck failure in pkg/kubelet/cm/cpuset
This commit is contained in:
Kubernetes Prow Robot 2021-11-11 15:15:13 -08:00 committed by GitHub
commit 3ca3daac76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 5 deletions

View File

@ -1,4 +1,3 @@
pkg/kubelet/cm/cpuset
pkg/util/flag
test/e2e/apimachinery
vendor/k8s.io/apimachinery/pkg/util/json

View File

@ -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{}{},
},
@ -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
}
@ -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 {
b.done = true
return b.result
}

View File

@ -19,6 +19,8 @@ package cpuset
import (
"reflect"
"testing"
"github.com/stretchr/testify/require"
)
func TestCPUSetBuilder(t *testing.T) {
@ -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) {