1
0
mirror of https://github.com/coreos/prometheus-operator.git synced 2026-02-05 06:45:27 +01:00

*: fix gosimple errors (#3934)

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
Simon Pasquier
2021-03-26 14:08:26 +01:00
committed by GitHub
parent bbb2431b99
commit 2060d3613f
7 changed files with 27 additions and 38 deletions

View File

@@ -5,6 +5,7 @@ linters:
disable-all: true
enable:
- golint
- gosimple
- govet
- staticcheck
- unused

View File

@@ -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, "|")
}
@@ -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
}
@@ -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 ""
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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"
@@ -27,7 +26,7 @@ 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
@@ -35,7 +34,7 @@ func createMutatingHook(kubeClient kubernetes.Interface, certBytes []byte, names
_, 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) }
@@ -46,7 +45,7 @@ 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
@@ -54,7 +53,7 @@ func createValidatingHook(kubeClient kubernetes.Interface, certBytes []byte, nam
_, 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) }
@@ -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
@@ -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

View File

@@ -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"
@@ -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
}
@@ -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
}
@@ -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