chore(lint): enable mnd
This commit is contained in:
parent
907a2ac625
commit
1fbead3621
|
@ -24,6 +24,17 @@ linters-settings:
|
||||||
rules:
|
rules:
|
||||||
- name: dot-imports
|
- name: dot-imports
|
||||||
disabled: true
|
disabled: true
|
||||||
|
mnd:
|
||||||
|
checks:
|
||||||
|
- argument
|
||||||
|
- case
|
||||||
|
- operation
|
||||||
|
- return
|
||||||
|
- assign
|
||||||
|
ignored-functions:
|
||||||
|
- '^len\.'
|
||||||
|
- '^strings\.SplitN$'
|
||||||
|
- '^make$'
|
||||||
linters:
|
linters:
|
||||||
enable-all: true
|
enable-all: true
|
||||||
disable:
|
disable:
|
||||||
|
@ -44,7 +55,6 @@ linters:
|
||||||
- goerr113
|
- goerr113
|
||||||
- gofumpt
|
- gofumpt
|
||||||
- golint
|
- golint
|
||||||
- gomnd
|
|
||||||
- gomoddirectives
|
- gomoddirectives
|
||||||
- interfacer
|
- interfacer
|
||||||
- ireturn
|
- ireturn
|
||||||
|
|
|
@ -23,6 +23,10 @@ import (
|
||||||
daprClient "github.com/dapr-sandbox/dapr-kubernetes-operator/pkg/client/clientset/versioned"
|
daprClient "github.com/dapr-sandbox/dapr-kubernetes-operator/pkg/client/clientset/versioned"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DiscoveryLimiterBurst = 30
|
||||||
|
)
|
||||||
|
|
||||||
var scaleConverter = scale.NewScaleConverter()
|
var scaleConverter = scale.NewScaleConverter()
|
||||||
var codecs = serializer.NewCodecFactory(scaleConverter.Scheme())
|
var codecs = serializer.NewCodecFactory(scaleConverter.Scheme())
|
||||||
|
|
||||||
|
@ -82,7 +86,7 @@ func NewClient(cfg *rest.Config, scheme *runtime.Scheme, cc ctrl.Client) (*Clien
|
||||||
rest: restCl,
|
rest: restCl,
|
||||||
}
|
}
|
||||||
|
|
||||||
c.discoveryLimiter = rate.NewLimiter(rate.Every(time.Second), 30)
|
c.discoveryLimiter = rate.NewLimiter(rate.Every(time.Second), DiscoveryLimiterBurst)
|
||||||
c.discoveryCache = memory.NewMemCacheClient(discoveryCl)
|
c.discoveryCache = memory.NewMemCacheClient(discoveryCl)
|
||||||
c.mapper = restmapper.NewDeferredDiscoveryRESTMapper(c.discoveryCache)
|
c.mapper = restmapper.NewDeferredDiscoveryRESTMapper(c.discoveryCache)
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,11 @@ var (
|
||||||
Log = ctrl.Log.WithName("controller")
|
Log = ctrl.Log.WithName("controller")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
PprofReadTimeout = 10 * time.Second
|
||||||
|
PprofWriteTimeout = 10 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
utilruntime.Must(clientgoscheme.AddToScheme(Scheme))
|
utilruntime.Must(clientgoscheme.AddToScheme(Scheme))
|
||||||
}
|
}
|
||||||
|
@ -78,8 +83,8 @@ func Start(options Options, setup func(manager.Manager, Options) error) error {
|
||||||
|
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
Addr: options.PprofAddr,
|
Addr: options.PprofAddr,
|
||||||
ReadTimeout: 10 * time.Second,
|
ReadTimeout: PprofReadTimeout,
|
||||||
WriteTimeout: 10 * time.Second,
|
WriteTimeout: PprofWriteTimeout,
|
||||||
Handler: mux,
|
Handler: mux,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,14 @@ import (
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DefaultProbeInitialDelay = 5
|
||||||
|
DefaultProbePeriod = 10
|
||||||
|
DefaultProbeTimeout = 10
|
||||||
|
DefaultProbeFailureThreshold = 10
|
||||||
|
DefaultProbeSuccessThreshold = 1
|
||||||
|
)
|
||||||
|
|
||||||
func WithOwnerReference(object client.Object) *metav1ac.OwnerReferenceApplyConfiguration {
|
func WithOwnerReference(object client.Object) *metav1ac.OwnerReferenceApplyConfiguration {
|
||||||
return metav1ac.OwnerReference().
|
return metav1ac.OwnerReference().
|
||||||
WithAPIVersion(object.GetObjectKind().GroupVersionKind().GroupVersion().String()).
|
WithAPIVersion(object.GetObjectKind().GroupVersionKind().GroupVersion().String()).
|
||||||
|
@ -22,11 +30,11 @@ func WithOwnerReference(object client.Object) *metav1ac.OwnerReferenceApplyConfi
|
||||||
|
|
||||||
func WithHTTPProbe(path string, port int32) *corev1ac.ProbeApplyConfiguration {
|
func WithHTTPProbe(path string, port int32) *corev1ac.ProbeApplyConfiguration {
|
||||||
return corev1ac.Probe().
|
return corev1ac.Probe().
|
||||||
WithInitialDelaySeconds(5).
|
WithInitialDelaySeconds(DefaultProbeInitialDelay).
|
||||||
WithPeriodSeconds(10).
|
WithPeriodSeconds(DefaultProbePeriod).
|
||||||
WithFailureThreshold(10).
|
WithFailureThreshold(DefaultProbeFailureThreshold).
|
||||||
WithSuccessThreshold(1).
|
WithSuccessThreshold(DefaultProbeSuccessThreshold).
|
||||||
WithTimeoutSeconds(10).
|
WithTimeoutSeconds(DefaultProbeTimeout).
|
||||||
WithHTTPGet(corev1ac.HTTPGetAction().
|
WithHTTPGet(corev1ac.HTTPGetAction().
|
||||||
WithPath(path).
|
WithPath(path).
|
||||||
WithPort(intstr.IntOrString{IntVal: port}).
|
WithPort(intstr.IntOrString{IntVal: port}).
|
||||||
|
|
|
@ -16,6 +16,10 @@ import (
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
IngressPort = 8081
|
||||||
|
)
|
||||||
|
|
||||||
func ValidateDaprApp(test support.Test, namespace string) {
|
func ValidateDaprApp(test support.Test, namespace string) {
|
||||||
test.T().Helper()
|
test.T().Helper()
|
||||||
|
|
||||||
|
@ -52,7 +56,7 @@ func ValidateDaprApp(test support.Test, namespace string) {
|
||||||
|
|
||||||
test.T().Logf("Testing the app with name %s", appName)
|
test.T().Logf("Testing the app with name %s", appName)
|
||||||
|
|
||||||
base := fmt.Sprintf("http://localhost:%d/%s", 8081, appName)
|
base := fmt.Sprintf("http://localhost:%d/%s", IngressPort, appName)
|
||||||
value := xid.New().String()
|
value := xid.New().String()
|
||||||
|
|
||||||
//nolint:bodyclose
|
//nolint:bodyclose
|
||||||
|
|
|
@ -19,6 +19,10 @@ var (
|
||||||
once sync.Once
|
once sync.Once
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
HTTPReadHeaderTimeout = 3 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
appPort = os.Getenv("APP_PORT")
|
appPort = os.Getenv("APP_PORT")
|
||||||
if appPort == "" {
|
if appPort == "" {
|
||||||
|
@ -110,7 +114,7 @@ func main() {
|
||||||
|
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
Addr: ":" + appPort,
|
Addr: ":" + appPort,
|
||||||
ReadHeaderTimeout: 3 * time.Second,
|
ReadHeaderTimeout: HTTPReadHeaderTimeout,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := server.ListenAndServe()
|
err := server.ListenAndServe()
|
||||||
|
|
|
@ -2,6 +2,7 @@ package dapr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/dapr-sandbox/dapr-kubernetes-operator/pkg/pointer"
|
"github.com/dapr-sandbox/dapr-kubernetes-operator/pkg/pointer"
|
||||||
|
@ -25,6 +26,11 @@ import (
|
||||||
metav1ac "k8s.io/client-go/applyconfigurations/meta/v1"
|
metav1ac "k8s.io/client-go/applyconfigurations/meta/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
TestAppPort = 8080
|
||||||
|
TestAppServicePort = 80
|
||||||
|
)
|
||||||
|
|
||||||
func DeployTestApp(t support.Test, name string, namespace string) {
|
func DeployTestApp(t support.Test, name string, namespace string) {
|
||||||
t.T().Helper()
|
t.T().Helper()
|
||||||
t.T().Logf("Setting up Dapr Application %s in namespace %s", name, namespace)
|
t.T().Logf("Setting up Dapr Application %s in namespace %s", name, namespace)
|
||||||
|
@ -103,7 +109,7 @@ func DeployTestApp(t support.Test, name string, namespace string) {
|
||||||
}).
|
}).
|
||||||
WithAnnotations(map[string]string{
|
WithAnnotations(map[string]string{
|
||||||
"dapr.io/app-id": name,
|
"dapr.io/app-id": name,
|
||||||
"dapr.io/app-port": "8080",
|
"dapr.io/app-port": strconv.Itoa(TestAppPort),
|
||||||
"dapr.io/enabled": "true",
|
"dapr.io/enabled": "true",
|
||||||
"dapr.io/enable-api-logging": "true",
|
"dapr.io/enable-api-logging": "true",
|
||||||
}).
|
}).
|
||||||
|
@ -112,9 +118,9 @@ func DeployTestApp(t support.Test, name string, namespace string) {
|
||||||
WithImage("kind.local/dapr-test-app:latest").
|
WithImage("kind.local/dapr-test-app:latest").
|
||||||
WithImagePullPolicy(corev1.PullNever).
|
WithImagePullPolicy(corev1.PullNever).
|
||||||
WithName("app").
|
WithName("app").
|
||||||
WithPorts(resources.WithPort("http", 8080)).
|
WithPorts(resources.WithPort("http", TestAppPort)).
|
||||||
WithReadinessProbe(resources.WithHTTPProbe("/health/readiness", 8080)).
|
WithReadinessProbe(resources.WithHTTPProbe("/health/readiness", TestAppPort)).
|
||||||
WithLivenessProbe(resources.WithHTTPProbe("/health/liveness", 8080)).
|
WithLivenessProbe(resources.WithHTTPProbe("/health/liveness", TestAppPort)).
|
||||||
WithEnv(resources.WithEnv("STATESTORE_NAME", name)),
|
WithEnv(resources.WithEnv("STATESTORE_NAME", name)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -148,8 +154,8 @@ func DeployTestApp(t support.Test, name string, namespace string) {
|
||||||
WithPorts(corev1ac.ServicePort().
|
WithPorts(corev1ac.ServicePort().
|
||||||
WithName("http").
|
WithName("http").
|
||||||
WithProtocol(corev1.ProtocolTCP).
|
WithProtocol(corev1.ProtocolTCP).
|
||||||
WithPort(80).
|
WithPort(TestAppServicePort).
|
||||||
WithTargetPort(intstr.FromInt32(8080))).
|
WithTargetPort(intstr.FromInt32(TestAppPort))).
|
||||||
WithSelector(map[string]string{
|
WithSelector(map[string]string{
|
||||||
"app": name,
|
"app": name,
|
||||||
}).
|
}).
|
||||||
|
@ -198,7 +204,7 @@ func DeployTestApp(t support.Test, name string, namespace string) {
|
||||||
WithService(netv1ac.IngressServiceBackend().
|
WithService(netv1ac.IngressServiceBackend().
|
||||||
WithName(name).
|
WithName(name).
|
||||||
WithPort(netv1ac.ServiceBackendPort().
|
WithPort(netv1ac.ServiceBackendPort().
|
||||||
WithNumber(80),
|
WithNumber(TestAppServicePort),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -11,6 +11,10 @@ import (
|
||||||
"helm.sh/helm/v3/pkg/release"
|
"helm.sh/helm/v3/pkg/release"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DefaultInstallTimeout = 10 * time.Minute
|
||||||
|
)
|
||||||
|
|
||||||
type InstallOption func(*ReleaseOptions[action.Install])
|
type InstallOption func(*ReleaseOptions[action.Install])
|
||||||
|
|
||||||
func (h *Helm) Install(ctx context.Context, chart string, options ...InstallOption) (*release.Release, error) {
|
func (h *Helm) Install(ctx context.Context, chart string, options ...InstallOption) (*release.Release, error) {
|
||||||
|
@ -21,7 +25,7 @@ func (h *Helm) Install(ctx context.Context, chart string, options ...InstallOpti
|
||||||
client.IncludeCRDs = true
|
client.IncludeCRDs = true
|
||||||
client.Wait = true
|
client.Wait = true
|
||||||
client.Namespace = xid.New().String()
|
client.Namespace = xid.New().String()
|
||||||
client.Timeout = 10 * time.Minute
|
client.Timeout = DefaultInstallTimeout
|
||||||
|
|
||||||
io := ReleaseOptions[action.Install]{
|
io := ReleaseOptions[action.Install]{
|
||||||
Client: client,
|
Client: client,
|
||||||
|
|
|
@ -17,6 +17,10 @@ import (
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
CatalogRegistryPollInterval = 10 * time.Minute
|
||||||
|
)
|
||||||
|
|
||||||
func DeployOperator(test support.Test, ns *corev1.Namespace, image string) {
|
func DeployOperator(test support.Test, ns *corev1.Namespace, image string) {
|
||||||
//
|
//
|
||||||
// Install OperatorGroups
|
// Install OperatorGroups
|
||||||
|
@ -91,7 +95,7 @@ func DeployOperator(test support.Test, ns *corev1.Namespace, image string) {
|
||||||
UpdateStrategy: &olmV1Alpha1.UpdateStrategy{
|
UpdateStrategy: &olmV1Alpha1.UpdateStrategy{
|
||||||
RegistryPoll: &olmV1Alpha1.RegistryPoll{
|
RegistryPoll: &olmV1Alpha1.RegistryPoll{
|
||||||
Interval: &metav1.Duration{
|
Interval: &metav1.Duration{
|
||||||
Duration: 10 * time.Minute,
|
Duration: CatalogRegistryPollInterval,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -3,7 +3,6 @@ package support
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/onsi/gomega"
|
"github.com/onsi/gomega"
|
||||||
|
|
||||||
|
@ -14,13 +13,6 @@ import (
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
TestTimeoutMini = 5 * time.Second
|
|
||||||
TestTimeoutShort = 1 * time.Minute
|
|
||||||
TestTimeoutMedium = 2 * time.Minute
|
|
||||||
TestTimeoutLong = 5 * time.Minute
|
|
||||||
)
|
|
||||||
|
|
||||||
func runCleanup(t Test, in runtime.Object) error {
|
func runCleanup(t Test, in runtime.Object) error {
|
||||||
un, err := resources.ToUnstructured(t.Client().Scheme(), in)
|
un, err := resources.ToUnstructured(t.Client().Scheme(), in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -28,6 +28,18 @@ import (
|
||||||
olmV1Alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
|
olmV1Alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
TestTimeoutMini = 5 * time.Second
|
||||||
|
TestTimeoutShort = 1 * time.Minute
|
||||||
|
TestTimeoutMedium = 2 * time.Minute
|
||||||
|
TestTimeoutLong = 5 * time.Minute
|
||||||
|
|
||||||
|
DefaultEventuallyPollingInterval = 500 * time.Millisecond
|
||||||
|
DefaultEventuallyTimeout = TestTimeoutLong
|
||||||
|
DefaultConsistentlyDuration = 500 * time.Millisecond
|
||||||
|
DefaultConsistentlyPollingInterval = 500 * time.Millisecond
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if err := daprApi.AddToScheme(scheme.Scheme); err != nil {
|
if err := daprApi.AddToScheme(scheme.Scheme); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -81,10 +93,10 @@ func With(t *testing.T) Test {
|
||||||
cleanup: make([]func() []runtime.Object, 0),
|
cleanup: make([]func() []runtime.Object, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
answer.SetDefaultEventuallyPollingInterval(500 * time.Millisecond)
|
answer.SetDefaultEventuallyPollingInterval(DefaultEventuallyPollingInterval)
|
||||||
answer.SetDefaultEventuallyTimeout(TestTimeoutLong)
|
answer.SetDefaultEventuallyTimeout(DefaultEventuallyTimeout)
|
||||||
answer.SetDefaultConsistentlyDuration(500 * time.Millisecond)
|
answer.SetDefaultConsistentlyDuration(DefaultConsistentlyDuration)
|
||||||
answer.SetDefaultConsistentlyDuration(TestTimeoutLong)
|
answer.SetDefaultConsistentlyPollingInterval(DefaultConsistentlyPollingInterval)
|
||||||
|
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
t.Log("Run Test cleanup")
|
t.Log("Run Test cleanup")
|
||||||
|
|
Loading…
Reference in New Issue