mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #94501 from ialidzhikov/nit/labels-staticcheck
Fix staging/src/k8s.io/apimachinery/pkg/labels golint findings
This commit is contained in:
commit
f728fbaa62
@ -257,7 +257,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/v1
|
||||
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/schema
|
||||
staging/src/k8s.io/apimachinery/pkg/runtime/serializer
|
||||
|
@ -39,7 +39,7 @@ type mutatingWebhookConfigurationStrategy struct {
|
||||
// Strategy is the default logic that applies when creating and updating mutatingWebhookConfiguration objects.
|
||||
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 {
|
||||
return false
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ type validatingWebhookConfigurationStrategy struct {
|
||||
// Strategy is the default logic that applies when creating and updating validatingWebhookConfiguration objects.
|
||||
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 {
|
||||
return false
|
||||
}
|
||||
|
@ -21,43 +21,43 @@ import (
|
||||
)
|
||||
|
||||
// Returns string version of ResourceName.
|
||||
func (self ResourceName) String() string {
|
||||
return string(self)
|
||||
func (rn ResourceName) String() string {
|
||||
return string(rn)
|
||||
}
|
||||
|
||||
// Returns the CPU limit if specified.
|
||||
func (self *ResourceList) Cpu() *resource.Quantity {
|
||||
if val, ok := (*self)[ResourceCPU]; ok {
|
||||
func (rl *ResourceList) Cpu() *resource.Quantity {
|
||||
if val, ok := (*rl)[ResourceCPU]; ok {
|
||||
return &val
|
||||
}
|
||||
return &resource.Quantity{Format: resource.DecimalSI}
|
||||
}
|
||||
|
||||
// Returns the Memory limit if specified.
|
||||
func (self *ResourceList) Memory() *resource.Quantity {
|
||||
if val, ok := (*self)[ResourceMemory]; ok {
|
||||
func (rl *ResourceList) Memory() *resource.Quantity {
|
||||
if val, ok := (*rl)[ResourceMemory]; ok {
|
||||
return &val
|
||||
}
|
||||
return &resource.Quantity{Format: resource.BinarySI}
|
||||
}
|
||||
|
||||
// Returns the Storage limit if specified.
|
||||
func (self *ResourceList) Storage() *resource.Quantity {
|
||||
if val, ok := (*self)[ResourceStorage]; ok {
|
||||
func (rl *ResourceList) Storage() *resource.Quantity {
|
||||
if val, ok := (*rl)[ResourceStorage]; ok {
|
||||
return &val
|
||||
}
|
||||
return &resource.Quantity{Format: resource.BinarySI}
|
||||
}
|
||||
|
||||
func (self *ResourceList) Pods() *resource.Quantity {
|
||||
if val, ok := (*self)[ResourcePods]; ok {
|
||||
func (rl *ResourceList) Pods() *resource.Quantity {
|
||||
if val, ok := (*rl)[ResourcePods]; ok {
|
||||
return &val
|
||||
}
|
||||
return &resource.Quantity{}
|
||||
}
|
||||
|
||||
func (self *ResourceList) StorageEphemeral() *resource.Quantity {
|
||||
if val, ok := (*self)[ResourceEphemeralStorage]; ok {
|
||||
func (rl *ResourceList) StorageEphemeral() *resource.Quantity {
|
||||
if val, ok := (*rl)[ResourceEphemeralStorage]; ok {
|
||||
return &val
|
||||
}
|
||||
return &resource.Quantity{}
|
||||
|
@ -263,11 +263,11 @@ func (r *Requirement) Values() sets.String {
|
||||
}
|
||||
|
||||
// Empty returns true if the internalSelector doesn't restrict selection space
|
||||
func (lsel internalSelector) Empty() bool {
|
||||
if lsel == nil {
|
||||
func (s internalSelector) Empty() bool {
|
||||
if s == nil {
|
||||
return true
|
||||
}
|
||||
return len(lsel) == 0
|
||||
return len(s) == 0
|
||||
}
|
||||
|
||||
// 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
|
||||
func (lsel internalSelector) Add(reqs ...Requirement) Selector {
|
||||
var sel internalSelector
|
||||
for ix := range lsel {
|
||||
sel = append(sel, lsel[ix])
|
||||
func (s internalSelector) Add(reqs ...Requirement) Selector {
|
||||
var ret internalSelector
|
||||
for ix := range s {
|
||||
ret = append(ret, s[ix])
|
||||
}
|
||||
for _, r := range reqs {
|
||||
sel = append(sel, r)
|
||||
ret = append(ret, r)
|
||||
}
|
||||
sort.Sort(ByKey(sel))
|
||||
return sel
|
||||
sort.Sort(ByKey(ret))
|
||||
return ret
|
||||
}
|
||||
|
||||
// Matches for a internalSelector returns true if all
|
||||
// its Requirements match the input Labels. If any
|
||||
// Requirement does not match, false is returned.
|
||||
func (lsel internalSelector) Matches(l Labels) bool {
|
||||
for ix := range lsel {
|
||||
if matches := lsel[ix].Matches(l); !matches {
|
||||
func (s internalSelector) Matches(l Labels) bool {
|
||||
for ix := range s {
|
||||
if matches := s[ix].Matches(l); !matches {
|
||||
return false
|
||||
}
|
||||
}
|
||||
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
|
||||
// the internalSelector Requirements' human-readable strings.
|
||||
func (lsel internalSelector) String() string {
|
||||
func (s internalSelector) String() string {
|
||||
var reqs []string
|
||||
for ix := range lsel {
|
||||
reqs = append(reqs, lsel[ix].String())
|
||||
for ix := range s {
|
||||
reqs = append(reqs, s[ix].String())
|
||||
}
|
||||
return strings.Join(reqs, ",")
|
||||
}
|
||||
|
||||
// RequiresExactMatch introspect whether a given selector requires a single specific field
|
||||
// to be set, and if so returns the value it requires.
|
||||
func (lsel internalSelector) RequiresExactMatch(label string) (value string, found bool) {
|
||||
for ix := range lsel {
|
||||
if lsel[ix].key == label {
|
||||
switch lsel[ix].operator {
|
||||
func (s internalSelector) RequiresExactMatch(label string) (value string, found bool) {
|
||||
for ix := range s {
|
||||
if s[ix].key == label {
|
||||
switch s[ix].operator {
|
||||
case selection.Equals, selection.DoubleEquals, selection.In:
|
||||
if len(lsel[ix].strValues) == 1 {
|
||||
return lsel[ix].strValues[0], true
|
||||
if len(s[ix].strValues) == 1 {
|
||||
return s[ix].strValues[0], true
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
|
Loading…
Reference in New Issue
Block a user