Skip to content

Commit

Permalink
fix linter errors 6
Browse files Browse the repository at this point in the history
  • Loading branch information
koala7659 committed Jun 25, 2024
1 parent a97b3d7 commit 0e124ec
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
5 changes: 5 additions & 0 deletions internal/controller/runtime/fsm/runtime_fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"reflect"
"runtime"
"time"

"github.com/go-logr/logr"
imv1 "github.com/kyma-project/infrastructure-manager/api/v1"
Expand All @@ -17,6 +18,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/source"
)

const (
gardenerRequeueDuration = 15 * time.Second
)

type stateFn func(context.Context, *fsm, *systemState) (stateFn, *ctrl.Result, error)

// runtime reconciler specific configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func sFnCreateShoot(ctx context.Context, m *fsm, s *systemState) (stateFn, *ctrl
"Gardener API create error",
)

return stopWithRequeueAfter(15 * time.Second)
return stopWithRequeueAfter(gardenerRequeueDuration)
}

m.log.Info("Gardener shoot for runtime initialised successfully", "Name", s.shoot.Name, "Namespace", s.shoot.Namespace)
Expand Down
14 changes: 5 additions & 9 deletions internal/controller/runtime/fsm/runtime_fsm_initialise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@ package fsm

import (
"context"

"k8s.io/apimachinery/pkg/api/meta"

"sigs.k8s.io/controller-runtime/pkg/client"

"time"

gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
util "k8s.io/apimachinery/pkg/util/runtime"

imv1 "github.com/kyma-project/infrastructure-manager/api/v1"
. "github.com/onsi/ginkgo/v2" //nolint:revive
. "github.com/onsi/gomega" //nolint:revive
"github.com/onsi/gomega/types"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
util "k8s.io/apimachinery/pkg/util/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)

var withTestFinalizer = withFinalizer("test-me-plz")

Check failure on line 19 in internal/controller/runtime/fsm/runtime_fsm_initialise_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

withTestFinalizer is a global variable (gochecknoglobals)
Expand Down
13 changes: 6 additions & 7 deletions internal/controller/runtime/fsm/runtime_fsm_prepare_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,32 @@ import (
"context"
"fmt"
"strings"
"time"

imv1 "github.com/kyma-project/infrastructure-manager/api/v1"

Check failure on line 8 in internal/controller/runtime/fsm/runtime_fsm_prepare_cluster.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gci`-ed with --skip-generated -s standard -s default (gci)

gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1"
gardenerhelper "github.com/gardener/gardener/pkg/apis/core/v1beta1/helper"

Check failure on line 11 in internal/controller/runtime/fsm/runtime_fsm_prepare_cluster.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gci`-ed with --skip-generated -s standard -s default (gci)
imv1 "github.com/kyma-project/infrastructure-manager/api/v1"
ctrl "sigs.k8s.io/controller-runtime"
)

type ErrReason string

func sFnPrepareCluster(_ context.Context, m *fsm, s *systemState) (stateFn, *ctrl.Result, error) {

if s.shoot == nil {
return stopWithErrorAndNoRequeue(fmt.Errorf("fatal state machine logic problem: Shoot can never be nil in PrepareCluster state"))
}

if s.shoot.Spec.DNS == nil || s.shoot.Spec.DNS.Domain == nil {
msg := fmt.Sprintf("DNS Domain is not set yet for shoot: %s, scheduling for retry", s.shoot.Name)
m.log.Info(msg)
return stopWithRequeueAfter(time.Second * 15)
return stopWithRequeueAfter(gardenerRequeueDuration)
}

lastOperation := s.shoot.Status.LastOperation
if lastOperation == nil {
msg := fmt.Sprintf("Last operation is nil for shoot: %s, scheduling for retry", s.shoot.Name)
m.log.Info(msg)
return stopWithRequeueAfter(time.Second * 15)
return stopWithRequeueAfter(gardenerRequeueDuration)
}

if lastOperation.Type == gardener.LastOperationTypeCreate {

Check failure on line 35 in internal/controller/runtime/fsm/runtime_fsm_prepare_cluster.go

View workflow job for this annotation

GitHub Actions / golangci-lint

`if lastOperation.Type == gardener.LastOperationTypeCreate` has complex nested blocks (complexity: 7) (nestif)
Expand All @@ -46,7 +45,7 @@ func sFnPrepareCluster(_ context.Context, m *fsm, s *systemState) (stateFn, *ctr
"Unknown",
"Shoot creation in progress")

return stopWithRequeueAfter(time.Second * 15)
return stopWithRequeueAfter(gardenerRequeueDuration)
}

if lastOperation.State == gardener.LastOperationStateSucceeded {
Expand All @@ -70,7 +69,7 @@ func sFnPrepareCluster(_ context.Context, m *fsm, s *systemState) (stateFn, *ctr
if gardenerhelper.HasErrorCode(s.shoot.Status.LastErrors, gardener.ErrorInfraRateLimitsExceeded) {
msg := fmt.Sprintf("Error during cluster provisioning: Rate limits exceeded for Shoot %s, scheduling for retry", s.shoot.Name)
m.log.Info(msg)
return stopWithRequeueAfter(time.Second * 15)
return stopWithRequeueAfter(gardenerRequeueDuration)
}

msg := fmt.Sprintf("Provisioning failed for shoot: %s ! Last state: %s, Description: %s", s.shoot.Name, lastOperation.State, lastOperation.Description)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ func (m *instanceConditionMatcher) Match(actual any) (success bool, err error) {
return Equal(m.expected).Match(m.actual)
}

func (m *instanceConditionMatcher) FailureMessage(actual interface{}) (message string) {
func (m *instanceConditionMatcher) FailureMessage(_ interface{}) (message string) {
return fmt.Sprintf("Expected\n\t%v\nto contain\n\t%s", m.actual, m.expected)
}

func (m *instanceConditionMatcher) NegatedFailureMessage(actual interface{}) (message string) {
func (m *instanceConditionMatcher) NegatedFailureMessage(_ interface{}) (message string) {
return fmt.Sprintf("Expected\n\t%v\nnot to contain\n\t%s", m.actual, m.expected)
}
2 changes: 1 addition & 1 deletion internal/controller/runtime/fsm/utilz_for_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

gardener_mocks "github.com/kyma-project/infrastructure-manager/internal/gardener/mocks"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega" //nolint:revive
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
Expand Down

0 comments on commit 0e124ec

Please sign in to comment.