Skip to content

Commit

Permalink
*: fix gosimple errors (prometheus-operator#3934)
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
  • Loading branch information
simonpasquier authored Mar 26, 2021
1 parent bbb2431 commit 2060d36
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 38 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ linters:
disable-all: true
enable:
- golint
- gosimple
- govet
- staticcheck
- unused
30 changes: 13 additions & 17 deletions cmd/po-docgen/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func printAPIDocs(paths []string) {

fmt.Println("| Field | Description | Scheme | Required |")
fmt.Println("| ----- | ----------- | ------ | -------- |")
fields := t[1:(len(t))]
fields := t[1:]
for _, f := range fields {
fmt.Println("|", f.Name, "|", f.Doc, "|", f.Type, "|", f.Mandatory, "|")
}
Expand Down Expand Up @@ -240,18 +240,16 @@ func isInlined(field *ast.Field) bool {
}

func isInternalType(typ ast.Expr) bool {
switch typ.(type) {
switch typ := typ.(type) {
case *ast.SelectorExpr:
e := typ.(*ast.SelectorExpr)
pkg := e.X.(*ast.Ident)
pkg := typ.X.(*ast.Ident)
return strings.HasPrefix(pkg.Name, "monitoring")
case *ast.StarExpr:
return isInternalType(typ.(*ast.StarExpr).X)
return isInternalType(typ.X)
case *ast.ArrayType:
return isInternalType(typ.(*ast.ArrayType).Elt)
return isInternalType(typ.Elt)
case *ast.MapType:
mapType := typ.(*ast.MapType)
return isInternalType(mapType.Key) && isInternalType(mapType.Value)
return isInternalType(typ.Key) && isInternalType(typ.Value)
default:
return true
}
Expand Down Expand Up @@ -283,21 +281,19 @@ func fieldRequired(field *ast.Field) bool {
}

func fieldType(typ ast.Expr) string {
switch typ.(type) {
switch typ := typ.(type) {
case *ast.Ident:
return toLink(typ.(*ast.Ident).Name)
return toLink(typ.Name)
case *ast.StarExpr:
return "*" + toLink(fieldType(typ.(*ast.StarExpr).X))
return "*" + toLink(fieldType(typ.X))
case *ast.SelectorExpr:
e := typ.(*ast.SelectorExpr)
pkg := e.X.(*ast.Ident)
t := e.Sel
pkg := typ.X.(*ast.Ident)
t := typ.Sel
return toLink(pkg.Name + "." + t.Name)
case *ast.ArrayType:
return "[]" + toLink(fieldType(typ.(*ast.ArrayType).Elt))
return "[]" + toLink(fieldType(typ.Elt))
case *ast.MapType:
mapType := typ.(*ast.MapType)
return "map[" + toLink(fieldType(mapType.Key)) + "]" + toLink(fieldType(mapType.Value))
return "map[" + toLink(fieldType(typ.Key)) + "]" + toLink(fieldType(typ.Value))
default:
return ""
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/alertmanager/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ func makeStatefulSet(am *monitoringv1.Alertmanager, old *appsv1.StatefulSet, con
statefulset.Annotations = old.Annotations
}

for _, volume := range am.Spec.Volumes {
statefulset.Spec.Template.Spec.Volumes = append(statefulset.Spec.Template.Spec.Volumes, volume)
}
statefulset.Spec.Template.Spec.Volumes = append(statefulset.Spec.Template.Spec.Volumes, am.Spec.Volumes...)

return statefulset, nil
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/prometheus/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,7 @@ func makeStatefulSet(
statefulset.Spec.VolumeClaimTemplates = append(statefulset.Spec.VolumeClaimTemplates, *pvcTemplate)
}

for _, volume := range p.Spec.Volumes {
statefulset.Spec.Template.Spec.Volumes = append(statefulset.Spec.Template.Spec.Volumes, volume)
}
statefulset.Spec.Template.Spec.Volumes = append(statefulset.Spec.Template.Spec.Volumes, p.Spec.Volumes...)

return statefulset, nil
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/thanos/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ func makeStatefulSet(tr *monitoringv1.ThanosRuler, config Config, ruleConfigMapN
statefulset.Spec.VolumeClaimTemplates = append(statefulset.Spec.VolumeClaimTemplates, *pvcTemplate)
}

for _, volume := range tr.Spec.Volumes {
statefulset.Spec.Template.Spec.Volumes = append(statefulset.Spec.Template.Spec.Volumes, volume)
}
statefulset.Spec.Template.Spec.Volumes = append(statefulset.Spec.Template.Spec.Volumes, tr.Spec.Volumes...)

return statefulset, nil
}
Expand Down
13 changes: 6 additions & 7 deletions test/framework/admission-webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package framework

import (
"context"
"fmt"
"github.com/pkg/errors"
"k8s.io/api/admissionregistration/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -27,15 +26,15 @@ import (
func createMutatingHook(kubeClient kubernetes.Interface, certBytes []byte, namespace, yamlPath string) (FinalizerFn, error) {
h, err := parseMutatingHookYaml(yamlPath)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("Failed parsing mutating webhook"))
return nil, errors.Wrap(err, "Failed parsing mutating webhook")
}

h.Webhooks[0].ClientConfig.Service.Namespace = namespace
h.Webhooks[0].ClientConfig.CABundle = certBytes

_, err = kubeClient.AdmissionregistrationV1beta1().MutatingWebhookConfigurations().Create(context.TODO(), h, metav1.CreateOptions{})
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to create mutating webhook %s", h.Name))
return nil, errors.Wrapf(err, "failed to create mutating webhook %s", h.Name)
}

finalizerFn := func() error { return deleteMutatingWebhook(kubeClient, h.Name) }
Expand All @@ -46,15 +45,15 @@ func createMutatingHook(kubeClient kubernetes.Interface, certBytes []byte, names
func createValidatingHook(kubeClient kubernetes.Interface, certBytes []byte, namespace, yamlPath string) (FinalizerFn, error) {
h, err := parseValidatingHookYaml(yamlPath)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("Failed parsing mutating webhook"))
return nil, errors.Wrap(err, "Failed parsing mutating webhook")
}

h.Webhooks[0].ClientConfig.Service.Namespace = namespace
h.Webhooks[0].ClientConfig.CABundle = certBytes

_, err = kubeClient.AdmissionregistrationV1beta1().ValidatingWebhookConfigurations().Create(context.TODO(), h, metav1.CreateOptions{})
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to create validating webhook %s", h.Name))
return nil, errors.Wrapf(err, "failed to create validating webhook %s", h.Name)
}

finalizerFn := func() error { return deleteValidatingWebhook(kubeClient, h.Name) }
Expand All @@ -78,7 +77,7 @@ func parseValidatingHookYaml(pathToYaml string) (*v1beta1.ValidatingWebhookConfi

resource := v1beta1.ValidatingWebhookConfiguration{}
if err := yaml.NewYAMLOrJSONDecoder(manifest, 100).Decode(&resource); err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to decode file %s", pathToYaml))
return nil, errors.Wrapf(err, "failed to decode file %s", pathToYaml)
}

return &resource, nil
Expand All @@ -92,7 +91,7 @@ func parseMutatingHookYaml(pathToYaml string) (*v1beta1.MutatingWebhookConfigura

resource := v1beta1.MutatingWebhookConfiguration{}
if err := yaml.NewYAMLOrJSONDecoder(manifest, 100).Decode(&resource); err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to decode file %s", pathToYaml))
return nil, errors.Wrapf(err, "failed to decode file %s", pathToYaml)
}

return &resource, nil
Expand Down
9 changes: 4 additions & 5 deletions test/framework/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ package framework

import (
"context"
"fmt"
"io/ioutil"
"net/http"
"strings"
"time"

"github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring"
"github.com/ghodss/yaml"
"github.com/pkg/errors"
"github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring"
v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -36,7 +35,7 @@ import (
func (f *Framework) GetCRD(name string) (*v1.CustomResourceDefinition, error) {
crd, err := f.APIServerClient.ApiextensionsV1().CustomResourceDefinitions().Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("unable to get CRD with name %v", name))
return nil, errors.Wrapf(err, "unable to get CRD with name %v", name)
}
return crd, nil
}
Expand All @@ -45,7 +44,7 @@ func (f *Framework) GetCRD(name string) (*v1.CustomResourceDefinition, error) {
func (f *Framework) ListCRDs() (*v1.CustomResourceDefinitionList, error) {
crds, err := f.APIServerClient.ApiextensionsV1().CustomResourceDefinitions().List(context.TODO(), metav1.ListOptions{})
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("unable to list CRDs"))
return nil, errors.Wrap(err, "unable to list CRDs")
}
return crds, nil
}
Expand Down Expand Up @@ -97,7 +96,7 @@ func WaitForCRDReady(listFunc func(opts metav1.ListOptions) (runtime.Object, err
return true, nil
})

return errors.Wrap(err, fmt.Sprintf("timed out waiting for Custom Resource"))
return errors.Wrap(err, "timed out waiting for Custom Resource")
}

// CreateCRDAndWaitUntilReady creates a Custom Resource Definition from yaml
Expand Down

0 comments on commit 2060d36

Please sign in to comment.