Skip to content

Commit

Permalink
Merge pull request #5 from futuretea/master
Browse files Browse the repository at this point in the history
fix lint
  • Loading branch information
Benjamin Huo authored Jul 31, 2020
2 parents 6fa66c6 + 61ed390 commit a24970f
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 45 deletions.
18 changes: 8 additions & 10 deletions cmd/docgen/kube-events-docgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,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 @@ -227,20 +227,18 @@ func fieldRequired(field *ast.Field) bool {
}

func fieldType(typ ast.Expr) string {
switch typ.(type) {
switch t := typ.(type) {
case *ast.Ident:
return toLink(typ.(*ast.Ident).Name)
return toLink(t.Name)
case *ast.StarExpr:
return "*" + toLink(fieldType(typ.(*ast.StarExpr).X))
return "*" + toLink(fieldType(t.X))
case *ast.SelectorExpr:
e := typ.(*ast.SelectorExpr)
pkg := e.X.(*ast.Ident)
t := e.Sel
return toLink(pkg.Name + "." + t.Name)
pkg := t.X.(*ast.Ident)
return toLink(pkg.Name + "." + t.Sel.Name)
case *ast.ArrayType:
return "[]" + toLink(fieldType(typ.(*ast.ArrayType).Elt))
return "[]" + toLink(fieldType(t.Elt))
case *ast.MapType:
mapType := typ.(*ast.MapType)
mapType := t
return "map[" + toLink(fieldType(mapType.Key)) + "]" + toLink(fieldType(mapType.Value))
default:
return ""
Expand Down
4 changes: 1 addition & 3 deletions cmd/exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ func main() {
klog.Info("Config reloaded")
})
server := &http.Server{Addr: ":8443", Handler: router}
wg.Go(func() error {
return server.ListenAndServe()
})
wg.Go(server.ListenAndServe)

stopCh := util.SignalHandler()
go func() {
Expand Down
3 changes: 2 additions & 1 deletion cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ package main

import (
"flag"
"github.com/kubesphere/kube-events/pkg/config"
"os"

"github.com/kubesphere/kube-events/pkg/config"

"k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
Expand Down
7 changes: 3 additions & 4 deletions cmd/ruler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"encoding/json"
"flag"
"fmt"
v1 "k8s.io/api/core/v1"
"net/http"
"runtime"
"time"

v1 "k8s.io/api/core/v1"

"github.com/julienschmidt/httprouter"
"github.com/kubesphere/kube-events/pkg/config"
"github.com/kubesphere/kube-events/pkg/ruler"
Expand Down Expand Up @@ -77,9 +78,7 @@ func main() {
}
})
server := &http.Server{Addr: ":8443", Handler: router}
wg.Go(func() error {
return server.ListenAndServe()
})
wg.Go(server.ListenAndServe)

stopCh := util.SignalHandler()
go func() {
Expand Down
3 changes: 1 addition & 2 deletions pkg/apis/v1alpha1/rule_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
"fmt"

apierrs "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -121,7 +122,6 @@ func (r *Rule) ValidateDelete() error {
}

func (r *Rule) validateRule() error {

var allErrs field.ErrorList
if err := r.validateRuleScope(); err != nil {
allErrs = append(allErrs, err)
Expand All @@ -136,7 +136,6 @@ func (r *Rule) validateRule() error {
}

func (r *Rule) validateRuleScope() *field.Error {

rs, ok := r.Labels[_ruleScopeConfig.ScopeLabelKey]
labelsFieldPath := field.NewPath("metadata").Child("labels", _ruleScopeConfig.ScopeLabelKey)
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/config/exporter_config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package config

import (
"github.com/pkg/errors"
"io/ioutil"

"github.com/pkg/errors"
"sigs.k8s.io/yaml"
)

Expand Down
4 changes: 1 addition & 3 deletions pkg/config/ruler_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package config

import (
"io/ioutil"
"k8s.io/apimachinery/pkg/labels"
)

import (
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/labels"
"sigs.k8s.io/yaml"
)

Expand Down
5 changes: 3 additions & 2 deletions pkg/controllers/exporter_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ package controllers
import (
"context"
"fmt"
"path"
"reflect"

"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/workqueue"
"path"
"reflect"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
Expand Down
5 changes: 3 additions & 2 deletions pkg/controllers/ruler_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ package controllers
import (
"context"
"fmt"
"path"
"reflect"

"github.com/go-logr/logr"
"github.com/kubesphere/kube-events/pkg/config"
appsv1 "k8s.io/api/apps/v1"
Expand All @@ -31,8 +34,6 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/util/workqueue"
"path"
"reflect"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
Expand Down
3 changes: 2 additions & 1 deletion pkg/exporter/kube_events_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package exporter

import (
"context"
"errors"
"fmt"
"sync"
"time"
Expand Down Expand Up @@ -72,7 +73,7 @@ func (s *K8sEventSource) Run(ctx context.Context) error {

func (s *K8sEventSource) waitForCacheSync(stopc <-chan struct{}) error {
if !cache.WaitForCacheSync(stopc, s.inf.HasSynced) {
return fmt.Errorf("Failed to sync events cache")
return errors.New("failed to sync events cache")
}
klog.Info("Successfully synced events cache")
return nil
Expand Down
3 changes: 2 additions & 1 deletion pkg/exporter/sinks/stdout.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import (
"context"
"encoding/json"
"fmt"
"k8s.io/api/core/v1"

v1 "k8s.io/api/core/v1"
)

type StdoutSinker struct {
Expand Down
2 changes: 0 additions & 2 deletions pkg/ruler/rule_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ func (c *RuleCache) GetRules(ctx context.Context, evt *types.Event) (rules []*v1
}

return

}

func (c *RuleCache) ruleAdd(obj interface{}) {
Expand All @@ -130,7 +129,6 @@ func (c *RuleCache) ruleAdd(obj interface{}) {
m, _ := c.namespaceRules.LoadOrStore(rule.Namespace, &sync.Map{})
m.(*sync.Map).Store(c.ruleNameFromNamespaceRule(rule), rule)
}

}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/ruler/sinks/alert/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ type AlertmanagerSinker struct {
}

func (s *AlertmanagerSinker) SinkAlerts(ctx context.Context, evtAlerts []*types.EventAlert) error {
var alerts []*amkit.RawAlert
for _, ea := range evtAlerts {
alerts = append(alerts, ea.Alert)
alerts := make([]*amkit.RawAlert, len(evtAlerts))
for i, ea := range evtAlerts {
alerts[i] = ea.Alert
}
if len(alerts) == 0 {
return nil
Expand Down
4 changes: 3 additions & 1 deletion pkg/ruler/sinks/alert/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/kubesphere/kube-events/pkg/util"
"net/http"

"github.com/kubesphere/kube-events/pkg/ruler/types"
Expand All @@ -29,8 +30,9 @@ func (s *WebhookSinker) SinkAlerts(ctx context.Context, evtAlerts []*types.Event
if err != nil {
return fmt.Errorf("error sinking to webhook(%s): %v", s.Url, err)
}
util.DrainResponse(resp)
if resp.StatusCode/100 != 2 {
err = fmt.Errorf("error sinking to webhook(%s): bad response status: %s", s.Url, resp.Status)
return fmt.Errorf("error sinking to webhook(%s): bad response status: %s", s.Url, resp.Status)
}
return nil
}
4 changes: 3 additions & 1 deletion pkg/ruler/sinks/notification/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/kubesphere/kube-events/pkg/util"
"net/http"

"github.com/kubesphere/kube-events/pkg/ruler/types"
Expand Down Expand Up @@ -35,8 +36,9 @@ func (s *WebhookSinker) SinkNotifications(ctx context.Context, evtNotifications
if err != nil {
return fmt.Errorf("error sinking to webhook(%s): %v", s.Url, err)
}
util.DrainResponse(resp)
if resp.StatusCode/100 != 2 {
err = fmt.Errorf("error sinking to webhook(%s): bad response status: %s", s.Url, resp.Status)
return fmt.Errorf("error sinking to webhook(%s): bad response status: %s", s.Url, resp.Status)
}
return nil
}
12 changes: 6 additions & 6 deletions pkg/ruler/visitor/eventrule.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ func NewVisitor(m map[string]interface{}) *Visitor {
}
}

func (l *Visitor) pushValue(i bool) {
l.valueStack = append(l.valueStack, i)
func (v *Visitor) pushValue(i bool) {
v.valueStack = append(v.valueStack, i)
}

func (l *Visitor) popValue() bool {
if len(l.valueStack) < 1 {
func (v *Visitor) popValue() bool {
if len(v.valueStack) < 1 {
panic("valueStack is empty unable to pop")
}

// Get the last value from the stack.
result := l.valueStack[len(l.valueStack)-1]
result := v.valueStack[len(v.valueStack)-1]

// Remove the last element from the stack.
l.valueStack = l.valueStack[:len(l.valueStack)-1]
v.valueStack = v.valueStack[:len(v.valueStack)-1]

return result
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/util/sysutil.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package util

import (
"k8s.io/klog"
"os"
"os/signal"
"syscall"

"k8s.io/klog"
)

// SignalHandler setups a signal hander to gracefully exit
Expand Down

0 comments on commit a24970f

Please sign in to comment.