Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
Update all the things
Browse files Browse the repository at this point in the history
* Update dependencies
* Use latest go on travis
* Switch to golangci-linter
  • Loading branch information
errm committed Feb 26, 2019
1 parent d83248e commit c51605a
Show file tree
Hide file tree
Showing 20 changed files with 617 additions and 88 deletions.
13 changes: 13 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
linters-settings:
lll:
line-length: 141

linters:
enable-all: true
disable:
- prealloc
- gochecknoglobals
- dupl

service:
golangci-lint-version: 1.15.x # use the fixed version to not introduce new linters unexpectedly
4 changes: 0 additions & 4 deletions .gometalinter.json

This file was deleted.

4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
language: go

go:
- "1.10.x"
- "1.11.x"

services:
- docker

before_script: bash .travis/setup.sh

script: make
script: make test ekstrap

after_success:
- bash <(curl -s https://codecov.io/bash)
Expand Down
4 changes: 2 additions & 2 deletions .travis/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

set -euo pipefail

GORELEASER_VERSION="0.79.0"
GORELEASER_CHECKSUM="8b3f62f582bddde2a29b1d33baaf92b66281312c2fd8a3d38ad2bac8e35c14dd"
GORELEASER_VERSION="0.98.0"
GORELEASER_CHECKSUM="85c3e4027e5aed1b5af6d75ed7fb1cb595a963335653ef3e6b8df3497e351755"

export DEBIAN_FRONTEND=noninteractive

Expand Down
2 changes: 0 additions & 2 deletions .travis/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ set -euo pipefail

openssl aes-256-cbc -K $encrypted_189aefeda93d_key -iv $encrypted_189aefeda93d_iv -in .travis/ekstrap.asc.enc -out .travis/ekstrap.asc -d
gpg --import .travis/ekstrap.asc
make install-linter
go get -u github.com/gobuffalo/packr/...
13 changes: 6 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ GOBUILD=$(GOCMD) build -ldflags="-s -w"
GOTEST=$(GOCMD) test
UPX=upx -9
BINARY_NAME=ekstrap
WORKDIR=/go/src/github.com/errm/ekstrap
PWD=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

GOMETALINTER = gometalinter ./...
GORELEASER = goreleaser release --rm-dist --debug

all: test lint $(BINARY_NAME)
Expand All @@ -18,21 +17,21 @@ compress: $(BINARY_NAME)
$(UPX) $(BINARY_NAME)
test: deps generate
$(GOTEST) -coverprofile=coverage.txt -covermode=count ./...
install-linter:
$(GOCMD) get -u github.com/alecthomas/gometalinter
$(GOMETALINTER) --install
lint: deps
$(GOMETALINTER)
lint:
command -v golangci-lint || GO111MODULE=off $(GOCMD) get -u github.com/golangci/golangci-lint/cmd/golangci-lint
golangci-lint run
release: generate .goreleaser.yml
$(GORELEASER)
snapshot: .goreleaser.yml
$(GORELEASER) --snapshot
install: $(BINARY_NAME)
install -m755 $(BINARY_NAME) /usr/sbin
generate:
command -v packr2 || $(GOCMD) get github.com/gobuffalo/packr/v2/packr2@v2.0.2
$(GOCMD) generate
clean:
$(GOCMD) clean
packr2 clean
rm -rf ./dist/
deps:
$(GOCMD) build -v ./...
Expand Down
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,14 @@ Will run the tests and build a binary

### Linting

We run [some](.gometalinter.json) linting processes.
We run some linting processes on [GolangCI](https://golangci.com)

To run locally:

* First install gometalinter: `make install-linter`.
* Then run: `make lint`
To run locally: `make lint`

## Dependencies

To build ekstrap you need [go](https://golang.org/)

Dependencies are checked into the vendor folder so you can build the project without any extra tools,
but if you need to change or update them you will need to install [dep](https://golang.github.io/dep/).

If you want a tiny binary, install [upx](https://upx.github.io/) and run the `make compress` task.

ekstrap currently only works with systemd, if you want us to support another init system please comment here https://github.com/errm/ekstrap/issues/28.
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ module github.com/errm/ekstrap

require (
github.com/aws/aws-sdk-go v1.14.3
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7
github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d
github.com/dchest/safefile v0.0.0-20151022103144-855e8d98f185
github.com/go-ini/ini v1.37.0
github.com/gobuffalo/packr v1.13.3
github.com/gobuffalo/packr/v2 v2.0.2
github.com/godbus/dbus v4.1.0+incompatible
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8
github.com/pkg/errors v0.8.0
github.com/pkg/errors v0.8.1
golang.org/x/sys v0.0.0-20190116161447-11f53e031339 // indirect
)
528 changes: 528 additions & 0 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

package main

//go:generate packr
//go:generate packr2

import (
"log"
Expand Down
5 changes: 4 additions & 1 deletion pkg/backoff/backoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ limitations under the License.
package backoff_test

import (
"github.com/errm/ekstrap/pkg/backoff"
"testing"
"time"

"github.com/errm/ekstrap/pkg/backoff"
)

func TestEmptyBackoff(t *testing.T) {
Expand All @@ -37,10 +38,12 @@ func TestEmptyBackoff(t *testing.T) {
func TestJitteredBackoff(t *testing.T) {
seq := backoff.Backoff{Seq: []int{1, 2, 4, 8}}

//nolint:staticcheck
if seq.Duration(1) == seq.Duration(1) {
t.Error("Jitter should ensure calls are not equal")
}

//nolint:staticcheck
if seq.Duration(4) == seq.Duration(4) {
t.Error("Jitter should ensure calls are not equal")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/eks/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ func Cluster(svc eksiface.EKSAPI, name string) (*eks.Cluster, error) {
tries++
continue
}
return nil, fmt.Errorf("Cannot use the EKS cluster: %s, because it is %s", name, *cluster.Status)
return nil, fmt.Errorf("cannot use the EKS cluster: %s, because it is %s", name, *cluster.Status)
}
}
7 changes: 4 additions & 3 deletions pkg/eks/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ import (
"github.com/aws/aws-sdk-go/service/eks/eksiface"
)

func init() {
func disableBackoff() {
// An empty backoff just returns 0 all the time so the tests run fast
b = backoff.Backoff{}
}

func TestCluster(t *testing.T) {
disableBackoff()
activeStatus := eks.ClusterStatusActive
activeCluster := &eks.Cluster{Status: &activeStatus}
deletingStatus := eks.ClusterStatusDeleting
Expand Down Expand Up @@ -60,13 +61,13 @@ func TestCluster(t *testing.T) {
clusters: []*eks.Cluster{deletingCluster},
errors: []error{nil},
expected: nil,
expectedError: errors.New("Cannot use the EKS cluster: cluster-name, because it is DELETING"),
expectedError: errors.New("cannot use the EKS cluster: cluster-name, because it is DELETING"),
},
{
clusters: []*eks.Cluster{failedCluster},
errors: []error{nil},
expected: nil,
expectedError: errors.New("Cannot use the EKS cluster: cluster-name, because it is FAILED"),
expectedError: errors.New("cannot use the EKS cluster: cluster-name, because it is FAILED"),
},
{
clusters: []*eks.Cluster{creatingCluster, activeCluster},
Expand Down
3 changes: 2 additions & 1 deletion pkg/file/atomic.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ limitations under the License.
package file

import (
"github.com/dchest/safefile"
"io"
"log"
"os"
"os/exec"
"path/filepath"
"syscall"

"github.com/dchest/safefile"
)

// Atomic exposes an interface to atomicly write config files to the filesystem
Expand Down
3 changes: 2 additions & 1 deletion pkg/file/atomic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ package file_test

import (
"fmt"
pkg "github.com/errm/ekstrap/pkg/file"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
"time"

pkg "github.com/errm/ekstrap/pkg/file"
)

var file = &pkg.Atomic{}
Expand Down
42 changes: 20 additions & 22 deletions pkg/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ import (
"github.com/aws/aws-sdk-go/service/ec2/ec2iface"
)

func init() {
var use1 = "us-east-1"
var usw2 = "us-west-2"

func disableBackoff() {
// An empty backoff just returns 0 all the time so the tests run fast
b = backoff.Backoff{}
}

func TestNewNode(t *testing.T) {
disableBackoff()
e := &mockEC2{
tags: [][]*ec2.Tag{
{},
Expand All @@ -46,8 +50,7 @@ func TestNewNode(t *testing.T) {
"instance-id": "1234",
},
}
region := "us-east-1"
node, err := New(e, metadata, &region)
node, err := New(e, metadata, &use1)
if err != nil {
t.Errorf("unexpected error: %s", err)
}
Expand All @@ -60,12 +63,13 @@ func TestNewNode(t *testing.T) {
t.Error("Expected returned node to have cluster-name")
}

if node.Region != region {
t.Errorf("Expected %s, to eq %s", node.Region, region)
if node.Region != use1 {
t.Errorf("Expected %s, to eq %s", node.Region, use1)
}
}

func TestNodeLabels(t *testing.T) {
disableBackoff()
e := &mockEC2{
tags: [][]*ec2.Tag{
{},
Expand All @@ -81,8 +85,7 @@ func TestNodeLabels(t *testing.T) {
"instance-id": "1234",
},
}
region := "us-east-1"
node, err := New(e, metadata, &region)
node, err := New(e, metadata, &use1)
if err != nil {
t.Errorf("unexpected error: %s", err)
}
Expand All @@ -107,7 +110,7 @@ func TestNodeLabels(t *testing.T) {
},
instanceLifecycle: ec2.InstanceLifecycleTypeSpot,
}
node, err = New(e, metadata, &region)
node, err = New(e, metadata, &use1)
if err != nil {
t.Errorf("unexpected error: %s", err)
}
Expand All @@ -123,6 +126,7 @@ func TestNodeLabels(t *testing.T) {
}

func TestNodeTaints(t *testing.T) {
disableBackoff()
e := &mockEC2{
tags: [][]*ec2.Tag{
{},
Expand All @@ -140,8 +144,7 @@ func TestNodeTaints(t *testing.T) {
"instance-id": "1234",
},
}
region := "us-east-1"
node, err := New(e, metadata, &region)
node, err := New(e, metadata, &use1)
if err != nil {
t.Errorf("unexpected error: %s", err)
}
Expand All @@ -162,8 +165,7 @@ func TestClusterDNS(t *testing.T) {
{tag("kubernetes.io/cluster/cluster-name", "owned")},
},
}
region := "us-east-1"
node, err := New(e, mockMetadata{}, &region)
node, err := New(e, mockMetadata{}, &use1)

if err != nil {
t.Errorf("unexpected error: %s", err)
Expand All @@ -179,7 +181,7 @@ func TestClusterDNS(t *testing.T) {
{tag("kubernetes.io/cluster/cluster-name", "owned")},
},
}
node, err = New(e, mockMetadata{}, &region)
node, err = New(e, mockMetadata{}, &use1)

if err != nil {
t.Errorf("unexpected error: %s", err)
Expand All @@ -197,8 +199,7 @@ func TestNewErrors(t *testing.T) {
e := &mockEC2{err: ec2Error}
metadata := mockMetadata{err: metadataError}

region := "us-east-1"
_, err := New(e, metadata, &region)
_, err := New(e, metadata, &use1)
if err != metadataError {
t.Errorf("expected error: %s to be %s", err, metadataError)
}
Expand All @@ -209,7 +210,7 @@ func TestNewErrors(t *testing.T) {
},
}

_, err = New(e, metadata, &region)
_, err = New(e, metadata, &use1)
if err != ec2Error {
t.Errorf("expected error: %s to be %s", err, ec2Error)
}
Expand Down Expand Up @@ -293,8 +294,7 @@ func TestMaxPods(t *testing.T) {
"instance-id": "1234",
},
}
region := "us-west-2"
node, err := New(e, metadata, &region)
node, err := New(e, metadata, &usw2)
if err != nil {
t.Errorf("unexpected error: %s", err)
}
Expand Down Expand Up @@ -369,8 +369,7 @@ func TestReservedCPU(t *testing.T) {
"instance-id": "1234",
},
}
region := "us-west-2"
node, err := New(e, metadata, &region)
node, err := New(e, metadata, &usw2)
if err != nil {
t.Errorf("unexpected error: %s", err)
}
Expand Down Expand Up @@ -440,8 +439,7 @@ func TestMemory(t *testing.T) {
"instance-id": "1234",
},
}
region := "us-west-2"
node, err := New(e, metadata, &region)
node, err := New(e, metadata, &usw2)
if err != nil {
t.Errorf("unexpected error: %s", err)
}
Expand Down
Loading

0 comments on commit c51605a

Please sign in to comment.