Skip to content
Permalink
Browse files

Run golang-ci linter in travisci. Add golang-ci configuration

  • Loading branch information
Dean-Coakley committed Aug 26, 2019
1 parent c2d7bd9 commit 5d4c5ddc70c2a40e78c803d0000908bfb2e6b63f
@@ -0,0 +1,18 @@
linters-settings:
misspell:
locale: US

linters:
enable:
- goimports
- gosimple
- govet
- misspell
- gofmt
- unparam
- unconvert
- interfacer
- structcheck
- errcheck
disable-all: true

@@ -19,3 +19,5 @@ before_install:
wget https://${fossalocation}/${fossafile} && tar xzf ${fossafile}
&& ./fossa init
&& GO111MODULE=on FOSSA_API_KEY=${fossapush} ./fossa analyze -t kubernetes-ingress -b ${TRAVIS_BRANCH}; fi
- echo "Checking ingress controller for linting errors" && wget -O - -q ${golangci_lint} | sh -s v1.17.1
- export PATH="$PATH:./bin" && make lint
@@ -209,7 +209,7 @@ func (cnf *Configurator) updateJWKSecret(ingEx *IngressEx) string {

func (cnf *Configurator) addOrUpdateJWKSecret(secret *api_v1.Secret) string {
name := objectMetaToFileName(&secret.ObjectMeta)
data := []byte(secret.Data[JWTKeyKey])
data := secret.Data[JWTKeyKey]
return cnf.nginxManager.CreateSecret(name, data, nginx.JWKSecretFileMode)
}

@@ -123,8 +123,8 @@ func TestPathOrDefaultReturnActual(t *testing.T) {

func createExpectedConfigForCafeIngressEx() version1.IngressNginxConfig {
coffeeUpstream := version1.Upstream{
Name: "default-cafe-ingress-cafe.example.com-coffee-svc-80",
LBMethod: "random two least_conn",
Name: "default-cafe-ingress-cafe.example.com-coffee-svc-80",
LBMethod: "random two least_conn",
UpstreamZoneSize: "256k",
UpstreamServers: []version1.UpstreamServer{
{
@@ -137,8 +137,8 @@ func createExpectedConfigForCafeIngressEx() version1.IngressNginxConfig {
},
}
teaUpstream := version1.Upstream{
Name: "default-cafe-ingress-cafe.example.com-tea-svc-80",
LBMethod: "random two least_conn",
Name: "default-cafe-ingress-cafe.example.com-tea-svc-80",
LBMethod: "random two least_conn",
UpstreamZoneSize: "256k",
UpstreamServers: []version1.UpstreamServer{
{
@@ -478,8 +478,8 @@ func createMergeableCafeIngress() *MergeableIngresses {

func createExpectedConfigForMergeableCafeIngress() version1.IngressNginxConfig {
coffeeUpstream := version1.Upstream{
Name: "default-cafe-ingress-coffee-minion-cafe.example.com-coffee-svc-80",
LBMethod: "random two least_conn",
Name: "default-cafe-ingress-coffee-minion-cafe.example.com-coffee-svc-80",
LBMethod: "random two least_conn",
UpstreamZoneSize: "256k",
UpstreamServers: []version1.UpstreamServer{
{
@@ -492,8 +492,8 @@ func createExpectedConfigForMergeableCafeIngress() version1.IngressNginxConfig {
},
}
teaUpstream := version1.Upstream{
Name: "default-cafe-ingress-tea-minion-cafe.example.com-tea-svc-80",
LBMethod: "random two least_conn",
Name: "default-cafe-ingress-tea-minion-cafe.example.com-tea-svc-80",
LBMethod: "random two least_conn",
UpstreamZoneSize: "256k",
UpstreamServers: []version1.UpstreamServer{
{
@@ -17,12 +17,12 @@ type Ingress struct {

// Upstream describes an NGINX upstream.
type Upstream struct {
Name string
UpstreamServers []UpstreamServer
StickyCookie string
LBMethod string
Queue int64
QueueTimeout int64
Name string
UpstreamServers []UpstreamServer
StickyCookie string
LBMethod string
Queue int64
QueueTimeout int64
UpstreamZoneSize string
}

@@ -169,7 +169,7 @@ type MainConfig struct {
// We use it for services that have no endpoints.
func NewUpstreamWithDefaultServer(name string) Upstream {
return Upstream{
Name: name,
Name: name,
UpstreamZoneSize: "256k",
UpstreamServers: []UpstreamServer{
{
@@ -12,7 +12,7 @@ const nginxPlusIngressTmpl = "nginx-plus.ingress.tmpl"
const nginxPlusMainTmpl = "nginx-plus.tmpl"

var testUps = Upstream{
Name: "test",
Name: "test",
UpstreamZoneSize: "256k",
UpstreamServers: []UpstreamServer{
{
@@ -177,7 +177,7 @@ func GenerateExternalNameSvcKey(namespace string, service string) string {
func generateEndpointsForUpstream(namespace string, upstream conf_v1alpha1.Upstream, virtualServerEx *VirtualServerEx, isResolverConfigured bool, isPlus bool) []string {
endpointsKey := GenerateEndpointsKey(namespace, upstream.Service, upstream.Port)
externalNameSvcKey := GenerateExternalNameSvcKey(namespace, upstream.Service)
endpoints, _ := virtualServerEx.Endpoints[endpointsKey]
endpoints := virtualServerEx.Endpoints[endpointsKey]
if !isPlus && len(endpoints) == 0 {
return []string{nginx502Server}
}
@@ -1858,7 +1858,7 @@ func TestGenerateEndpointsForUpstream(t *testing.T) {
},
},
Endpoints: map[string][]string{
"test-namespace/test:80": []string{"example.com:80"},
"test-namespace/test:80": {"example.com:80"},
},
ExternalNameSvcs: map[string]bool{
"test-namespace/test": true,
@@ -1882,7 +1882,7 @@ func TestGenerateEndpointsForUpstream(t *testing.T) {
},
},
Endpoints: map[string][]string{
"test-namespace/test:80": []string{"example.com:80"},
"test-namespace/test:80": {"example.com:80"},
},
ExternalNameSvcs: map[string]bool{
"test-namespace/test": true,
@@ -1906,7 +1906,7 @@ func TestGenerateEndpointsForUpstream(t *testing.T) {
},
},
Endpoints: map[string][]string{
"test-namespace/test:8080": []string{"192.168.10.10:8080"},
"test-namespace/test:8080": {"192.168.10.10:8080"},
},
},
isPlus: false,
@@ -1399,7 +1399,7 @@ func (lbc *LoadBalancerController) createIngress(ing *extensions.Ingress) (*conf
if err != nil {
glog.V(3).Infof("Error getting service %v: %v", ing.Spec.Backend.ServiceName, err)
} else {
endps, external, err = lbc.getEndpointsForIngressBackend(ing.Spec.Backend, ing.Namespace, svc)
endps, external, err = lbc.getEndpointsForIngressBackend(ing.Spec.Backend, svc)
if err == nil && external && lbc.isNginxPlus {
ingEx.ExternalNameSvcs[svc.Name] = true
}
@@ -1436,7 +1436,7 @@ func (lbc *LoadBalancerController) createIngress(ing *extensions.Ingress) (*conf
if err != nil {
glog.V(3).Infof("Error getting service %v: %v", &path.Backend.ServiceName, err)
} else {
endps, external, err = lbc.getEndpointsForIngressBackend(&path.Backend, ing.Namespace, svc)
endps, external, err = lbc.getEndpointsForIngressBackend(&path.Backend, svc)
if err == nil && external && lbc.isNginxPlus {
ingEx.ExternalNameSvcs[svc.Name] = true
}
@@ -1593,15 +1593,15 @@ func (lbc *LoadBalancerController) getEndpointsForUpstream(namespace string, ups
ServicePort: intstr.FromInt(int(upstream.Port)),
}

endps, isExternal, err := lbc.getEndpointsForIngressBackend(backend, namespace, svc)
endps, isExternal, err := lbc.getEndpointsForIngressBackend(backend, svc)
if err != nil {
return nil, false, fmt.Errorf("Error retrieving endpoints for the service %v: %v", upstream.Service, err)
}

return endps, isExternal, err
}

func (lbc *LoadBalancerController) getPodsForIngressBackend(svc *api_v1.Service, namespace string) *api_v1.PodList {
func (lbc *LoadBalancerController) getPodsForIngressBackend(svc *api_v1.Service) *api_v1.PodList {
pods, err := lbc.client.CoreV1().Pods(svc.Namespace).List(meta_v1.ListOptions{LabelSelector: labels.Set(svc.Spec.Selector).String()})
if err != nil {
glog.V(3).Infof("Error fetching pods for namespace %v: %v", svc.Namespace, err)
@@ -1620,7 +1620,7 @@ func (lbc *LoadBalancerController) getHealthChecksForIngressBackend(backend *ext
if svcPort == nil {
return nil
}
pods := lbc.getPodsForIngressBackend(svc, namespace)
pods := lbc.getPodsForIngressBackend(svc)
if pods == nil {
return nil
}
@@ -1658,20 +1658,20 @@ func compareContainerPortAndServicePort(containerPort api_v1.ContainerPort, svcP
return false
}

func (lbc *LoadBalancerController) getExternalEndpointsForIngressBackend(backend *extensions.IngressBackend, namespace string, svc *api_v1.Service) []string {
func (lbc *LoadBalancerController) getExternalEndpointsForIngressBackend(backend *extensions.IngressBackend, svc *api_v1.Service) []string {
endpoint := fmt.Sprintf("%s:%d", svc.Spec.ExternalName, int32(backend.ServicePort.IntValue()))
endpoints := []string{endpoint}
return endpoints
}

func (lbc *LoadBalancerController) getEndpointsForIngressBackend(backend *extensions.IngressBackend, namespace string, svc *api_v1.Service) (result []string, isExternal bool, err error) {
func (lbc *LoadBalancerController) getEndpointsForIngressBackend(backend *extensions.IngressBackend, svc *api_v1.Service) (result []string, isExternal bool, err error) {
endps, err := lbc.endpointLister.GetServiceEndpoints(svc)
if err != nil {
if svc.Spec.Type == api_v1.ServiceTypeExternalName {
if !lbc.isNginxPlus {
return nil, false, fmt.Errorf("Type ExternalName Services feature is only available in NGINX Plus")
}
result = lbc.getExternalEndpointsForIngressBackend(backend, namespace, svc)
result = lbc.getExternalEndpointsForIngressBackend(backend, svc)
return result, true, nil
}
glog.V(3).Infof("Error getting endpoints for service %s from the cache: %v", svc.Name, err)
@@ -3,7 +3,7 @@ package k8s
import (
"testing"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)

@@ -7,7 +7,7 @@ import (

"github.com/golang/glog"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
@@ -3,7 +3,7 @@ package k8s
import (
"fmt"

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

// JWTKeyKey is the key of the data field of a Secret where the JWK must be stored.
@@ -258,7 +258,7 @@ func TestValidateUpstreamsFails(t *testing.T) {
},
},
expectedUpstreamNames: map[string]sets.Empty{
"upstream1": sets.Empty{},
"upstream1": {},
},
msg: "invalid next upstream syntax",
},
@@ -274,7 +274,7 @@ func TestValidateUpstreamsFails(t *testing.T) {
},
},
expectedUpstreamNames: map[string]sets.Empty{
"upstream1": sets.Empty{},
"upstream1": {},
},
msg: "invalid upstream timeout value",
},
@@ -290,7 +290,7 @@ func TestValidateUpstreamsFails(t *testing.T) {
},
},
expectedUpstreamNames: map[string]sets.Empty{
"upstream1": sets.Empty{},
"upstream1": {},
},
msg: "invalid upstream tries value",
},
@@ -1822,7 +1822,6 @@ func TestValidateStatusMatchFails(t *testing.T) {
func TestValidateHeader(t *testing.T) {
tests := []struct {
header v1alpha1.Header
msg string
}{
{
header: v1alpha1.Header{

0 comments on commit 5d4c5dd

Please sign in to comment.
You can’t perform that action at this time.