Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable lint in Travis #186

Merged
merged 1 commit into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
sudo: false
os: linux
distro: xenial
language: go

go_import_path: github.com/asobti/kube-monkey

go:
- "1.12.x"
- "1.13.x"
Expand All @@ -11,10 +14,10 @@ git:
depth: 1

env:
- GOLANGCI_RELEASE="v1.4.1"
- GOLANGCI_RELEASE="v1.26.0"

script:
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s ${GOLANGCI_RELEASE}
- make
- make test lint
# See https://github.com/asobti/kube-monkey/issues/120
# - .travis/check_workspace.sh
6 changes: 0 additions & 6 deletions chaos/chaos.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,6 @@ func (c *Chaos) getKillValue(clientset kube.Interface) (int, error) {
return killValue, nil
}

// Redundant for DeleteRandomPods(clientset,1) but DeleteRandomPod is faster
// Terminates one random pod
func (c *Chaos) terminatePod(clientset kube.Interface) error {
return c.Victim().DeleteRandomPod(clientset)
}

// NewResult creates a ChaosResult instance
func (c *Chaos) NewResult(e error) *Result {
return &Result{
Expand Down
3 changes: 2 additions & 1 deletion chaos/chaos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package chaos

import (
"errors"
"testing"

"github.com/asobti/kube-monkey/config"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"
"testing"

kube "k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/fake"
Expand Down
8 changes: 4 additions & 4 deletions victims/factory/daemonsets/daemonsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
"github.com/asobti/kube-monkey/config"
"github.com/asobti/kube-monkey/victims"

"k8s.io/api/apps/v1"
appsv1 "k8s.io/api/apps/v1"
)

type DaemonSet struct {
*victims.VictimBase
}

// New creates a new instance of DaemonSet
func New(dep *v1.DaemonSet) (*DaemonSet, error) {
func New(dep *appsv1.DaemonSet) (*DaemonSet, error) {
ident, err := identifier(dep)
if err != nil {
return nil, err
Expand All @@ -34,7 +34,7 @@ func New(dep *v1.DaemonSet) (*DaemonSet, error) {
// This label should be unique to a DaemonSet, and is used to
// identify the pods that belong to this DaemonSet, as pods
// inherit labels from the DaemonSet
func identifier(kubekind *v1.DaemonSet) (string, error) {
func identifier(kubekind *appsv1.DaemonSet) (string, error) {
identifier, ok := kubekind.Labels[config.IdentLabelKey]
if !ok {
return "", fmt.Errorf("%T %s does not have %s label", kubekind, kubekind.Name, config.IdentLabelKey)
Expand All @@ -44,7 +44,7 @@ func identifier(kubekind *v1.DaemonSet) (string, error) {

// Read the mean-time-between-failures value defined by the DaemonSet
// in the label defined by config.MtbfLabelKey
func meanTimeBetweenFailures(kubekind *v1.DaemonSet) (int, error) {
func meanTimeBetweenFailures(kubekind *appsv1.DaemonSet) (int, error) {
mtbf, ok := kubekind.Labels[config.MtbfLabelKey]
if !ok {
return -1, fmt.Errorf("%T %s does not have %s label", kubekind, kubekind.Name, config.MtbfLabelKey)
Expand Down
6 changes: 3 additions & 3 deletions victims/factory/daemonsets/daemonsets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/asobti/kube-monkey/config"
"github.com/stretchr/testify/assert"
"k8s.io/api/apps/v1"
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -15,9 +15,9 @@ const (
NAMESPACE = metav1.NamespaceDefault
)

func newDaemonSet(name string, labels map[string]string) v1.DaemonSet {
func newDaemonSet(name string, labels map[string]string) appsv1.DaemonSet {

return v1.DaemonSet{
return appsv1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: NAMESPACE,
Expand Down
8 changes: 4 additions & 4 deletions victims/factory/deployments/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
"github.com/asobti/kube-monkey/config"
"github.com/asobti/kube-monkey/victims"

"k8s.io/api/apps/v1"
appsv1 "k8s.io/api/apps/v1"
)

type Deployment struct {
*victims.VictimBase
}

// New creates a new instance of Deployment
func New(dep *v1.Deployment) (*Deployment, error) {
func New(dep *appsv1.Deployment) (*Deployment, error) {
ident, err := identifier(dep)
if err != nil {
return nil, err
Expand All @@ -34,7 +34,7 @@ func New(dep *v1.Deployment) (*Deployment, error) {
// This label should be unique to a deployment, and is used to
// identify the pods that belong to this deployment, as pods
// inherit labels from the Deployment
func identifier(kubekind *v1.Deployment) (string, error) {
func identifier(kubekind *appsv1.Deployment) (string, error) {
identifier, ok := kubekind.Labels[config.IdentLabelKey]
if !ok {
return "", fmt.Errorf("%T %s does not have %s label", kubekind, kubekind.Name, config.IdentLabelKey)
Expand All @@ -44,7 +44,7 @@ func identifier(kubekind *v1.Deployment) (string, error) {

// Read the mean-time-between-failures value defined by the Deployment
// in the label defined by config.MtbfLabelKey
func meanTimeBetweenFailures(kubekind *v1.Deployment) (int, error) {
func meanTimeBetweenFailures(kubekind *appsv1.Deployment) (int, error) {
mtbf, ok := kubekind.Labels[config.MtbfLabelKey]
if !ok {
return -1, fmt.Errorf("%T %s does not have %s label", kubekind, kubekind.Name, config.MtbfLabelKey)
Expand Down
6 changes: 3 additions & 3 deletions victims/factory/deployments/deployments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/asobti/kube-monkey/config"
"github.com/stretchr/testify/assert"
"k8s.io/api/apps/v1"
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -15,9 +15,9 @@ const (
NAMESPACE = metav1.NamespaceDefault
)

func newDeployment(name string, labels map[string]string) v1.Deployment {
func newDeployment(name string, labels map[string]string) appsv1.Deployment {

return v1.Deployment{
return appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: NAMESPACE,
Expand Down
6 changes: 3 additions & 3 deletions victims/factory/statefulsets/statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/asobti/kube-monkey/config"
"github.com/stretchr/testify/assert"
"k8s.io/api/apps/v1"
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -15,9 +15,9 @@ const (
NAMESPACE = metav1.NamespaceDefault
)

func newStatefulSet(name string, labels map[string]string) v1.StatefulSet {
func newStatefulSet(name string, labels map[string]string) appsv1.StatefulSet {

return v1.StatefulSet{
return appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: NAMESPACE,
Expand Down
8 changes: 4 additions & 4 deletions victims/factory/statefulsets/statefulsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
"github.com/asobti/kube-monkey/config"
"github.com/asobti/kube-monkey/victims"

"k8s.io/api/apps/v1"
corev1 "k8s.io/api/apps/v1"
)

type StatefulSet struct {
*victims.VictimBase
}

// New creates a new instance of StatefulSet
func New(ss *v1.StatefulSet) (*StatefulSet, error) {
func New(ss *corev1.StatefulSet) (*StatefulSet, error) {
ident, err := identifier(ss)
if err != nil {
return nil, err
Expand All @@ -34,7 +34,7 @@ func New(ss *v1.StatefulSet) (*StatefulSet, error) {
// This label should be unique to a statefulset, and is used to
// identify the pods that belong to this statefulset, as pods
// inherit labels from the StatefulSet
func identifier(kubekind *v1.StatefulSet) (string, error) {
func identifier(kubekind *corev1.StatefulSet) (string, error) {
identifier, ok := kubekind.Labels[config.IdentLabelKey]
if !ok {
return "", fmt.Errorf("%T %s does not have %s label", kubekind, kubekind.Name, config.IdentLabelKey)
Expand All @@ -44,7 +44,7 @@ func identifier(kubekind *v1.StatefulSet) (string, error) {

// Read the mean-time-between-failures value defined by the StatefulSet
// in the label defined by config.MtbfLabelKey
func meanTimeBetweenFailures(kubekind *v1.StatefulSet) (int, error) {
func meanTimeBetweenFailures(kubekind *corev1.StatefulSet) (int, error) {
mtbf, ok := kubekind.Labels[config.MtbfLabelKey]
if !ok {
return -1, fmt.Errorf("%T %s does not have %s label", kubekind, kubekind.Name, config.MtbfLabelKey)
Expand Down
14 changes: 7 additions & 7 deletions victims/victims.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

kube "k8s.io/client-go/kubernetes"

"k8s.io/api/core/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
Expand Down Expand Up @@ -45,8 +45,8 @@ type VictimSpecificAPICalls interface {

type VictimAPICalls interface {
// Exposed Api Calls
RunningPods(kube.Interface) ([]v1.Pod, error)
Pods(kube.Interface) ([]v1.Pod, error)
RunningPods(kube.Interface) ([]corev1.Pod, error)
Pods(kube.Interface) ([]corev1.Pod, error)
DeletePod(kube.Interface, string) error
DeleteRandomPod(kube.Interface) error // Deprecated, but faster than DeleteRandomPods for single pod termination
DeleteRandomPods(kube.Interface, int) error
Expand Down Expand Up @@ -95,14 +95,14 @@ func (v *VictimBase) Mtbf() int {
}

// RunningPods returns a list of running pods for the victim
func (v *VictimBase) RunningPods(clientset kube.Interface) (runningPods []v1.Pod, err error) {
func (v *VictimBase) RunningPods(clientset kube.Interface) (runningPods []corev1.Pod, err error) {
pods, err := v.Pods(clientset)
if err != nil {
return nil, err
}

for _, pod := range pods {
if pod.Status.Phase == v1.PodRunning {
if pod.Status.Phase == corev1.PodRunning {
runningPods = append(runningPods, pod)
}
}
Expand All @@ -111,7 +111,7 @@ func (v *VictimBase) RunningPods(clientset kube.Interface) (runningPods []v1.Pod
}

// Pods returns a list of pods under the victim
func (v *VictimBase) Pods(clientset kube.Interface) ([]v1.Pod, error) {
func (v *VictimBase) Pods(clientset kube.Interface) ([]corev1.Pod, error) {
labelSelector, err := labelFilterForPods(v.identifier)
if err != nil {
return nil, err
Expand Down Expand Up @@ -246,7 +246,7 @@ func labelRequirementForPods(identifier string) (*labels.Requirement, error) {
}

// RandomPodName picks a random pod name from a list of Pods
func RandomPodName(pods []v1.Pod) string {
func RandomPodName(pods []corev1.Pod) string {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
randIndex := r.Intn(len(pods))
return pods[randIndex].Name
Expand Down
Loading