Fix staging/src/k8s.io/apimachinery/pkg/labels golint findings

Signed-off-by: ialidzhikov <i.alidjikov@gmail.com>
This commit is contained in:
ialidzhikov 2020-09-04 02:54:28 +03:00
parent 48d5d204c3
commit 88fadb24c1
5 changed files with 37 additions and 38 deletions

View File

@ -261,7 +261,6 @@ staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1
staging/src/k8s.io/apimachinery/pkg/apis/testapigroup staging/src/k8s.io/apimachinery/pkg/apis/testapigroup
staging/src/k8s.io/apimachinery/pkg/apis/testapigroup/v1 staging/src/k8s.io/apimachinery/pkg/apis/testapigroup/v1
staging/src/k8s.io/apimachinery/pkg/conversion staging/src/k8s.io/apimachinery/pkg/conversion
staging/src/k8s.io/apimachinery/pkg/labels
staging/src/k8s.io/apimachinery/pkg/runtime staging/src/k8s.io/apimachinery/pkg/runtime
staging/src/k8s.io/apimachinery/pkg/runtime/schema staging/src/k8s.io/apimachinery/pkg/runtime/schema
staging/src/k8s.io/apimachinery/pkg/runtime/serializer staging/src/k8s.io/apimachinery/pkg/runtime/serializer

View File

@ -39,7 +39,7 @@ type mutatingWebhookConfigurationStrategy struct {
// Strategy is the default logic that applies when creating and updating mutatingWebhookConfiguration objects. // Strategy is the default logic that applies when creating and updating mutatingWebhookConfiguration objects.
var Strategy = mutatingWebhookConfigurationStrategy{legacyscheme.Scheme, names.SimpleNameGenerator} var Strategy = mutatingWebhookConfigurationStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
// NamespaceScoped returns true because all mutatingWebhookConfiguration' need to be within a namespace. // NamespaceScoped returns false because MutatingWebhookConfiguration is cluster-scoped resource.
func (mutatingWebhookConfigurationStrategy) NamespaceScoped() bool { func (mutatingWebhookConfigurationStrategy) NamespaceScoped() bool {
return false return false
} }

View File

@ -39,7 +39,7 @@ type validatingWebhookConfigurationStrategy struct {
// Strategy is the default logic that applies when creating and updating validatingWebhookConfiguration objects. // Strategy is the default logic that applies when creating and updating validatingWebhookConfiguration objects.
var Strategy = validatingWebhookConfigurationStrategy{legacyscheme.Scheme, names.SimpleNameGenerator} var Strategy = validatingWebhookConfigurationStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
// NamespaceScoped returns true because all validatingWebhookConfiguration' need to be within a namespace. // NamespaceScoped returns false because ValidatingWebhookConfiguration is cluster-scoped resource.
func (validatingWebhookConfigurationStrategy) NamespaceScoped() bool { func (validatingWebhookConfigurationStrategy) NamespaceScoped() bool {
return false return false
} }

View File

@ -21,43 +21,43 @@ import (
) )
// Returns string version of ResourceName. // Returns string version of ResourceName.
func (self ResourceName) String() string { func (rn ResourceName) String() string {
return string(self) return string(rn)
} }
// Returns the CPU limit if specified. // Returns the CPU limit if specified.
func (self *ResourceList) Cpu() *resource.Quantity { func (rl *ResourceList) Cpu() *resource.Quantity {
if val, ok := (*self)[ResourceCPU]; ok { if val, ok := (*rl)[ResourceCPU]; ok {
return &val return &val
} }
return &resource.Quantity{Format: resource.DecimalSI} return &resource.Quantity{Format: resource.DecimalSI}
} }
// Returns the Memory limit if specified. // Returns the Memory limit if specified.
func (self *ResourceList) Memory() *resource.Quantity { func (rl *ResourceList) Memory() *resource.Quantity {
if val, ok := (*self)[ResourceMemory]; ok { if val, ok := (*rl)[ResourceMemory]; ok {
return &val return &val
} }
return &resource.Quantity{Format: resource.BinarySI} return &resource.Quantity{Format: resource.BinarySI}
} }
// Returns the Storage limit if specified. // Returns the Storage limit if specified.
func (self *ResourceList) Storage() *resource.Quantity { func (rl *ResourceList) Storage() *resource.Quantity {
if val, ok := (*self)[ResourceStorage]; ok { if val, ok := (*rl)[ResourceStorage]; ok {
return &val return &val
} }
return &resource.Quantity{Format: resource.BinarySI} return &resource.Quantity{Format: resource.BinarySI}
} }
func (self *ResourceList) Pods() *resource.Quantity { func (rl *ResourceList) Pods() *resource.Quantity {
if val, ok := (*self)[ResourcePods]; ok { if val, ok := (*rl)[ResourcePods]; ok {
return &val return &val
} }
return &resource.Quantity{} return &resource.Quantity{}
} }
func (self *ResourceList) StorageEphemeral() *resource.Quantity { func (rl *ResourceList) StorageEphemeral() *resource.Quantity {
if val, ok := (*self)[ResourceEphemeralStorage]; ok { if val, ok := (*rl)[ResourceEphemeralStorage]; ok {
return &val return &val
} }
return &resource.Quantity{} return &resource.Quantity{}

View File

@ -263,11 +263,11 @@ func (r *Requirement) Values() sets.String {
} }
// Empty returns true if the internalSelector doesn't restrict selection space // Empty returns true if the internalSelector doesn't restrict selection space
func (lsel internalSelector) Empty() bool { func (s internalSelector) Empty() bool {
if lsel == nil { if s == nil {
return true return true
} }
return len(lsel) == 0 return len(s) == 0
} }
// String returns a human-readable string that represents this // String returns a human-readable string that represents this
@ -330,51 +330,51 @@ func safeSort(in []string) []string {
} }
// Add adds requirements to the selector. It copies the current selector returning a new one // Add adds requirements to the selector. It copies the current selector returning a new one
func (lsel internalSelector) Add(reqs ...Requirement) Selector { func (s internalSelector) Add(reqs ...Requirement) Selector {
var sel internalSelector var ret internalSelector
for ix := range lsel { for ix := range s {
sel = append(sel, lsel[ix]) ret = append(ret, s[ix])
} }
for _, r := range reqs { for _, r := range reqs {
sel = append(sel, r) ret = append(ret, r)
} }
sort.Sort(ByKey(sel)) sort.Sort(ByKey(ret))
return sel return ret
} }
// Matches for a internalSelector returns true if all // Matches for a internalSelector returns true if all
// its Requirements match the input Labels. If any // its Requirements match the input Labels. If any
// Requirement does not match, false is returned. // Requirement does not match, false is returned.
func (lsel internalSelector) Matches(l Labels) bool { func (s internalSelector) Matches(l Labels) bool {
for ix := range lsel { for ix := range s {
if matches := lsel[ix].Matches(l); !matches { if matches := s[ix].Matches(l); !matches {
return false return false
} }
} }
return true return true
} }
func (lsel internalSelector) Requirements() (Requirements, bool) { return Requirements(lsel), true } func (s internalSelector) Requirements() (Requirements, bool) { return Requirements(s), true }
// String returns a comma-separated string of all // String returns a comma-separated string of all
// the internalSelector Requirements' human-readable strings. // the internalSelector Requirements' human-readable strings.
func (lsel internalSelector) String() string { func (s internalSelector) String() string {
var reqs []string var reqs []string
for ix := range lsel { for ix := range s {
reqs = append(reqs, lsel[ix].String()) reqs = append(reqs, s[ix].String())
} }
return strings.Join(reqs, ",") return strings.Join(reqs, ",")
} }
// RequiresExactMatch introspect whether a given selector requires a single specific field // RequiresExactMatch introspect whether a given selector requires a single specific field
// to be set, and if so returns the value it requires. // to be set, and if so returns the value it requires.
func (lsel internalSelector) RequiresExactMatch(label string) (value string, found bool) { func (s internalSelector) RequiresExactMatch(label string) (value string, found bool) {
for ix := range lsel { for ix := range s {
if lsel[ix].key == label { if s[ix].key == label {
switch lsel[ix].operator { switch s[ix].operator {
case selection.Equals, selection.DoubleEquals, selection.In: case selection.Equals, selection.DoubleEquals, selection.In:
if len(lsel[ix].strValues) == 1 { if len(s[ix].strValues) == 1 {
return lsel[ix].strValues[0], true return s[ix].strValues[0], true
} }
} }
return "", false return "", false