Skip to content

Commit

Permalink
adding golint and goimports check
Browse files Browse the repository at this point in the history
  • Loading branch information
M00nF1sh committed Nov 5, 2018
1 parent 4459b01 commit 6c6ddee
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 42 deletions.
16 changes: 16 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
linters:
enable:
- deadcode
- errcheck
- goimports
- golint
- govet
- ineffassign
- megacheck
- structcheck
- typecheck
- varcheck

issues:
exclude:
- IpAddressType # AWS SDK GO are using IpAddressType, while go-lint requires IPAddressType :(
4 changes: 2 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func main() {
if options.ProfilingEnabled {
registerProfiler(mux)
}
registerHealthz(mux, &aws.AWSHealthChecker{Cloud: cloud})
registerHealthz(mux, &aws.HealthChecker{Cloud: cloud})
registerMetrics(mux, reg)
registerHandlers(mux)
go startHTTPServer(options.HealthzPort, mux)
Expand Down Expand Up @@ -143,7 +143,7 @@ func registerHandlers(mux *http.ServeMux) {
})
}

func registerHealthz(mux *http.ServeMux, awsChecker *aws.AWSHealthChecker) {
func registerHealthz(mux *http.ServeMux, awsChecker *aws.HealthChecker) {
healthz.InstallHandler(mux, healthz.PingHealthz, awsChecker)
}

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/gogo/protobuf v1.1.1 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/groupcache v0.0.0-20180513044358-24b0969c4cb7 // indirect
github.com/golangci/golangci-lint v1.11.2 // indirect
github.com/golangci/golangci-lint v1.11.3 // indirect
github.com/google/btree v0.0.0-20180124185431-e89373fe6b4a // indirect
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect
github.com/google/pprof v0.0.0-20181002142953-f36417847b1c // indirect
Expand Down Expand Up @@ -51,6 +51,7 @@ require (
golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1 // indirect
golang.org/x/sys v0.0.0-20181011152604-fa43e7bc11ba // indirect
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 // indirect
golang.org/x/tools v0.0.0-20181105213840-e504f914a84b // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/go-playground/pool.v3 v3.1.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand Down
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ github.com/golangci/gocyclo v0.0.0-20180528134321-2becd97e67ee h1:J2XAy40+7yz70u
github.com/golangci/gocyclo v0.0.0-20180528134321-2becd97e67ee/go.mod h1:ozx7R9SIwqmqf5pRP90DhR2Oay2UIjGuKheCBCNwAYU=
github.com/golangci/gofmt v0.0.0-20180506063654-2076e05ced53 h1:8jBcdanEIu0YqTWHt9SUjObv3T0WnlTcmo/ZYm7qkRM=
github.com/golangci/gofmt v0.0.0-20180506063654-2076e05ced53/go.mod h1:9qCChq59u/eW8im404Q2WWTrnBUQKjpNYKMbU4M7EFU=
github.com/golangci/gofmt v0.0.0-20180506063654-f021c4179c82 h1:5BiROOAXXZtBptroGmuGdcW0ixsbp7xves58FY1gabE=
github.com/golangci/gofmt v0.0.0-20180506063654-f021c4179c82/go.mod h1:9qCChq59u/eW8im404Q2WWTrnBUQKjpNYKMbU4M7EFU=
github.com/golangci/golangci-lint v1.11.2 h1:acJRljphMCm3y3W7d72EF71uCGd1soIRgCwBCAxnAxI=
github.com/golangci/golangci-lint v1.11.2/go.mod h1:i/0K4y5EU5IXsEVUNIPBisgv7UYGoGT4x1x68i0OWR0=
github.com/golangci/golangci-lint v1.11.3 h1:a8YbZ4DmOhcuGRL3E7/jc9UhkpnlNJQ7FIJdHPZynDM=
github.com/golangci/golangci-lint v1.11.3/go.mod h1:HAEIsExr9/wT2mWEZ5ULKm5ZaArSSddtq0pinjO42t4=
github.com/golangci/gosec v0.0.0-20180901114220-8afd9cbb6cfb h1:Bi7BYmZVg4C+mKGi8LeohcP2GGUl2XJD4xCkJoZSaYc=
github.com/golangci/gosec v0.0.0-20180901114220-8afd9cbb6cfb/go.mod h1:ON/c2UR0VAAv6ZEAFKhjCLplESSmRFfZcDLASbI1GWo=
github.com/golangci/govet v0.0.0-20180818181408-44ddbe260190 h1:SLIgprnxQNjBpkz55PK1vfb64/gKU/TgVi0obFw8Lec=
Expand All @@ -104,6 +108,8 @@ github.com/golangci/revgrep v0.0.0-20180526074752-d9c87f5ffaf0 h1:HVfrLniijszjS1
github.com/golangci/revgrep v0.0.0-20180526074752-d9c87f5ffaf0/go.mod h1:qOQCunEYvmd/TLamH+7LlVccLvUH5kZNhbCgTHoBbp4=
github.com/golangci/tools v0.0.0-20180902102414-01dd7756e01d h1:4QH4xtTy4M3F8kdIfqyllzZrTErojSFfwt1NFApxWBQ=
github.com/golangci/tools v0.0.0-20180902102414-01dd7756e01d/go.mod h1:zgj6NOYXOC1cexsdtDceI4/mj3aXK4JOVg9AV3C5LWI=
github.com/golangci/tools v0.0.0-20180902102414-ed64e33c8c8b h1:3a73k6ptEhiI9YA8cEe4i6nsLWQRjtBG97+tjhS+QBs=
github.com/golangci/tools v0.0.0-20180902102414-ed64e33c8c8b/go.mod h1:zgj6NOYXOC1cexsdtDceI4/mj3aXK4JOVg9AV3C5LWI=
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4 h1:zwtduBRr5SSWhqsYNgcuWO2kFlpdOZbP0+yRjmvPGys=
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4/go.mod h1:Izgrg8RkN3rCIMLGE9CyYmU9pY2Jer6DgANEnZ/L/cQ=
github.com/golangci/unparam v0.0.0-20180902112548-7ad9dbcccc16 h1:QURX/XMP2uJUzzEvfJ291v1snmbJuyznAJLSQVnPyko=
Expand Down Expand Up @@ -288,8 +294,11 @@ golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxb
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180826000951-f6ba57429505/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180831211245-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180831211245-f60e5f99f081 h1:Z5EL45q6aqWaubSrtqXPa58Maax3YqHzst1l7qHcYV4=
golang.org/x/tools v0.0.0-20180831211245-f60e5f99f081/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181105213840-e504f914a84b h1:tMmal9ZzeRWqWBgbwCDPBuFlWWRjzF5yD5acalTV70M=
golang.org/x/tools v0.0.0-20181105213840-e504f914a84b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
Expand Down
8 changes: 4 additions & 4 deletions internal/alb/ls/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,18 @@ func (controller *defaultController) newLSInstance(ctx context.Context, lbArn st

func (controller *defaultController) reconcileLSInstance(ctx context.Context, instance *elbv2.Listener, config listenerConfig) (*elbv2.Listener, error) {
if controller.LSInstanceNeedsModification(ctx, instance, config) {
if output, err := controller.cloud.ModifyListenerWithContext(ctx, &elbv2.ModifyListenerInput{
output, err := controller.cloud.ModifyListenerWithContext(ctx, &elbv2.ModifyListenerInput{
ListenerArn: instance.ListenerArn,
Port: config.Port,
Protocol: config.Protocol,
Certificates: config.Certificates,
SslPolicy: config.SslPolicy,
DefaultActions: config.DefaultActions,
}); err != nil {
})
if err != nil {
return instance, err
} else {
return output.Listeners[0], nil
}
return output.Listeners[0], nil
}
return instance, nil
}
Expand Down
6 changes: 2 additions & 4 deletions internal/alb/sg/lb_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package sg
import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/util/sets"

"github.com/kubernetes-sigs/aws-alb-ingress-controller/internal/albctx"

"github.com/aws/aws-sdk-go/service/elbv2"

"github.com/kubernetes-sigs/aws-alb-ingress-controller/internal/albctx"
"github.com/kubernetes-sigs/aws-alb-ingress-controller/internal/aws"
"k8s.io/apimachinery/pkg/util/sets"
)

// LbAttachment represents the desired SecurityGroups attached to Lb
Expand Down
8 changes: 4 additions & 4 deletions internal/alb/tg/targetgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (controller *defaultController) newTGInstance(ctx context.Context, name str

func (controller *defaultController) reconcileTGInstance(ctx context.Context, instance *elbv2.TargetGroup, serviceAnnos *annotations.Service) (*elbv2.TargetGroup, error) {
if controller.TGInstanceNeedsModification(ctx, instance, serviceAnnos) {
if output, err := controller.cloud.ModifyTargetGroupWithContext(ctx, &elbv2.ModifyTargetGroupInput{
output, err := controller.cloud.ModifyTargetGroupWithContext(ctx, &elbv2.ModifyTargetGroupInput{
TargetGroupArn: instance.TargetGroupArn,
HealthCheckPath: serviceAnnos.HealthCheck.Path,
HealthCheckIntervalSeconds: serviceAnnos.HealthCheck.IntervalSeconds,
Expand All @@ -131,11 +131,11 @@ func (controller *defaultController) reconcileTGInstance(ctx context.Context, in
Matcher: &elbv2.Matcher{HttpCode: serviceAnnos.TargetGroup.SuccessCodes},
HealthyThresholdCount: serviceAnnos.TargetGroup.HealthyThresholdCount,
UnhealthyThresholdCount: serviceAnnos.TargetGroup.UnhealthyThresholdCount,
}); err != nil {
})
if err != nil {
return instance, err
} else {
return output.TargetGroups[0], err
}
return output.TargetGroups[0], err
}
return instance, nil
}
Expand Down
8 changes: 4 additions & 4 deletions internal/albctx/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ var (
contextKeyLogger = contextKey("Logger")
)

type eventf func(string, string, string, ...interface{})
type Eventf func(string, string, string, ...interface{})

func missingEventf(eventType, reason, format string, vals ...interface{}) {
f := fmt.Sprintf("Event function missing. Type(%v) Reason(%v): %v", eventType, reason, format)
glog.Errorf(f, vals...)
}

func SetEventf(ctx context.Context, f eventf) context.Context {
func SetEventf(ctx context.Context, f Eventf) context.Context {
return context.WithValue(ctx, contextKeyEventf, f)
}

func GetEventf(ctx context.Context) eventf {
if f, ok := ctx.Value(contextKeyEventf).(eventf); ok {
func GetEventf(ctx context.Context) Eventf {
if f, ok := ctx.Value(contextKeyEventf).(Eventf); ok {
return f
}
return missingEventf
Expand Down
16 changes: 8 additions & 8 deletions internal/aws/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
)

const (
ManagedByKey = "ManagedBy"
ManagedByValue = "alb-ingress"
ManagedByKey = "ManagedBy"
ManagedByValue = "alb-ingress"

TagNameCluster = "kubernetes.io/cluster"

Expand Down Expand Up @@ -302,18 +302,18 @@ func (c *Cloud) GetVPC(id *string) (*ec2.Vpc, error) {
// instanceVPCIsValid ensures returned instance data has a valid VPC ID in the output
func instanceVPCIsValid(o *ec2.DescribeInstancesOutput) error {
if len(o.Reservations) < 1 {
return fmt.Errorf("When looking up VPC ID could not identify instance. Found %d reservations"+
" in AWS call. Should have found atleast 1.", len(o.Reservations))
return fmt.Errorf("when looking up VPC ID could not identify instance. Found %d reservations"+
" in AWS call. Should have found atleast 1", len(o.Reservations))
}
if len(o.Reservations[0].Instances) < 1 {
return fmt.Errorf("When looking up VPC ID could not identify instance. Found %d instances"+
" in AWS call. Should have found atleast 1.", len(o.Reservations))
return fmt.Errorf("when looking up VPC ID could not identify instance. Found %d instances"+
" in AWS call. Should have found atleast 1", len(o.Reservations))
}
if o.Reservations[0].Instances[0].VpcId == nil {
return fmt.Errorf("When looking up VPC ID could not instance returned had a nil value for VPC.")
return fmt.Errorf("when looking up VPC ID could not instance returned had a nil value for VPC")
}
if *o.Reservations[0].Instances[0].VpcId == "" {
return fmt.Errorf("When looking up VPC ID could not instance returned had an empty value for VPC.")
return fmt.Errorf("when looking up VPC ID could not instance returned had an empty value for VPC")
}

return nil
Expand Down
8 changes: 4 additions & 4 deletions internal/aws/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import (
"k8s.io/apiserver/pkg/server/healthz"
)

type AWSHealthChecker struct {
type HealthChecker struct {
Cloud CloudAPI
}

var _ healthz.HealthzChecker = (*AWSHealthChecker)(nil)
var _ healthz.HealthzChecker = (*HealthChecker)(nil)

func (c *AWSHealthChecker) Name() string {
func (c *HealthChecker) Name() string {
// TODO, can we rename it to, e.g. AWS? is there any dependencies on the name?
return "aws-alb-ingress-controller"
}

// TODO, validate the call health check frequency
func (c *AWSHealthChecker) Check(_ *http.Request) error {
func (c *HealthChecker) Check(_ *http.Request) error {
for _, fn := range []func() error{
c.Cloud.StatusACM(),
c.Cloud.StatusEC2(),
Expand Down
6 changes: 3 additions & 3 deletions internal/ingress/controller/config/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ func (config *Configuration) BindDynamicSettings(mgr manager.Manager, c controll
}
}
if config.VpcID == "" {
if vpcID, err := cloud.GetVPCID(); err != nil {
vpcID, err := cloud.GetVPCID()
if err != nil {
return err
} else {
config.VpcID = aws.StringValue(vpcID)
}
config.VpcID = aws.StringValue(vpcID)
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions internal/ingress/controller/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,12 @@ func (s *k8sStore) GetNodeInstanceID(node *corev1.Node) (string, error) {
return node.Spec.DoNotUse_ExternalID, nil
}

providerId := node.Spec.ProviderID
if providerId == "" {
providerID := node.Spec.ProviderID
if providerID == "" {
return "", fmt.Errorf("No providerID found for node %s", node.ObjectMeta.Name)
}

p := strings.Split(providerId, "/")
p := strings.Split(providerID, "/")
return p[len(p)-1], nil
}

Expand Down
7 changes: 2 additions & 5 deletions internal/ingress/metric/collectors/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,13 @@ func GatherAndCompare(c prometheus.Collector, expected string, metricNames []str
return nil
}

return fmt.Errorf(`
metric output does not match expectation; want:
return fmt.Errorf(`metric output does not match expectation; want:
'%s'
got:
'%s'
`, buf2.String(), buf1.String())
'%s'`, buf2.String(), buf1.String())
}
return nil
}
Expand Down

0 comments on commit 6c6ddee

Please sign in to comment.