Skip to content

Commit

Permalink
Upgrade to golanci-lint v1.18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatur authored and traefiker committed Sep 16, 2019
1 parent 8e424d4 commit cd3692f
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 35 deletions.
11 changes: 10 additions & 1 deletion .golangci.toml
Expand Up @@ -33,5 +33,14 @@
"gochecknoinits",
"gochecknoglobals",
"scopelint",
"typecheck", # v1.17.1 and Go1.13 => bug
"funlen",
]

[issues]
exclude-use-default = false
max-per-linter = 0
max-same-issues = 0
exclude = [
"Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*printf?|os\\.(Un)?Setenv). is not checked",
"should have a package comment, unless it's in another file for this package",
]
3 changes: 3 additions & 0 deletions Dockerfile
Expand Up @@ -21,6 +21,9 @@ WORKDIR /go/src/github.com/containous/maesh
# Download goreleaser binary to bin folder in $GOPATH
RUN curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh

# Download golangci-lint binary to bin folder in $GOPATH
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.18.0

ENV GO111MODULE on
COPY go.mod go.sum ./
RUN go mod download
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Expand Up @@ -6,7 +6,6 @@ BINARY_NAME = maesh
DIST_DIR = $(CURDIR)/dist
DIST_DIR_MAESH = $(DIST_DIR)/$(BINARY_NAME)
PROJECT ?= github.com/containous/$(BINARY_NAME)
GOLANGCI_LINTER_VERSION = v1.17.1

TAG_NAME ?= $(shell git tag -l --contains HEAD)
SHA := $(shell git rev-parse --short HEAD)
Expand Down Expand Up @@ -64,7 +63,12 @@ test: $(DIST_DIR)
docker build --tag "$(DOCKER_IMAGE_NAME):test" --target maker --build-arg="MAKE_TARGET=local-test" $(CURDIR)/

check: $(DIST_DIR) helm-lint
docker run -t --rm -v $(CURDIR):/go/src/$(PROJECT) -w /go/src/$(PROJECT) -e GO111MODULE golangci/golangci-lint:$(GOLANGCI_LINTER_VERSION) golangci-lint run --config .golangci.toml
docker build --tag "$(DOCKER_IMAGE_NAME):check" --target base-image $(CURDIR)/
docker run --rm \
-v $(CURDIR):/go/src/$(PROJECT) \
-w /go/src/$(PROJECT) \
-e GO111MODULE \
"$(DOCKER_IMAGE_NAME):check" golangci-lint run --config .golangci.toml

publish-images: build
seihon publish -v "$(VERSION)" -v "latest" --image-name ${DOCKER_IMAGE_NAME} --dry-run=false --base-runtime-image=alpine:3.10
Expand Down
15 changes: 1 addition & 14 deletions cmd/configuration.go
Expand Up @@ -34,24 +34,11 @@ type PrepareConfig struct {
Namespace string `description:"The namespace that maesh is installed in." export:"true"`
}

// NewPrepareConfig creates PrepareConfig.
func NewPrepareConfig() *PrepareConfig {
return &PrepareConfig{
KubeConfig: os.Getenv("KUBECONFIG"),
Debug: false,
Namespace: "maesh",
}
}

// CheckConfig .
type CheckConfig struct {
KubeConfig string `description:"Path to a kubeconfig. Only required if out-of-cluster." export:"true"`
MasterURL string `description:"The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster." export:"true"`
Debug bool `description:"Debug mode" export:"true"`
}

func NewCheckConfig() *CheckConfig {
return &CheckConfig{
KubeConfig: os.Getenv("KUBECONFIG"),
Debug: false,
}
}
2 changes: 2 additions & 0 deletions integration/try/try.go
Expand Up @@ -22,10 +22,12 @@ const (
CITimeoutMultiplier = 3
)

// Try holds try configuration.
type Try struct {
client *k8s.ClientWrapper
}

// NewTry creates a new try.
func NewTry(client *k8s.ClientWrapper) *Try {
return &Try{client: client}
}
Expand Down
7 changes: 4 additions & 3 deletions internal/controller/controller.go
Expand Up @@ -25,6 +25,7 @@ import (
"k8s.io/client-go/util/workqueue"
)

// Controller hold controller configuration.
type Controller struct {
clients *k8s.ClientWrapper
kubernetesFactory informers.SharedInformerFactory
Expand All @@ -47,7 +48,7 @@ type Controller struct {
tcpStateTable *k8s.State
}

// New is used to build the informers and other required components of the mesh controller,
// NewMeshController is used to build the informers and other required components of the mesh controller,
// and return an initialized mesh controller object.
func NewMeshController(clients *k8s.ClientWrapper, smiEnabled bool, defaultMode string, meshNamespace string) *Controller {
ignored := k8s.NewIgnored(meshNamespace)
Expand Down Expand Up @@ -504,7 +505,7 @@ func (c *Controller) loadTCPStateTable() (*k8s.State, error) {
result = &k8s.State{Table: make(map[int]*k8s.ServiceWithPort)}
}

configMap, exists, err := c.clients.GetConfigMap(c.meshNamespace, k8s.TCPStateConfigmapName)
configMap, exists, err := c.clients.GetConfigMap(c.meshNamespace, k8s.TCPStateConfigMapName)
if err != nil {
return result, err
}
Expand Down Expand Up @@ -562,7 +563,7 @@ func (c *Controller) getTCPPortFromState(serviceName, serviceNamespace string, s
}

func (c *Controller) saveTCPStateTable() error {
configMap, exists, err := c.clients.GetConfigMap(c.meshNamespace, k8s.TCPStateConfigmapName)
configMap, exists, err := c.clients.GetConfigMap(c.meshNamespace, k8s.TCPStateConfigMapName)
if err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions internal/controller/handler.go
Expand Up @@ -14,6 +14,7 @@ type Handler struct {
messageQueue workqueue.RateLimitingInterface
}

// NewHandler creates a handler.
func NewHandler(ignored k8s.IgnoreWrapper, messageQueue workqueue.RateLimitingInterface) *Handler {
h := &Handler{
ignored: ignored,
Expand All @@ -34,6 +35,7 @@ func (h *Handler) Init() error {
return nil
}

// OnAdd executed when an object is added.
func (h *Handler) OnAdd(obj interface{}) {
// convert the resource object into a key (in this case
// we are just doing it in the format of 'namespace/name')
Expand All @@ -54,6 +56,7 @@ func (h *Handler) OnAdd(obj interface{}) {
}
}

// OnUpdate executed when an object is updated.
func (h *Handler) OnUpdate(oldObj, newObj interface{}) {
key, err := cache.MetaNamespaceKeyFunc(newObj)
if err != nil {
Expand All @@ -71,6 +74,7 @@ func (h *Handler) OnUpdate(oldObj, newObj interface{}) {
}
}

// OnDelete executed when an object is deleted.
func (h *Handler) OnDelete(obj interface{}) {
// DeletionHandlingMetaNamsespaceKeyFunc is a helper function that allows
// us to check the DeletedFinalStateUnknown existence in the event that
Expand Down
7 changes: 4 additions & 3 deletions internal/deployer/deployer.go
Expand Up @@ -197,17 +197,18 @@ func (d *Deployer) deployAPI(m message.Deploy) bool {
}

url := fmt.Sprintf("http://%s:8080/api/providers/rest", m.PodIP)
client := &http.Client{Timeout: 10 * time.Second}

req, err := http.NewRequest(http.MethodPut, url, bytes.NewBuffer(b))
if err != nil {
log.Errorf("Could not create request: %v", err)
return false
}

client := &http.Client{Timeout: 10 * time.Second}
resp, err := client.Do(req)
if resp != nil {
defer resp.Body.Close()
_, bodyErr := ioutil.ReadAll(resp.Body)
if bodyErr != nil {
if _, bodyErr := ioutil.ReadAll(resp.Body); bodyErr != nil {
log.Errorf("Unable to read response body: %v", bodyErr)
return false
}
Expand Down
7 changes: 7 additions & 0 deletions internal/k8s/client.go
Expand Up @@ -46,6 +46,7 @@ type ClusterInitClient interface {
VerifyCluster() error
}

// CoreV1Client CoreV1 client.
type CoreV1Client interface {
GetService(namespace, name string) (*corev1.Service, bool, error)
GetServices(namespace string) ([]*corev1.Service, error)
Expand All @@ -64,25 +65,30 @@ type CoreV1Client interface {
CreateConfigMap(configMap *corev1.ConfigMap) (*corev1.ConfigMap, error)
}

// AppsV1Client AppsV1 client.
type AppsV1Client interface {
GetDeployment(namespace, name string) (*appsv1.Deployment, bool, error)
UpdateDeployment(deployment *appsv1.Deployment) (*appsv1.Deployment, error)
}

// SMIClient SMI client.
type SMIClient interface {
SMIAccessV1Alpha1Client
SMISpecsV1Alpha1Client
SMISplitV1Alpha1Client
}

// SMIAccessV1Alpha1Client SMI Access v1Alpha client.
type SMIAccessV1Alpha1Client interface {
GetTrafficTargets() ([]*smiAccessv1alpha1.TrafficTarget, error)
}

// SMISpecsV1Alpha1Client SMI Specs v1Alpha client.
type SMISpecsV1Alpha1Client interface {
GetHTTPRouteGroup(namespace, name string) (*smiSpecsv1alpha1.HTTPRouteGroup, bool, error)
}

// SMISplitV1Alpha1Client SMI Split v1Alpha client.
type SMISplitV1Alpha1Client interface {
GetTrafficSplits() ([]*smiSplitv1alpha1.TrafficSplit, error)
}
Expand Down Expand Up @@ -427,6 +433,7 @@ func (w *ClientWrapper) GetPod(namespace, name string) (*corev1.Pod, bool, error
return pod, exists, err
}

// ListPodWithOptions retrieves pods from the specified namespace.
func (w *ClientWrapper) ListPodWithOptions(namespace string, options metav1.ListOptions) (*corev1.PodList, error) {
return w.KubeClient.CoreV1().Pods(namespace).List(options)
}
Expand Down

0 comments on commit cd3692f

Please sign in to comment.