mirror of https://github.com/knative/pkg.git
Fix the issues pointed out by staticcheck (#541)
* Fix the issues pointed out by staticcheck * review fix
This commit is contained in:
parent
e4bc08cc8d
commit
74c5d67ea0
|
@ -192,12 +192,7 @@ func (r conditionsImpl) isTerminal(t ConditionType) bool {
|
|||
return true
|
||||
}
|
||||
}
|
||||
|
||||
if t == r.happy {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
return t == r.happy
|
||||
}
|
||||
|
||||
func (r conditionsImpl) severity(t ConditionType) ConditionSeverity {
|
||||
|
|
|
@ -81,8 +81,8 @@ func CheckDeprecatedUpdate(ctx context.Context, obj interface{}, original interf
|
|||
}
|
||||
|
||||
func getPrefixedNamedFieldValues(prefix string, obj interface{}) (map[string]reflect.Value, map[string]interface{}) {
|
||||
fields := make(map[string]reflect.Value, 0)
|
||||
inlined := make(map[string]interface{}, 0)
|
||||
fields := map[string]reflect.Value{}
|
||||
inlined := map[string]interface{}{}
|
||||
|
||||
objValue := reflect.Indirect(reflect.ValueOf(obj))
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ var (
|
|||
)
|
||||
|
||||
// GetFullType implements duck.Implementable
|
||||
func (_ *PodSpecable) GetFullType() duck.Populatable {
|
||||
func (*PodSpecable) GetFullType() duck.Populatable {
|
||||
return &WithPod{}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ var (
|
|||
)
|
||||
|
||||
// GetFullType implements duck.Implementable
|
||||
func (_ *Scalable) GetFullType() duck.Populatable {
|
||||
func (*Scalable) GetFullType() duck.Populatable {
|
||||
return &Scalable{}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ func (dif *TypedInformerFactory) Get(gvr schema.GroupVersionResource) (cache.Sha
|
|||
go inf.Run(dif.StopChannel)
|
||||
|
||||
if ok := cache.WaitForCacheSync(dif.StopChannel, inf.HasSynced); !ok {
|
||||
return nil, nil, fmt.Errorf("Failed starting shared index informer for %v with type %T", gvr, dif.Type)
|
||||
return nil, nil, fmt.Errorf("failed starting shared index informer for %v with type %T", gvr, dif.Type)
|
||||
}
|
||||
|
||||
return inf, lister, nil
|
||||
|
|
|
@ -218,11 +218,7 @@ func (r conditionsImpl) isTerminal(t ConditionType) bool {
|
|||
}
|
||||
}
|
||||
|
||||
if t == r.happy {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
return t == r.happy
|
||||
}
|
||||
|
||||
func (r conditionsImpl) severity(t ConditionType) ConditionSeverity {
|
||||
|
|
|
@ -321,7 +321,6 @@ func (u *UnableToMarshal) GetFullType() Populatable {
|
|||
}
|
||||
|
||||
func (u *UnableToMarshal) Populate() {
|
||||
return
|
||||
}
|
||||
|
||||
func (u *UnableToMarshal) MarshalJSON() ([]byte, error) {
|
||||
|
@ -340,7 +339,6 @@ func (u *UnableToUnmarshal) GetFullType() Populatable {
|
|||
}
|
||||
|
||||
func (u *UnableToUnmarshal) Populate() {
|
||||
return
|
||||
}
|
||||
|
||||
func (u *UnableToUnmarshal) UnmarshalJSON([]byte) error {
|
||||
|
@ -362,5 +360,4 @@ func (u *UnexportedFields) GetFullType() Populatable {
|
|||
|
||||
func (u *UnexportedFields) Populate() {
|
||||
u.a = "hello"
|
||||
return
|
||||
}
|
||||
|
|
|
@ -116,13 +116,6 @@ func anyError(errs ...error) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func require(name string, value string) error {
|
||||
if len(value) == 0 {
|
||||
return fmt.Errorf("missing required field %q", name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// The Cloud-Events spec allows two forms of JSON encoding:
|
||||
// 1. The overall message (Structured JSON encoding)
|
||||
// 2. Just the event data, where the context will be in HTTP headers instead
|
||||
|
@ -160,7 +153,7 @@ func unmarshalEventData(encoding string, reader io.Reader, data interface{}) err
|
|||
return xml.NewDecoder(reader).Decode(&data)
|
||||
}
|
||||
|
||||
return fmt.Errorf("Cannot decode content type %q", encoding)
|
||||
return fmt.Errorf("cannot decode content type %q", encoding)
|
||||
}
|
||||
|
||||
func marshalEventData(encoding string, data interface{}) ([]byte, error) {
|
||||
|
@ -172,7 +165,7 @@ func marshalEventData(encoding string, data interface{}) ([]byte, error) {
|
|||
} else if isXMLEncoding(encoding) {
|
||||
b, err = xml.Marshal(data)
|
||||
} else {
|
||||
err = fmt.Errorf("Cannot encode content type %q", encoding)
|
||||
err = fmt.Errorf("cannot encode content type %q", encoding)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -40,11 +40,9 @@ func (w *ManualWatcher) Watch(name string, o Observer) {
|
|||
defer w.m.Unlock()
|
||||
|
||||
if w.observers == nil {
|
||||
w.observers = make(map[string][]Observer)
|
||||
w.observers = make(map[string][]Observer, 1)
|
||||
}
|
||||
|
||||
wl, _ := w.observers[name]
|
||||
w.observers[name] = append(wl, o)
|
||||
w.observers[name] = append(w.observers[name], o)
|
||||
}
|
||||
|
||||
func (w *ManualWatcher) Start(<-chan struct{}) error {
|
||||
|
|
|
@ -107,14 +107,11 @@ func appendTo(evidence *[]string) func(int) func(string, interface{}) {
|
|||
}
|
||||
|
||||
func listOf(f func(int) func(string, interface{}), count int, tail ...func(string, interface{})) []func(string, interface{}) {
|
||||
var result []func(string, interface{})
|
||||
result := make([]func(string, interface{}), 0, count)
|
||||
for i := 0; i < count; i++ {
|
||||
result = append(result, f(i))
|
||||
}
|
||||
for _, f := range tail {
|
||||
result = append(result, f)
|
||||
}
|
||||
return result
|
||||
return append(result, tail...)
|
||||
}
|
||||
|
||||
func expectedEvidence(name string, count int) []string {
|
||||
|
|
|
@ -409,7 +409,7 @@ func StartInformers(stopCh <-chan struct{}, informers ...Informer) error {
|
|||
|
||||
for i, informer := range informers {
|
||||
if ok := cache.WaitForCacheSync(stopCh, informer.HasSynced); !ok {
|
||||
return fmt.Errorf("Failed to wait for cache at index %d to sync", i)
|
||||
return fmt.Errorf("failed to wait for cache at index %d to sync", i)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -37,7 +37,7 @@ func TestSendGlobalUpdate(t *testing.T) {
|
|||
}
|
||||
SendGlobalUpdates(&dummyInformer{}, handler)
|
||||
for _, obj := range dummyObjs {
|
||||
if updated, _ := called[obj]; !updated {
|
||||
if updated := called[obj]; !updated {
|
||||
t.Errorf("Expected obj %v to be updated but wasn't", obj)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,11 +82,11 @@ func DeletionHandlingAccessor(obj interface{}) (Accessor, error) {
|
|||
// To handle obj deletion, try to fetch info from DeletedFinalStateUnknown.
|
||||
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Couldn't get Accessor from tombstone %#v", obj)
|
||||
return nil, fmt.Errorf("couldn't get Accessor from tombstone %#v", obj)
|
||||
}
|
||||
accessor, ok = tombstone.Obj.(Accessor)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("The object that Tombstone contained is not of kmeta.Accessor %#v", obj)
|
||||
return nil, fmt.Errorf("the object that Tombstone contained is not of kmeta.Accessor %#v", obj)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ const (
|
|||
head = longest - md5Len
|
||||
)
|
||||
|
||||
// ChildName generates a name for the resource based upong the parent resource and suffix.
|
||||
// ChildName generates a name for the resource based upon the parent resource and suffix.
|
||||
// If the concatenated name is longer than K8s permits the name is hashed and truncated to permit
|
||||
// construction of the resource, but still keeps it unique.
|
||||
func ChildName(parent, suffix string) string {
|
||||
|
|
|
@ -112,7 +112,7 @@ func (r *ShortDiffReporter) Report(rs cmp.Result) {
|
|||
var diff string
|
||||
// Prefix struct values with the types to add clarity in output
|
||||
if !vx.IsValid() && !vy.IsValid() {
|
||||
r.err = fmt.Errorf("Unable to diff %+v and %+v on path %#v", vx, vy, r.path)
|
||||
r.err = fmt.Errorf("unable to diff %+v and %+v on path %#v", vx, vy, r.path)
|
||||
} else {
|
||||
diff = fmt.Sprintf("%#v:\n", r.path)
|
||||
if vx.IsValid() {
|
||||
|
|
|
@ -50,7 +50,7 @@ func newMetricsExporter(config *metricsConfig, logger *zap.SugaredLogger) (view.
|
|||
case Prometheus:
|
||||
e, err = newPrometheusExporter(config, logger)
|
||||
default:
|
||||
err = fmt.Errorf("Unsupported metrics backend %v", config.backendDestination)
|
||||
err = fmt.Errorf("unsupported metrics backend %v", config.backendDestination)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -70,7 +70,7 @@ func (scc *signalContext) Err() error {
|
|||
select {
|
||||
case _, ok := <-scc.Done():
|
||||
if !ok {
|
||||
return errors.New("received a termination signal.")
|
||||
return errors.New("received a termination signal")
|
||||
}
|
||||
default:
|
||||
}
|
||||
|
|
|
@ -110,5 +110,5 @@ func (client *KubeClient) PodLogs(podName, containerName, namespace string) ([]b
|
|||
return result.Raw()
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("Could not find logs for %s/%s", podName, containerName)
|
||||
return nil, fmt.Errorf("could not find logs for %s/%s", podName, containerName)
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ func GetIngressEndpoint(kubeClientset *kubernetes.Clientset) (*string, error) {
|
|||
func EndpointFromService(svc *v1.Service) (string, error) {
|
||||
ingresses := svc.Status.LoadBalancer.Ingress
|
||||
if len(ingresses) != 1 {
|
||||
return "", fmt.Errorf("Expected exactly one ingress load balancer, instead had %d: %v", len(ingresses), ingresses)
|
||||
return "", fmt.Errorf("expected exactly one ingress load balancer, instead had %d: %v", len(ingresses), ingresses)
|
||||
}
|
||||
itu := ingresses[0]
|
||||
|
||||
|
@ -67,6 +67,6 @@ func EndpointFromService(svc *v1.Service) (string, error) {
|
|||
case itu.Hostname != "":
|
||||
return itu.Hostname, nil
|
||||
default:
|
||||
return "", fmt.Errorf("Expected ingress loadbalancer IP or hostname for %s to be set, instead was empty", svc.Name)
|
||||
return "", fmt.Errorf("expected ingress loadbalancer IP or hostname for %s to be set, instead was empty", svc.Name)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ func CheckPortAvailability(port int) error {
|
|||
func GetPods(kubeClientset *kubernetes.Clientset, app, namespace string) (*v1.PodList, error) {
|
||||
pods, err := kubeClientset.CoreV1().Pods(namespace).List(metav1.ListOptions{LabelSelector: fmt.Sprintf("app=%s", app)})
|
||||
if err == nil && len(pods.Items) == 0 {
|
||||
err = fmt.Errorf("No %s Pod found on the cluster. Ensure monitoring is switched on for your Knative Setup", app)
|
||||
err = fmt.Errorf("no %s Pod found on the cluster. Ensure monitoring is switched on for your Knative Setup", app)
|
||||
}
|
||||
|
||||
return pods, err
|
||||
|
@ -65,7 +65,7 @@ func PortForward(logf logging.FormatLogger, podList *v1.PodList, localPort, remo
|
|||
portFwdProcess, err := executeCmdBackground(logf, portFwdCmd)
|
||||
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("Failed to port forward: %v", err)
|
||||
return 0, fmt.Errorf("failed to port forward: %v", err)
|
||||
}
|
||||
|
||||
logf("running %s port-forward in background, pid = %d", podName, portFwdProcess.Pid)
|
||||
|
|
|
@ -57,14 +57,14 @@ func NewTracingConfigFromMap(cfgMap map[string]string) (*Config, error) {
|
|||
if enable, ok := cfgMap[enableKey]; ok {
|
||||
enableBool, err := strconv.ParseBool(enable)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed parsing tracing config %q: %v", enableKey, err)
|
||||
return nil, fmt.Errorf("failed parsing tracing config %q: %v", enableKey, err)
|
||||
}
|
||||
tc.Enable = enableBool
|
||||
}
|
||||
|
||||
if endpoint, ok := cfgMap[zipkinEndpointKey]; !ok {
|
||||
if tc.Enable {
|
||||
return nil, errors.New("Tracing enabled but no zipkin endpoint specified")
|
||||
return nil, errors.New("tracing enabled but no zipkin endpoint specified")
|
||||
}
|
||||
} else {
|
||||
tc.ZipkinEndpoint = endpoint
|
||||
|
@ -73,7 +73,7 @@ func NewTracingConfigFromMap(cfgMap map[string]string) (*Config, error) {
|
|||
if debug, ok := cfgMap[debugKey]; ok {
|
||||
debugBool, err := strconv.ParseBool(debug)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed parsing tracing config %q", debugKey)
|
||||
return nil, fmt.Errorf("failed parsing tracing config %q", debugKey)
|
||||
}
|
||||
tc.Debug = debugBool
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ func NewTracingConfigFromMap(cfgMap map[string]string) (*Config, error) {
|
|||
if sampleRate, ok := cfgMap[sampleRateKey]; ok {
|
||||
sampleRateFloat, err := strconv.ParseFloat(sampleRate, 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to parse sampleRate in tracing config: %v", err)
|
||||
return nil, fmt.Errorf("failed to parse sampleRate in tracing config: %v", err)
|
||||
}
|
||||
tc.SampleRate = sampleRateFloat
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ func (oct *OpenCensusTracer) Finish() error {
|
|||
err := oct.acquireGlobal()
|
||||
defer octMutex.Unlock()
|
||||
if err != nil {
|
||||
return errors.New("Finish called on OpenTracer which is not the global OpenCensusTracer.")
|
||||
return errors.New("finish called on OpenTracer which is not the global OpenCensusTracer")
|
||||
}
|
||||
|
||||
for _, configOpt := range oct.configOptions {
|
||||
|
@ -79,7 +79,7 @@ func (oct *OpenCensusTracer) acquireGlobal() error {
|
|||
if globalOct == nil {
|
||||
globalOct = oct
|
||||
} else if globalOct != oct {
|
||||
return errors.New("A OpenCensusTracer already exists and only one can be run at a time.")
|
||||
return errors.New("an OpenCensusTracer already exists and only one can be run at a time")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -80,7 +80,7 @@ func (i *impl) Track(ref corev1.ObjectReference, obj interface{}) error {
|
|||
}
|
||||
if len(fieldErrors) > 0 {
|
||||
sort.Strings(fieldErrors)
|
||||
return fmt.Errorf("Invalid ObjectReference:\n%s", strings.Join(fieldErrors, "\n"))
|
||||
return fmt.Errorf("invalid ObjectReference:\n%s", strings.Join(fieldErrors, "\n"))
|
||||
}
|
||||
|
||||
key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(obj)
|
||||
|
|
|
@ -40,7 +40,7 @@ func waitForServerAvailable(t *testing.T, serverURL string, timeout time.Duratio
|
|||
|
||||
conditionFunc := func() (done bool, err error) {
|
||||
var conn net.Conn
|
||||
conn, err = net.DialTimeout("tcp", serverURL, timeout)
|
||||
conn, _ = net.DialTimeout("tcp", serverURL, timeout)
|
||||
if conn != nil {
|
||||
conn.Close()
|
||||
return true, nil
|
||||
|
|
|
@ -127,10 +127,6 @@ type AdmissionController struct {
|
|||
DisallowUnknownFields bool
|
||||
}
|
||||
|
||||
func nop(ctx context.Context) context.Context {
|
||||
return ctx
|
||||
}
|
||||
|
||||
// GenericCRD is the interface definition that allows us to perform the generic
|
||||
// CRD actions like deciding whether to increment generation and so forth.
|
||||
type GenericCRD interface {
|
||||
|
@ -214,13 +210,15 @@ func getOrGenerateKeyCertsFromSecret(ctx context.Context, client kubernetes.Inte
|
|||
return nil, nil, nil, err
|
||||
}
|
||||
secret, err = client.CoreV1().Secrets(newSecret.Namespace).Create(newSecret)
|
||||
if err != nil && !apierrors.IsAlreadyExists(err) {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
// Ok, so something else might have created, try fetching it one more time
|
||||
secret, err = client.CoreV1().Secrets(options.Namespace).Get(options.SecretName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
if !apierrors.IsAlreadyExists(err) {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
// OK, so something else might have created, try fetching it instead.
|
||||
secret, err = client.CoreV1().Secrets(options.Namespace).Get(options.SecretName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ func TestMissingContentType(t *testing.T) {
|
|||
go func() {
|
||||
err := ac.Run(stopCh)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to run controller: %s", err)
|
||||
t.Errorf("Unable to run controller: %s", err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -102,7 +102,7 @@ func TestEmptyRequestBody(t *testing.T) {
|
|||
go func() {
|
||||
err := ac.Run(stopCh)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to run controller: %s", err)
|
||||
t.Errorf("Unable to run controller: %s", err)
|
||||
}
|
||||
}()
|
||||
defer close(stopCh)
|
||||
|
@ -156,7 +156,7 @@ func TestValidResponseForResource(t *testing.T) {
|
|||
go func() {
|
||||
err := ac.Run(stopCh)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to run controller: %s", err)
|
||||
t.Errorf("Unable to run controller: %s", err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -242,7 +242,7 @@ func TestValidResponseForResourceWithContextDefault(t *testing.T) {
|
|||
go func() {
|
||||
err := ac.Run(stopCh)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to run controller: %s", err)
|
||||
t.Errorf("Unable to run controller: %s", err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -337,7 +337,7 @@ func TestInvalidResponseForResource(t *testing.T) {
|
|||
go func() {
|
||||
err := ac.Run(stopCh)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to run controller: %s", err)
|
||||
t.Errorf("Unable to run controller: %s", err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -445,7 +445,7 @@ func TestWebhookClientAuth(t *testing.T) {
|
|||
go func() {
|
||||
err := ac.Run(stopCh)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to run controller: %s", err)
|
||||
t.Errorf("Unable to run controller: %s", err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
@ -76,7 +76,6 @@ func (c *inspectableConnection) SetPongHandler(func(string) error) {
|
|||
if c.setPongHandlerCalls != nil {
|
||||
c.setPongHandlerCalls <- struct{}{}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// staticConnFactory returns a static connection, for example
|
||||
|
|
Loading…
Reference in New Issue