Merge pull request #92547 from kensipe/apiservier-staticchecks-bools

fix Apiserver staticchecks for bools
This commit is contained in:
Kubernetes Prow Robot 2020-08-27 19:06:01 -07:00 committed by GitHub
commit 31191f6055
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 24 additions and 40 deletions

View File

@ -88,7 +88,7 @@ func (authzHandler unionAuthzRulesHandler) RulesFor(user user.Info, namespace st
for _, currAuthzHandler := range authzHandler { for _, currAuthzHandler := range authzHandler {
resourceRules, nonResourceRules, incomplete, err := currAuthzHandler.RulesFor(user, namespace) resourceRules, nonResourceRules, incomplete, err := currAuthzHandler.RulesFor(user, namespace)
if incomplete == true { if incomplete {
incompleteStatus = true incompleteStatus = true
} }
if err != nil { if err != nil {

View File

@ -141,7 +141,7 @@ func DeleteResource(r rest.GracefulDeleter, allowsOptions bool, scope *RequestSc
// that will break existing clients. // that will break existing clients.
// Other cases where resource is not instantly deleted are: namespace deletion // Other cases where resource is not instantly deleted are: namespace deletion
// and pod graceful deletion. // and pod graceful deletion.
if !wasDeleted && options.OrphanDependents != nil && *options.OrphanDependents == false { if !wasDeleted && options.OrphanDependents != nil && !*options.OrphanDependents {
status = http.StatusAccepted status = http.StatusAccepted
} }
// if the rest.Deleter returns a nil object, fill out a status. Callers may return a valid // if the rest.Deleter returns a nil object, fill out a status. Callers may return a valid

View File

@ -67,7 +67,7 @@ func (f *capManagersManager) capUpdateManagers(managed Managed) (newManaged Mana
// Gather all entries from updates // Gather all entries from updates
updaters := []string{} updaters := []string{}
for manager, fields := range managed.Fields() { for manager, fields := range managed.Fields() {
if fields.Applied() == false { if !fields.Applied() {
updaters = append(updaters, manager) updaters = append(updaters, manager)
} }
} }

View File

@ -683,10 +683,7 @@ func shouldOrphanDependents(ctx context.Context, e *Store, accessor metav1.Objec
} }
// Get default orphan policy from this REST object type if it exists // Get default orphan policy from this REST object type if it exists
if defaultGCPolicy == rest.OrphanDependents { return defaultGCPolicy == rest.OrphanDependents
return true
}
return false
} }
// shouldDeleteDependents returns true if the finalizer for foreground deletion should be set // shouldDeleteDependents returns true if the finalizer for foreground deletion should be set

View File

@ -1115,7 +1115,7 @@ func (t *Tester) testDeleteGracefulImmediate(obj runtime.Object, createFn Create
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
if wasDeleted != true { if !wasDeleted {
t.Errorf("unexpected, object %s should have been deleted immediately", objectMeta.GetName()) t.Errorf("unexpected, object %s should have been deleted immediately", objectMeta.GetName())
} }
_, err = t.storage.(rest.Getter).Get(ctx, objectMeta.GetName(), &metav1.GetOptions{}) _, err = t.storage.(rest.Getter).Get(ctx, objectMeta.GetName(), &metav1.GetOptions{})

View File

@ -199,7 +199,7 @@ func validateTLSConfig(tlsConfig *apiserver.TLSConfig, fldPath *field.Path) fiel
return allErrs return allErrs
} }
if tlsConfig.CABundle != "" { if tlsConfig.CABundle != "" {
if exists, err := path.Exists(path.CheckFollowSymlink, tlsConfig.CABundle); exists == false || err != nil { if exists, err := path.Exists(path.CheckFollowSymlink, tlsConfig.CABundle); !exists || err != nil {
allErrs = append(allErrs, field.Invalid( allErrs = append(allErrs, field.Invalid(
fldPath.Child("tlsConfig", "caBundle"), fldPath.Child("tlsConfig", "caBundle"),
tlsConfig.CABundle, tlsConfig.CABundle,
@ -211,7 +211,7 @@ func validateTLSConfig(tlsConfig *apiserver.TLSConfig, fldPath *field.Path) fiel
fldPath.Child("tlsConfig", "clientCert"), fldPath.Child("tlsConfig", "clientCert"),
"nil", "nil",
"Using TLS requires clientCert")) "Using TLS requires clientCert"))
} else if exists, err := path.Exists(path.CheckFollowSymlink, tlsConfig.ClientCert); exists == false || err != nil { } else if exists, err := path.Exists(path.CheckFollowSymlink, tlsConfig.ClientCert); !exists || err != nil {
allErrs = append(allErrs, field.Invalid( allErrs = append(allErrs, field.Invalid(
fldPath.Child("tlsConfig", "clientCert"), fldPath.Child("tlsConfig", "clientCert"),
tlsConfig.ClientCert, tlsConfig.ClientCert,
@ -222,7 +222,7 @@ func validateTLSConfig(tlsConfig *apiserver.TLSConfig, fldPath *field.Path) fiel
fldPath.Child("tlsConfig", "clientKey"), fldPath.Child("tlsConfig", "clientKey"),
"nil", "nil",
"Using TLS requires requires clientKey")) "Using TLS requires requires clientKey"))
} else if exists, err := path.Exists(path.CheckFollowSymlink, tlsConfig.ClientKey); exists == false || err != nil { } else if exists, err := path.Exists(path.CheckFollowSymlink, tlsConfig.ClientKey); !exists || err != nil {
allErrs = append(allErrs, field.Invalid( allErrs = append(allErrs, field.Invalid(
fldPath.Child("tlsConfig", "clientKey"), fldPath.Child("tlsConfig", "clientKey"),
tlsConfig.ClientKey, tlsConfig.ClientKey,

View File

@ -80,9 +80,5 @@ type probabilisticGoawayDecider struct {
// Goaway implement GoawayDecider // Goaway implement GoawayDecider
func (p *probabilisticGoawayDecider) Goaway(r *http.Request) bool { func (p *probabilisticGoawayDecider) Goaway(r *http.Request) bool {
if p.next() < p.chance { return p.next() < p.chance
return true
}
return false
} }

View File

@ -113,17 +113,15 @@ func TestClientReceivedGOAWAY(t *testing.T) {
count := 0 count := 0
for { for {
select { <-timer.C
case <-timer.C: n, err := w.Write([]byte("w"))
n, err := w.Write([]byte("w")) if err != nil {
if err != nil { return
return }
} flusher.Flush()
flusher.Flush() count += n
count += n if count == watchExpectSendBytes {
if count == watchExpectSendBytes { return
return
}
} }
} }
}) })

View File

@ -18,6 +18,7 @@ package options
import ( import (
"fmt" "fmt"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"k8s.io/utils/path" "k8s.io/utils/path"
@ -84,7 +85,7 @@ func (o *EgressSelectorOptions) Validate() []error {
errs := []error{} errs := []error{}
if exists, err := path.Exists(path.CheckFollowSymlink, o.ConfigFile); exists == false || err != nil { if exists, err := path.Exists(path.CheckFollowSymlink, o.ConfigFile); !exists || err != nil {
errs = append(errs, fmt.Errorf("egress-selector-config-file %s does not exist", o.ConfigFile)) errs = append(errs, fmt.Errorf("egress-selector-config-file %s does not exist", o.ConfigFile))
} }

View File

@ -85,11 +85,7 @@ func (o *ResourceConfig) EnableVersions(versions ...schema.GroupVersion) {
func (o *ResourceConfig) VersionEnabled(version schema.GroupVersion) bool { func (o *ResourceConfig) VersionEnabled(version schema.GroupVersion) bool {
enabled, _ := o.GroupVersionConfigs[version] enabled, _ := o.GroupVersionConfigs[version]
if enabled { return enabled
return true
}
return false
} }
func (o *ResourceConfig) DisableResources(resources ...schema.GroupVersionResource) { func (o *ResourceConfig) DisableResources(resources ...schema.GroupVersionResource) {

View File

@ -348,9 +348,7 @@ func ClockWait(clk *testclock.FakeEventClock, counter counter.GoRoutineCounter,
close(dunch) close(dunch)
}, duration) }, duration)
counter.Add(-1) counter.Add(-1)
select { <-dunch
case <-dunch:
}
} }
func init() { func init() {

View File

@ -51,10 +51,8 @@ type RealEventClock struct {
func (RealEventClock) EventAfterDuration(f EventFunc, d time.Duration) { func (RealEventClock) EventAfterDuration(f EventFunc, d time.Duration) {
ch := time.After(d) ch := time.After(d)
go func() { go func() {
select { t := <-ch
case t := <-ch: f(t)
f(t)
}
}() }()
} }