diff --git a/cmd/shell-operator/main.go b/cmd/shell-operator/main.go index 6ed296fb..16f8a727 100644 --- a/cmd/shell-operator/main.go +++ b/cmd/shell-operator/main.go @@ -2,9 +2,7 @@ package main import ( "fmt" - "math/rand" "os" - "time" "github.com/deckhouse/deckhouse/pkg/log" "gopkg.in/alecthomas/kingpin.v2" @@ -27,13 +25,13 @@ func main() { kpApp.UsageTemplate(app.OperatorUsageTemplate(app.AppName)) // Initialize klog wrapper when all values are parsed - kpApp.Action(func(c *kingpin.ParseContext) error { + kpApp.Action(func(_ *kingpin.ParseContext) error { klogtolog.InitAdapter(app.DebugKubernetesAPI, logger.Named("klog")) return nil }) // print version - kpApp.Command("version", "Show version.").Action(func(c *kingpin.ParseContext) error { + kpApp.Command("version", "Show version.").Action(func(_ *kingpin.ParseContext) error { fmt.Printf("%s %s\n", app.AppName, app.Version) fmt.Println(jq.FilterInfo()) return nil @@ -42,12 +40,9 @@ func main() { // start main loop startCmd := kpApp.Command("start", "Start shell-operator."). Default(). - Action(func(c *kingpin.ParseContext) error { + Action(func(_ *kingpin.ParseContext) error { app.AppStartMessage = fmt.Sprintf("%s %s", app.AppName, app.Version) - // Init rand generator. - rand.Seed(time.Now().UnixNano()) - // Init logging and initialize a ShellOperator instance. operator, err := shell_operator.Init(logger.Named("shell-operator")) if err != nil { diff --git a/pkg/app/app.go b/pkg/app/app.go index 24318705..f0edf74d 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -148,7 +148,7 @@ Use "%s debug-options" for a list of debug options for start command. // CommandWithDefaultUsageTemplate is used to workaround an absence of per-command usage templates func CommandWithDefaultUsageTemplate(kpApp *kingpin.Application, name, help string) *kingpin.CmdClause { - return kpApp.Command(name, help).PreAction(func(context *kingpin.ParseContext) error { + return kpApp.Command(name, help).PreAction(func(_ *kingpin.ParseContext) error { kpApp.UsageTemplate(kingpin.DefaultUsageTemplate) return nil }) diff --git a/pkg/app/log.go b/pkg/app/log.go index 316303e1..88bfe80e 100644 --- a/pkg/app/log.go +++ b/pkg/app/log.go @@ -69,11 +69,11 @@ func SetupLogging(runtimeConfig *config.Config, logger *log.Logger) { runtimeConfig.Register("log.level", fmt.Sprintf("Global log level. Default duration for debug level is %s", ForcedDurationForDebugLevel), strings.ToLower(LogLevel), - func(oldValue string, newValue string) error { - log.Infof("Set log level to '%s'", newValue) + func(_ string, newValue string) error { + logger.Infof("Set log level to '%s'", newValue) log.SetDefaultLevel(log.LogLevelFromStr(newValue)) return nil - }, func(oldValue string, newValue string) time.Duration { + }, func(_ string, newValue string) time.Duration { if strings.ToLower(newValue) == "debug" { return ForcedDurationForDebugLevel } diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 2425a8bf..4261f44b 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -36,7 +36,7 @@ func TestConfig_OnChange(t *testing.T) { c := NewConfig(log.NewNop()) newValue := "" - c.Register("log.level", "", "info", func(oldValue string, n string) error { + c.Register("log.level", "", "info", func(_ string, n string) error { newValue = n return nil }, nil) @@ -69,7 +69,7 @@ func TestConfig_Errors(t *testing.T) { var err error c := NewConfig(log.NewNop()) - c.Register("log.level", "", "info", func(oldValue string, n string) error { + c.Register("log.level", "", "info", func(_ string, n string) error { if n == "debug" { return nil } diff --git a/pkg/debug/debug-cmd.go b/pkg/debug/debug-cmd.go index 07f8ddd7..702a6d12 100644 --- a/pkg/debug/debug-cmd.go +++ b/pkg/debug/debug-cmd.go @@ -19,7 +19,7 @@ func DefineDebugCommands(kpApp *kingpin.Application) { queueCmd := app.CommandWithDefaultUsageTemplate(kpApp, "queue", "Dump queues.") queueListCmd := queueCmd.Command("list", "Dump tasks in all queues."). - Action(func(c *kingpin.ParseContext) error { + Action(func(_ *kingpin.ParseContext) error { out, err := Queue(DefaultClient()).List(outputFormat, showEmpty) if err != nil { return err @@ -34,7 +34,7 @@ func DefineDebugCommands(kpApp *kingpin.Application) { app.DefineDebugUnixSocketFlag(queueListCmd) queueMainCmd := queueCmd.Command("main", "Dump tasks in the main queue."). - Action(func(c *kingpin.ParseContext) error { + Action(func(_ *kingpin.ParseContext) error { out, err := Queue(DefaultClient()).Main(outputFormat) if err != nil { return err @@ -49,7 +49,7 @@ func DefineDebugCommands(kpApp *kingpin.Application) { configCmd := app.CommandWithDefaultUsageTemplate(kpApp, "config", "Manage runtime parameters.") configListCmd := configCmd.Command("list", "List available runtime parameters."). - Action(func(c *kingpin.ParseContext) error { + Action(func(_ *kingpin.ParseContext) error { out, err := Config(DefaultClient()).List(outputFormat) if err != nil { return err @@ -64,7 +64,7 @@ func DefineDebugCommands(kpApp *kingpin.Application) { var paramValue string var paramDuration time.Duration configSetCmd := configCmd.Command("set", "Set runtime parameter."). - Action(func(c *kingpin.ParseContext) error { + Action(func(_ *kingpin.ParseContext) error { out, err := Config(DefaultClient()).Set(paramName, paramValue, paramDuration) if err != nil { return err @@ -80,7 +80,7 @@ func DefineDebugCommands(kpApp *kingpin.Application) { // Raw request command var rawUrl string rawCommand := app.CommandWithDefaultUsageTemplate(kpApp, "raw", "Make a raw request to debug endpoint."). - Action(func(c *kingpin.ParseContext) error { + Action(func(_ *kingpin.ParseContext) error { url := fmt.Sprintf("http://unix%s", rawUrl) resp, err := DefaultClient().Get(url) if err != nil { @@ -97,7 +97,7 @@ func DefineDebugCommandsSelf(kpApp *kingpin.Application) { // Get hook names hookCmd := app.CommandWithDefaultUsageTemplate(kpApp, "hook", "Actions for hooks") hookListCmd := hookCmd.Command("list", "List all hooks."). - Action(func(c *kingpin.ParseContext) error { + Action(func(_ *kingpin.ParseContext) error { outBytes, err := Hook(DefaultClient()).List(outputFormat) if err != nil { return err @@ -111,7 +111,7 @@ func DefineDebugCommandsSelf(kpApp *kingpin.Application) { // Get hook snapshots var hookName string hookSnapshotCmd := hookCmd.Command("snapshot", "Dump hook snapshots."). - Action(func(c *kingpin.ParseContext) error { + Action(func(_ *kingpin.ParseContext) error { outBytes, err := Hook(DefaultClient()).Name(hookName).Snapshots(outputFormat) if err != nil { return err diff --git a/pkg/executor/executor.go b/pkg/executor/executor.go index 409dcb88..68cda40e 100644 --- a/pkg/executor/executor.go +++ b/pkg/executor/executor.go @@ -122,7 +122,7 @@ func (pl *proxyLogger) Write(p []byte) (int, error) { logLine := string(logLineRaw) if len(logLine) > 10000 { - logLine = fmt.Sprintf("%s:truncated", string(logLine[:10000])) + logLine = fmt.Sprintf("%s:truncated", logLine[:10000]) logger.Log(context.Background(), log.LevelFatal.Level(), "hook result", slog.Any("hook", map[string]any{ "truncated": logLine, diff --git a/pkg/executor/executor_test.go b/pkg/executor/executor_test.go index 6a008c3d..6159dc2f 100644 --- a/pkg/executor/executor_test.go +++ b/pkg/executor/executor_test.go @@ -3,7 +3,7 @@ package executor import ( "bytes" "io" - "math/rand" + "math/rand/v2" "os" "os/exec" "regexp" @@ -159,7 +159,7 @@ var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") func randStringRunes(n int) string { b := make([]rune, n) for i := range b { - b[i] = letterRunes[rand.Intn(len(letterRunes))] + b[i] = letterRunes[rand.IntN(len(letterRunes))] } return string(b) } diff --git a/pkg/hook/config/config_test.go b/pkg/hook/config/config_test.go index d47c57a5..5d1b828a 100644 --- a/pkg/hook/config/config_test.go +++ b/pkg/hook/config/config_test.go @@ -775,7 +775,7 @@ settings: } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { + t.Run(test.name, func(_ *testing.T) { hookConfig = &HookConfig{} err = hookConfig.LoadAndValidate([]byte(test.jsonConfig)) test.testFn() @@ -1045,7 +1045,7 @@ func Test_HookConfig_V1_Kubernetes_Validate(t *testing.T) { } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { + t.Run(test.name, func(_ *testing.T) { hookConfig = &HookConfig{} err = hookConfig.LoadAndValidate([]byte(test.jsonText)) test.testFn() @@ -1083,7 +1083,7 @@ func Test_MergeArrays(t *testing.T) { } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { + t.Run(test.name, func(_ *testing.T) { res := MergeArrays(test.a1, test.a2) g.Expect(res).To(Equal(test.expect)) }) diff --git a/pkg/hook/config/validator_test.go b/pkg/hook/config/validator_test.go index 16a4f698..6bc3533f 100644 --- a/pkg/hook/config/validator_test.go +++ b/pkg/hook/config/validator_test.go @@ -144,7 +144,7 @@ func Test_Validate_V1_With_Error(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(_ *testing.T) { vu = prepareConfigObj(g, tt.configText) s := GetSchema(vu.Version) err = ValidateConfig(vu.Obj, s, "root") diff --git a/pkg/hook/config/versioned_untyped_test.go b/pkg/hook/config/versioned_untyped_test.go index 93971f60..aa250db3 100644 --- a/pkg/hook/config/versioned_untyped_test.go +++ b/pkg/hook/config/versioned_untyped_test.go @@ -136,7 +136,7 @@ schedule: } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(_ *testing.T) { vu = NewDefaultVersionedUntyped() err = vu.Load([]byte(tt.input)) diff --git a/pkg/hook/controller/conversion_bindings_controller.go b/pkg/hook/controller/conversion_bindings_controller.go index 9f56e21e..d64e3939 100644 --- a/pkg/hook/controller/conversion_bindings_controller.go +++ b/pkg/hook/controller/conversion_bindings_controller.go @@ -69,7 +69,7 @@ func (c *ConversionBindingsController) DisableConversionBindings() { // TODO dynamic enable/disable conversion webhooks. } -func (c *ConversionBindingsController) CanHandleEvent(crdName string, request *v1.ConversionRequest, rule conversion.Rule) bool { +func (c *ConversionBindingsController) CanHandleEvent(crdName string, _ *v1.ConversionRequest, rule conversion.Rule) bool { _, has := c.Links[crdName] if !has { return false diff --git a/pkg/hook/controller/hook_controller.go b/pkg/hook/controller/hook_controller.go index f69c77c0..54cd166d 100644 --- a/pkg/hook/controller/hook_controller.go +++ b/pkg/hook/controller/hook_controller.go @@ -63,6 +63,7 @@ func (hc *HookController) InitKubernetesBindings(bindings []OnKubernetesEventCon bindingCtrl.WithKubernetesBindings(bindings) hc.KubernetesController = bindingCtrl hc.kubernetesBindings = bindings + hc.logger = logger } func (hc *HookController) InitScheduleBindings(bindings []ScheduleConfig, scheduleMgr schedule_manager.ScheduleManager) { diff --git a/pkg/hook/hook_test.go b/pkg/hook/hook_test.go index 25090a3d..b7c28cf8 100644 --- a/pkg/hook/hook_test.go +++ b/pkg/hook/hook_test.go @@ -87,7 +87,7 @@ func Test_CreateLimiter(t *testing.T) { } for _, c := range cases { - t.Run(c.title, func(t *testing.T) { + t.Run(c.title, func(_ *testing.T) { cfg := &config.HookConfig{ Settings: c.settings, } @@ -135,7 +135,7 @@ func Test_Hook_WithConfig(t *testing.T) { } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { + t.Run(test.name, func(_ *testing.T) { hook = NewHook("hook-sh", "/hooks/hook.sh", log.NewNop()) _, err = hook.LoadConfig([]byte(test.jsonData)) test.fn() diff --git a/pkg/kube_events_manager/util.go b/pkg/kube_events_manager/util.go index f37869eb..b4459d2e 100644 --- a/pkg/kube_events_manager/util.go +++ b/pkg/kube_events_manager/util.go @@ -2,7 +2,7 @@ package kube_events_manager import ( "fmt" - "math/rand" + "math/rand/v2" "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -59,9 +59,9 @@ const ( // randomizedResyncPeriod returns a time.Duration between 2 hours and 4 hours with jitter and granularity func randomizedResyncPeriod() time.Duration { spreadCount := ResyncPeriodSpread.Nanoseconds() / ResyncPeriodGranularity.Nanoseconds() - rndSpreadDelta := time.Duration(rand.Int63n(spreadCount)) * ResyncPeriodGranularity + rndSpreadDelta := time.Duration(rand.Int64N(spreadCount)) * ResyncPeriodGranularity jitterCount := ResyncPeriodGranularity.Nanoseconds() / ResyncPeriodJitterGranularity.Nanoseconds() - rndJitterDelta := time.Duration(rand.Int63n(jitterCount)) * ResyncPeriodJitterGranularity + rndJitterDelta := time.Duration(rand.Int64N(jitterCount)) * ResyncPeriodJitterGranularity return ResyncPeriodMedian - (ResyncPeriodSpread / 2) + rndSpreadDelta + rndJitterDelta } diff --git a/pkg/schedule_manager/schedule_manager_test.go b/pkg/schedule_manager/schedule_manager_test.go index c0802ffe..21efbc2b 100644 --- a/pkg/schedule_manager/schedule_manager_test.go +++ b/pkg/schedule_manager/schedule_manager_test.go @@ -39,7 +39,7 @@ func Test_ScheduleManager_Add(t *testing.T) { } for _, expectation := range expectations { - t.Run(expectation.testName, func(t *testing.T) { + t.Run(expectation.testName, func(_ *testing.T) { sm.Add(types.ScheduleEntry{Crontab: expectation.crontab, Id: expectation.id}) // if expectation.err != "" { diff --git a/pkg/shell-operator/combine_binding_context_test.go b/pkg/shell-operator/combine_binding_context_test.go index fa36a2bb..96106dbb 100644 --- a/pkg/shell-operator/combine_binding_context_test.go +++ b/pkg/shell-operator/combine_binding_context_test.go @@ -20,7 +20,7 @@ func Test_CombineBindingContext_MultipleHooks(t *testing.T) { TaskQueues := queue.NewTaskQueueSet() TaskQueues.WithContext(context.Background()) - TaskQueues.NewNamedQueue("test_multiple_hooks", func(tsk task.Task) queue.TaskResult { + TaskQueues.NewNamedQueue("test_multiple_hooks", func(_ task.Task) queue.TaskResult { return queue.TaskResult{ Status: "Success", } @@ -114,7 +114,7 @@ func Test_CombineBindingContext_Nil_On_NoCombine(t *testing.T) { TaskQueues := queue.NewTaskQueueSet() TaskQueues.WithContext(context.Background()) - TaskQueues.NewNamedQueue("test_no_combine", func(tsk task.Task) queue.TaskResult { + TaskQueues.NewNamedQueue("test_no_combine", func(_ task.Task) queue.TaskResult { return queue.TaskResult{ Status: "Success", } @@ -173,7 +173,7 @@ func Test_CombineBindingContext_Group_Compaction(t *testing.T) { TaskQueues := queue.NewTaskQueueSet() TaskQueues.WithContext(context.Background()) - TaskQueues.NewNamedQueue("test_multiple_hooks", func(tsk task.Task) queue.TaskResult { + TaskQueues.NewNamedQueue("test_multiple_hooks", func(_ task.Task) queue.TaskResult { return queue.TaskResult{ Status: "Success", } @@ -275,7 +275,7 @@ func Test_CombineBindingContext_Group_Type(t *testing.T) { TaskQueues := queue.NewTaskQueueSet() TaskQueues.WithContext(context.Background()) - TaskQueues.NewNamedQueue("test_multiple_hooks", func(tsk task.Task) queue.TaskResult { + TaskQueues.NewNamedQueue("test_multiple_hooks", func(_ task.Task) queue.TaskResult { return queue.TaskResult{ Status: "Success", } diff --git a/pkg/shell-operator/http_server.go b/pkg/shell-operator/http_server.go index 506e7e31..ebda8d13 100644 --- a/pkg/shell-operator/http_server.go +++ b/pkg/shell-operator/http_server.go @@ -77,9 +77,9 @@ func newBaseHTTPServer(address, port string) *baseHTTPServer { // inject pprof router.Mount("/debug", middleware.Profiler()) - router.Get("/discovery", func(writer http.ResponseWriter, request *http.Request) { + router.Get("/discovery", func(writer http.ResponseWriter, _ *http.Request) { buf := bytes.NewBuffer(nil) - walkFn := func(method string, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error { + walkFn := func(method string, route string, _ http.Handler, _ ...func(http.Handler) http.Handler) error { // skip pprof routes if strings.HasPrefix(route, "/debug/") { return nil @@ -110,7 +110,7 @@ func newBaseHTTPServer(address, port string) *baseHTTPServer { } func registerRootRoute(op *ShellOperator) { - op.APIServer.RegisterRoute(http.MethodGet, "/", func(writer http.ResponseWriter, request *http.Request) { + op.APIServer.RegisterRoute(http.MethodGet, "/", func(writer http.ResponseWriter, _ *http.Request) { _, _ = fmt.Fprintf(writer, `