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