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

fix(lint): Fix the lint issues discovered by golangci-lint #292

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ lint:
@echo "------------------"
@go vet $(PACKAGES)

.PHONY: ci-lint
ci-lint:
@echo "------------------"
@echo "--> Running golangci-lint"
@echo "------------------"
golangci-lint run

.PHONY: build
build:
@echo "------------------"
Expand Down
4 changes: 2 additions & 2 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import (
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"

"github.com/litmuschaos/chaos-operator/pkg/analytics"
"github.com/litmuschaos/chaos-operator/pkg/apis"
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/litmuschaos/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/runtime/scheme"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

// GroupName is the name of api group for the custom resources
Expand Down
15 changes: 11 additions & 4 deletions pkg/controller/chaosengine/chaosengine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,13 @@ func (r *ReconcileChaosEngine) updateEngineState(engine *chaosTypes.EngineInfo,
}

// checkRunnerContainerCompletedStatus check for the runner pod's container status for Completed
func (r *ReconcileChaosEngine) checkRunnerContainerCompletedStatus(engine *chaosTypes.EngineInfo) bool {
func (r *ReconcileChaosEngine) checkRunnerContainerCompletedStatus(engine *chaosTypes.EngineInfo) (bool, error) {
runnerPod := corev1.Pod{}
isCompleted := false
r.client.Get(context.TODO(), types.NamespacedName{Name: engine.Instance.Name + "-runner", Namespace: engine.Instance.Namespace}, &runnerPod)
err := r.client.Get(context.TODO(), types.NamespacedName{Name: engine.Instance.Name + "-runner", Namespace: engine.Instance.Namespace}, &runnerPod)
if err != nil {
return false, err
}

if runnerPod.Status.Phase == corev1.PodRunning || runnerPod.Status.Phase == corev1.PodSucceeded {
for _, container := range runnerPod.Status.ContainerStatuses {
Expand All @@ -529,7 +532,7 @@ func (r *ReconcileChaosEngine) checkRunnerContainerCompletedStatus(engine *chaos
}
}
}
return isCompleted
return isCompleted, nil
}

// gracefullyRemoveDefaultChaosResources removes all chaos-resources gracefully
Expand Down Expand Up @@ -630,7 +633,11 @@ func (r *ReconcileChaosEngine) reconcileForCreationAndRunning(engine *chaosTypes
return reconcile.Result{}, err
}

isCompleted := r.checkRunnerContainerCompletedStatus(engine)
isCompleted, err := r.checkRunnerContainerCompletedStatus(engine)
if err != nil {
r.recorder.Eventf(engine.Instance, corev1.EventTypeWarning, "ChaosResourcesOperationFailed", "Unable to check runner container completed status")
return reconcile.Result{}, err
}
if isCompleted {
err := r.updateEngineForComplete(engine, isCompleted)
if err != nil {
Expand Down
10 changes: 8 additions & 2 deletions pkg/controller/chaosengine/chaosengine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,10 @@ func TestCheckRunnerPodCompletedStatus(t *testing.T) {
if err != nil {
fmt.Printf("Unable to create engine: %v", err)
}
val := r.checkRunnerContainerCompletedStatus(&mock.engine)
val, err := r.checkRunnerContainerCompletedStatus(&mock.engine)
if err != nil {
fmt.Printf("Unable to check runner container status: %v", err)
}
if mock.isErr && val == false {
t.Fatalf("Test %q failed: expected error not to be nil", name)
}
Expand Down Expand Up @@ -1120,7 +1123,10 @@ func TestEngineRunnerPod(t *testing.T) {
t.Run(name, func(t *testing.T) {

if name == "Test Positive-2" {
mock.runner.r.client.Create(context.TODO(), mock.runner.engineRunner)
err := mock.runner.r.client.Create(context.TODO(), mock.runner.engineRunner)
if err != nil {
fmt.Printf("Unable to create mock runner client: %v", err)
}
}
err := engineRunnerPod(mock.runner)
if mock.isErr && err == nil {
Expand Down
4 changes: 0 additions & 4 deletions pkg/controller/resource/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ var (
}
)

func print32(p int32) *int32 {
return &p
}

func TestCheckChaosAnnotationDeployment(t *testing.T) {

tests := map[string]struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ package types

import (
"k8s.io/apimachinery/pkg/types"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
logf "sigs.k8s.io/controller-runtime/pkg/log"

"github.com/litmuschaos/chaos-operator/pkg/apis/litmuschaos/v1alpha1"
litmuschaosv1alpha1 "github.com/litmuschaos/chaos-operator/pkg/apis/litmuschaos/v1alpha1"
Expand Down
5 changes: 0 additions & 5 deletions pkg/controller/utils/volumeUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ import (
corev1 "k8s.io/api/core/v1"
)

var (
// hostpathTypeFile represents the hostpath type
hostpathTypeFile = corev1.HostPathFile
)

// CreateVolumeBuilders build Volume needed in execution of experiments
func CreateVolumeBuilders(configMaps []v1alpha1.ConfigMap, secrets []v1alpha1.Secret) []*volume.Builder {
volumeBuilderList := []*volume.Builder{}
Expand Down
1 change: 1 addition & 0 deletions tests/bdd/bdd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ var _ = BeforeSuite(func() {
//Creating crds
By("creating all crds")
err = exec.Command("kubectl", "apply", "-f", "../../deploy/chaos_crds.yaml").Run()
Expect(err).To(BeNil())

//Creating rbacs
err = exec.Command("kubectl", "apply", "-f", "../../deploy/rbac.yaml").Run()
Expand Down