diff --git a/cmd/addon-operator/main.go b/cmd/addon-operator/main.go index 2fa9b6ac..b45920f4 100644 --- a/cmd/addon-operator/main.go +++ b/cmd/addon-operator/main.go @@ -14,6 +14,7 @@ import ( "k8s.io/client-go/tools/leaderelection" "k8s.io/client-go/tools/leaderelection/resourcelock" + "github.com/deckhouse/deckhouse/go_lib/log" addon_operator "github.com/flant/addon-operator/pkg/addon-operator" "github.com/flant/addon-operator/pkg/app" "github.com/flant/addon-operator/pkg/kube_config_manager/backend/configmap" @@ -21,7 +22,6 @@ import ( "github.com/flant/kube-client/klogtologrus" sh_app "github.com/flant/shell-operator/pkg/app" "github.com/flant/shell-operator/pkg/debug" - "github.com/flant/shell-operator/pkg/unilogger" utils_signal "github.com/flant/shell-operator/pkg/utils/signal" ) @@ -35,8 +35,8 @@ const ( func main() { kpApp := kingpin.New(app.AppName, fmt.Sprintf("%s %s: %s", app.AppName, app.Version, app.AppDescription)) - logger := unilogger.NewLogger(unilogger.Options{}) - unilogger.SetDefault(logger) + logger := log.NewLogger(log.Options{}) + log.SetDefault(logger) // override usage template to reveal additional commands with information about start command kpApp.UsageTemplate(sh_app.OperatorUsageTemplate(app.AppName)) @@ -66,7 +66,7 @@ func main() { kingpin.MustParse(kpApp.Parse(os.Args[1:])) } -func start(logger *unilogger.Logger) func(_ *kingpin.ParseContext) error { +func start(logger *log.Logger) func(_ *kingpin.ParseContext) error { return func(_ *kingpin.ParseContext) error { sh_app.AppStartMessage = fmt.Sprintf("%s %s, shell-operator %s", app.AppName, app.Version, sh_app.Version) @@ -170,7 +170,7 @@ func runHAMode(ctx context.Context, operator *addon_operator.AddonOperator) { go func() { <-ctx.Done() - unilogger.Info("Context canceled received") + log.Info("Context canceled received") if err := syscall.Kill(1, syscall.SIGUSR2); err != nil { operator.Logger.Fatal("Couldn't shutdown addon-operator", slog.String("error", err.Error())) } diff --git a/go.mod b/go.mod index 914df464..5cdda6b6 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,14 @@ module github.com/flant/addon-operator -go 1.22.4 +go 1.23.1 require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc + github.com/deckhouse/deckhouse/go_lib/log v0.0.0-20241031111821-6d9459d45b78 github.com/dominikbraun/graph v0.23.0 github.com/ettle/strcase v0.2.0 github.com/flant/kube-client v1.2.0 - github.com/flant/shell-operator v1.4.15-slog3 + github.com/flant/shell-operator v0.0.0-20241031112753-639b2cc1e5ad github.com/go-chi/chi/v5 v5.1.0 github.com/go-openapi/loads v0.19.5 github.com/go-openapi/spec v0.19.8 diff --git a/go.sum b/go.sum index 884f0700..28bd36eb 100644 --- a/go.sum +++ b/go.sum @@ -87,6 +87,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/deckhouse/deckhouse/go_lib/log v0.0.0-20241031111821-6d9459d45b78 h1:H5ROFYwvuxE51WzcS9mSKDiD2/6tQCjNExqiUOxLvqY= +github.com/deckhouse/deckhouse/go_lib/log v0.0.0-20241031111821-6d9459d45b78/go.mod h1:okGCqOIU70vDhivVs/UmuSMTdZMHKNTVw2cRAv+Pzqc= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/distribution/distribution/v3 v3.0.0-beta.1 h1:X+ELTxPuZ1Xe5MsD3kp2wfGUhc8I+MPfRis8dZ818Ic= @@ -134,8 +136,8 @@ github.com/flant/kube-client v1.2.0 h1:cOjnZgwoJVm4scqsMGcgO6qctJ+Z6wRVTFqvyhoAO github.com/flant/kube-client v1.2.0/go.mod h1:qjNvqCqnBqS+kc9Hj+wMBbkFzfdyGyiX4r4teE/0Pm8= github.com/flant/libjq-go v1.6.3-0.20201126171326-c46a40ff22ee h1:evii83J+/6QGNvyf6tjQ/p27DPY9iftxIBb37ALJRTg= github.com/flant/libjq-go v1.6.3-0.20201126171326-c46a40ff22ee/go.mod h1:f+REaGl/+pZR97rbTcwHEka/MAipoQQ2Mc0iQUj4ak0= -github.com/flant/shell-operator v1.4.15-slog3 h1:R4UqvjGsHFcFLpCxy9AensPTNWXXy33OtvupJ+rcvgo= -github.com/flant/shell-operator v1.4.15-slog3/go.mod h1:vcq3LKAS3Zg/aMnRzzy7YCJYeRuhfyz3zoSqQRfbotA= +github.com/flant/shell-operator v0.0.0-20241031112753-639b2cc1e5ad h1:3X0Q1SbmOdsZSgaaIZBioR+bCdqDDIeOHj/iUPl1VHw= +github.com/flant/shell-operator v0.0.0-20241031112753-639b2cc1e5ad/go.mod h1:WvORh9wzl30x6LPlqVs+5OuEo04kw+kXMuWgPQKH71I= github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8= github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/foxcpp/go-mockdns v1.0.0 h1:7jBqxd3WDWwi/6WhDvacvH1XsN3rOLXyHM1uhvIx6FI= diff --git a/pkg/addon-operator/admission_http_server.go b/pkg/addon-operator/admission_http_server.go index 45d43eee..dbb0b4d7 100644 --- a/pkg/addon-operator/admission_http_server.go +++ b/pkg/addon-operator/admission_http_server.go @@ -8,7 +8,7 @@ import ( "path" "time" - log "github.com/flant/shell-operator/pkg/unilogger" + log "github.com/deckhouse/deckhouse/go_lib/log" ) type AdmissionServer struct { diff --git a/pkg/addon-operator/bootstrap.go b/pkg/addon-operator/bootstrap.go index 36aa9948..25839ddb 100644 --- a/pkg/addon-operator/bootstrap.go +++ b/pkg/addon-operator/bootstrap.go @@ -1,6 +1,7 @@ package addon_operator import ( + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/app" "github.com/flant/addon-operator/pkg/kube_config_manager" "github.com/flant/addon-operator/pkg/kube_config_manager/backend" @@ -8,7 +9,6 @@ import ( sh_app "github.com/flant/shell-operator/pkg/app" "github.com/flant/shell-operator/pkg/debug" shell_operator "github.com/flant/shell-operator/pkg/shell-operator" - log "github.com/flant/shell-operator/pkg/unilogger" ) // Bootstrap inits all dependencies for a full-fledged AddonOperator instance. diff --git a/pkg/addon-operator/kube_client.go b/pkg/addon-operator/kube_client.go index f5479595..9bb806ee 100644 --- a/pkg/addon-operator/kube_client.go +++ b/pkg/addon-operator/kube_client.go @@ -4,12 +4,12 @@ import ( "context" "fmt" + "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/app" "github.com/flant/addon-operator/pkg/helm_resources_manager" klient "github.com/flant/kube-client/client" sh_app "github.com/flant/shell-operator/pkg/app" "github.com/flant/shell-operator/pkg/metric_storage" - "github.com/flant/shell-operator/pkg/unilogger" utils "github.com/flant/shell-operator/pkg/utils/labels" ) @@ -28,7 +28,7 @@ func defaultHelmMonitorKubeClient(metricStorage *metric_storage.MetricStorage, m return client } -func InitDefaultHelmResourcesManager(ctx context.Context, metricStorage *metric_storage.MetricStorage, logger *unilogger.Logger) (helm_resources_manager.HelmResourcesManager, error) { +func InitDefaultHelmResourcesManager(ctx context.Context, metricStorage *metric_storage.MetricStorage, logger *log.Logger) (helm_resources_manager.HelmResourcesManager, error) { kubeClient := defaultHelmMonitorKubeClient(metricStorage, DefaultHelmMonitorKubeClientMetricLabels) if err := kubeClient.Init(); err != nil { return nil, fmt.Errorf("initialize Kubernetes client for Helm resources manager: %s\n", err) diff --git a/pkg/addon-operator/operator.go b/pkg/addon-operator/operator.go index 691c67d2..1c385df8 100644 --- a/pkg/addon-operator/operator.go +++ b/pkg/addon-operator/operator.go @@ -15,6 +15,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/tools/leaderelection" + "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/addon-operator/converge" "github.com/flant/addon-operator/pkg/app" "github.com/flant/addon-operator/pkg/helm" @@ -45,7 +46,6 @@ import ( shell_operator "github.com/flant/shell-operator/pkg/shell-operator" sh_task "github.com/flant/shell-operator/pkg/task" "github.com/flant/shell-operator/pkg/task/queue" - "github.com/flant/shell-operator/pkg/unilogger" fileUtils "github.com/flant/shell-operator/pkg/utils/file" "github.com/flant/shell-operator/pkg/utils/measure" ) @@ -102,7 +102,7 @@ type AddonOperator struct { // discoveredGVKs is a map of GVKs from applied modules' CRDs discoveredGVKs map[string]struct{} - Logger *unilogger.Logger + Logger *log.Logger } type parallelQueueEvent struct { @@ -135,7 +135,7 @@ func (pq *parallelTaskChannels) Delete(id string) { pq.l.Unlock() } -func NewAddonOperator(ctx context.Context, logger *unilogger.Logger) *AddonOperator { +func NewAddonOperator(ctx context.Context, logger *log.Logger) *AddonOperator { cctx, cancel := context.WithCancel(ctx) so := shell_operator.NewShellOperator(cctx, logger.Named("shell-operator")) @@ -220,7 +220,7 @@ func (op *AddonOperator) Setup() error { if err != nil { return fmt.Errorf("global hooks directory: %s", err) } - unilogger.Infof("Global hooks directory: %s", globalHooksDir) + log.Infof("Global hooks directory: %s", globalHooksDir) tempDir, err := fileUtils.EnsureTempDirectory(sh_app.TempDir) if err != nil { @@ -243,7 +243,7 @@ func (op *AddonOperator) Start(_ context.Context) error { return err } - unilogger.Info("Start first converge for modules") + log.Info("Start first converge for modules") // Loading the onStartup hooks into the queue and running all modules. // Turning tracking changes on only after startup ends. @@ -920,12 +920,12 @@ func (op *AddonOperator) CreateAndStartQueuesForGlobalHooks() { h := op.ModuleManager.GetGlobalHook(hookName) for _, hookBinding := range h.GetHookConfig().Schedules { if op.CreateAndStartQueue(hookBinding.Queue) { - unilogger.Debugf("Queue '%s' started for global 'schedule' hook %s", hookBinding.Queue, hookName) + log.Debugf("Queue '%s' started for global 'schedule' hook %s", hookBinding.Queue, hookName) } } for _, hookBinding := range h.GetHookConfig().OnKubernetesEvents { if op.CreateAndStartQueue(hookBinding.Queue) { - unilogger.Debugf("Queue '%s' started for global 'kubernetes' hook %s", hookBinding.Queue, hookName) + log.Debugf("Queue '%s' started for global 'kubernetes' hook %s", hookBinding.Queue, hookName) } } } @@ -944,7 +944,7 @@ func (op *AddonOperator) CreateAndStartQueuesForModuleHooks(moduleName string) { for _, hook := range scheduleHooks { for _, hookBinding := range hook.GetHookConfig().Schedules { if op.CreateAndStartQueue(hookBinding.Queue) { - unilogger.Debugf("Queue '%s' started for module 'schedule' hook %s", hookBinding.Queue, hook.GetName()) + log.Debugf("Queue '%s' started for module 'schedule' hook %s", hookBinding.Queue, hook.GetName()) } } } @@ -953,7 +953,7 @@ func (op *AddonOperator) CreateAndStartQueuesForModuleHooks(moduleName string) { for _, hook := range kubeEventsHooks { for _, hookBinding := range hook.GetHookConfig().OnKubernetesEvents { if op.CreateAndStartQueue(hookBinding.Queue) { - unilogger.Debugf("Queue '%s' started for module 'kubernetes' hook %s", hookBinding.Queue, hook.GetName()) + log.Debugf("Queue '%s' started for module 'kubernetes' hook %s", hookBinding.Queue, hook.GetName()) } } } @@ -964,12 +964,12 @@ func (op *AddonOperator) CreateAndStartQueuesForModuleHooks(moduleName string) { // h := op.ModuleManager.GetModuleHook(hookName) // for _, hookBinding := range h.Config.Schedules { // if op.CreateAndStartQueue(hookBinding.Queue) { - // unilogger.Debugf("Queue '%s' started for module 'schedule' hook %s", hookBinding.Queue, hookName) + // log.Debugf("Queue '%s' started for module 'schedule' hook %s", hookBinding.Queue, hookName) // } // } // for _, hookBinding := range h.Config.OnKubernetesEvents { // if op.CreateAndStartQueue(hookBinding.Queue) { - // unilogger.Debugf("Queue '%s' started for module 'kubernetes' hook %s", hookBinding.Queue, hookName) + // log.Debugf("Queue '%s' started for module 'kubernetes' hook %s", hookBinding.Queue, hookName) // } // } //} @@ -980,7 +980,7 @@ func (op *AddonOperator) CreateAndStartParallelQueues() { for i := 0; i < app.NumberOfParallelQueues; i++ { queueName := fmt.Sprintf(app.ParallelQueueNamePattern, i) if op.engine.TaskQueues.GetByName(queueName) != nil { - unilogger.Warnf("Parallel queue %s already exists", queueName) + log.Warnf("Parallel queue %s already exists", queueName) continue } op.engine.TaskQueues.NewNamedQueue(queueName, op.ParallelTasksHandler) @@ -991,7 +991,7 @@ func (op *AddonOperator) CreateAndStartParallelQueues() { func (op *AddonOperator) DrainModuleQueues(modName string) { m := op.ModuleManager.GetModule(modName) if m == nil { - unilogger.Warnf("Module %q is absent when we try to drain its queue", modName) + log.Warnf("Module %q is absent when we try to drain its queue", modName) return } @@ -1465,7 +1465,7 @@ func (op *AddonOperator) HandleGlobalHookEnableKubernetesBindings(t sh_task.Task for _, tsk := range parallelSyncTasksToWait { q := op.engine.TaskQueues.GetByName(tsk.GetQueueName()) if q == nil { - unilogger.Errorf("Queue %s is not created while run GlobalHookEnableKubernetesBindings task!", tsk.GetQueueName()) + log.Errorf("Queue %s is not created while run GlobalHookEnableKubernetesBindings task!", tsk.GetQueueName()) } else { // Skip state creation if WaitForSynchronization is disabled. thm := task.HookMetadataAccessor(tsk) @@ -1478,7 +1478,7 @@ func (op *AddonOperator) HandleGlobalHookEnableKubernetesBindings(t sh_task.Task for _, tsk := range parallelSyncTasks { q := op.engine.TaskQueues.GetByName(tsk.GetQueueName()) if q == nil { - unilogger.Errorf("Queue %s is not created while run GlobalHookEnableKubernetesBindings task!", tsk.GetQueueName()) + log.Errorf("Queue %s is not created while run GlobalHookEnableKubernetesBindings task!", tsk.GetQueueName()) } else { q.AddLast(tsk) } @@ -2394,7 +2394,7 @@ func (op *AddonOperator) CreateConvergeModulesTasks(state *module_manager.Module queuedAt := time.Now() // Add ModuleDelete tasks to delete helm releases of disabled modules. - unilogger.Debugf("The following modules are going to be disabled: %v", state.ModulesToDisable) + log.Debugf("The following modules are going to be disabled: %v", state.ModulesToDisable) for _, moduleName := range state.ModulesToDisable { ev := events.ModuleEvent{ ModuleName: moduleName, @@ -2417,7 +2417,7 @@ func (op *AddonOperator) CreateConvergeModulesTasks(state *module_manager.Module // Add ModuleRun tasks to install or reload enabled modules. newlyEnabled := utils.ListToMapStringStruct(state.ModulesToEnable) - unilogger.Debugf("The following modules are going to be enabled/rerun: %v", state.AllEnabledModulesByOrder) + log.Debugf("The following modules are going to be enabled/rerun: %v", state.AllEnabledModulesByOrder) // sort modules' orders sortedOrders := make(node.NodeWeightRange, 0, len(state.AllEnabledModulesByOrder)) for order := range state.AllEnabledModulesByOrder { @@ -2509,13 +2509,13 @@ func (op *AddonOperator) CreateConvergeModulesTasks(state *module_manager.Module modulesTasks = append(modulesTasks, newTask.WithQueuedAt(queuedAt)) default: - unilogger.Errorf("Invalid ModulesState %v", state) + log.Errorf("Invalid ModulesState %v", state) } } // as resultingTasks contains new ensureCRDsTasks we invalidate // ConvregeState.CRDsEnsured if there are new ensureCRDsTasks to execute if op.ConvergeState.CRDsEnsured && len(resultingTasks) > 0 { - unilogger.Debug("CheckCRDsEnsured: set to false") + log.Debug("CheckCRDsEnsured: set to false") op.ConvergeState.CRDsEnsured = false } @@ -2530,7 +2530,7 @@ func (op *AddonOperator) CreateConvergeModulesTasks(state *module_manager.Module // the discovered GVKs func (op *AddonOperator) CheckCRDsEnsured(t sh_task.Task) { if !op.ConvergeState.CRDsEnsured && !ModuleEnsureCRDsTasksInQueueAfterId(op.engine.TaskQueues.GetMain(), t.GetId()) { - unilogger.Debug("CheckCRDsEnsured: set to true") + log.Debug("CheckCRDsEnsured: set to true") op.ConvergeState.CRDsEnsured = true // apply global values patch op.discoveredGVKsLock.Lock() @@ -2573,7 +2573,7 @@ func (op *AddonOperator) CheckConvergeStatus(t sh_task.Task) { // Report modules left to process. if convergeTasks > 0 && (t.GetType() == task.ModuleRun || t.GetType() == task.ModuleDelete) { moduleTasks := ConvergeModulesInQueue(op.engine.TaskQueues.GetMain()) - unilogger.Infof("Converge modules in progress: %d modules left to process in queue 'main'", moduleTasks) + log.Infof("Converge modules in progress: %d modules left to process in queue 'main'", moduleTasks) } } @@ -2591,7 +2591,7 @@ func (op *AddonOperator) UpdateFirstConvergeStatus(convergeTasks int) { case converge.FirstStarted: // Switch to 'done' state after first converge is started and when no 'converge' tasks left in the queue. if convergeTasks == 0 { - unilogger.Infof("First converge is finished. Operator is ready now.") + log.Infof("First converge is finished. Operator is ready now.") op.ConvergeState.SetFirstRunPhase(converge.FirstDone) } } @@ -2703,7 +2703,7 @@ func taskDescriptionForTaskFlowLog(tsk sh_task.Task, action string, phase string } // logTaskAdd prints info about queued tasks. -func (op *AddonOperator) logTaskAdd(logEntry *unilogger.Logger, action string, tasks ...sh_task.Task) { +func (op *AddonOperator) logTaskAdd(logEntry *log.Logger, action string, tasks ...sh_task.Task) { logger := logEntry.With("task.flow", "add") for _, tsk := range tasks { logger.Info(taskDescriptionForTaskFlowLog(tsk, action, "", "")) @@ -2711,7 +2711,7 @@ func (op *AddonOperator) logTaskAdd(logEntry *unilogger.Logger, action string, t } // logTaskStart prints info about task at start. Also prints event source info from task props. -func (op *AddonOperator) logTaskStart(logEntry *unilogger.Logger, tsk sh_task.Task) { +func (op *AddonOperator) logTaskStart(logEntry *log.Logger, tsk sh_task.Task) { // Prevent excess messages for highly frequent tasks. if tsk.GetType() == task.GlobalHookWaitKubernetesSynchronization { return @@ -2739,14 +2739,14 @@ func (op *AddonOperator) logTaskStart(logEntry *unilogger.Logger, tsk sh_task.Ta } // logTaskEnd prints info about task at the end. Info level used only for the ConvergeModules task. -func (op *AddonOperator) logTaskEnd(logEntry *unilogger.Logger, tsk sh_task.Task, result queue.TaskResult) { +func (op *AddonOperator) logTaskEnd(logEntry *log.Logger, tsk sh_task.Task, result queue.TaskResult) { logger := logEntry. With("task.flow", "end") logger = utils.EnrichLoggerWithLabels(logger, tsk.GetLogLabels()) - level := unilogger.LevelDebug + level := log.LevelDebug if tsk.GetType() == task.ConvergeModules { - level = unilogger.LevelInfo + level = log.LevelInfo } logger.Log(context.TODO(), level.Level(), taskDescriptionForTaskFlowLog(tsk, "end", op.taskPhase(tsk), string(result.Status))) diff --git a/pkg/addon-operator/operator_test.go b/pkg/addon-operator/operator_test.go index 578e55a2..71891066 100644 --- a/pkg/addon-operator/operator_test.go +++ b/pkg/addon-operator/operator_test.go @@ -14,6 +14,7 @@ import ( k8types "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/yaml" + "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/addon-operator/converge" mockhelm "github.com/flant/addon-operator/pkg/helm/test/mock" mockhelmresmgr "github.com/flant/addon-operator/pkg/helm_resources_manager/test/mock" @@ -27,7 +28,6 @@ import ( . "github.com/flant/shell-operator/pkg/hook/types" sh_task "github.com/flant/shell-operator/pkg/task" "github.com/flant/shell-operator/pkg/task/queue" - "github.com/flant/shell-operator/pkg/unilogger" file_utils "github.com/flant/shell-operator/pkg/utils/file" ) @@ -102,7 +102,7 @@ func assembleTestAddonOperator(t *testing.T, configPath string) (*AddonOperator, g.Expect(err).ShouldNot(HaveOccurred(), "Should create ConfigMap/%s", result.cmName) // Assemble AddonOperator. - op := NewAddonOperator(context.Background(), unilogger.NewNop()) + op := NewAddonOperator(context.Background(), log.NewNop()) op.engine.KubeClient = kubeClient // Mock helm client for ModuleManager result.helmClient = &mockhelm.Client{} @@ -113,8 +113,8 @@ func assembleTestAddonOperator(t *testing.T, configPath string) (*AddonOperator, op.engine.SetupEventManagers() - bk := configmap.New(unilogger.NewNop(), op.engine.KubeClient, result.cmNamespace, result.cmName) - manager := kube_config_manager.NewKubeConfigManager(op.ctx, bk, op.runtimeConfig, unilogger.NewNop()) + bk := configmap.New(log.NewNop(), op.engine.KubeClient, result.cmNamespace, result.cmName) + manager := kube_config_manager.NewKubeConfigManager(op.ctx, bk, op.runtimeConfig, log.NewNop()) op.KubeConfigManager = manager dirs := module_manager.DirectoryConfig{ @@ -136,7 +136,7 @@ func assembleTestAddonOperator(t *testing.T, configPath string) (*AddonOperator, DirectoryConfig: dirs, Dependencies: deps, } - op.ModuleManager = module_manager.NewModuleManager(op.ctx, &cfg, unilogger.NewNop()) + op.ModuleManager = module_manager.NewModuleManager(op.ctx, &cfg, log.NewNop()) err = op.InitModuleManager() g.Expect(err).ShouldNot(HaveOccurred(), "Should init ModuleManager") @@ -165,7 +165,7 @@ func convergeDone(op *AddonOperator) func(g Gomega) bool { // TaskRunner should run all hooks and clean the queue. func Test_Operator_startup_tasks(t *testing.T) { g := NewWithT(t) - unilogger.SetDefaultLevel(unilogger.LevelError) + log.SetDefaultLevel(log.LevelError) op, _ := assembleTestAddonOperator(t, "startup_tasks") @@ -214,7 +214,7 @@ func Test_Operator_startup_tasks(t *testing.T) { func Test_Operator_ConvergeModules_main_queue_only(t *testing.T) { g := NewWithT(t) // Mute messages about registration and tasks queueing. - unilogger.SetDefaultLevel(unilogger.LevelError) + log.SetDefaultLevel(log.LevelError) op, res := assembleTestAddonOperator(t, "converge__main_queue_only") @@ -346,7 +346,7 @@ func Test_Operator_ConvergeModules_main_queue_only(t *testing.T) { func Test_HandleConvergeModules_global_changed_during_converge(t *testing.T) { g := NewWithT(t) // Mute messages about registration and tasks queueing. - unilogger.SetDefaultLevel(unilogger.LevelError) + log.SetDefaultLevel(log.LevelError) op, res := assembleTestAddonOperator(t, "converge__main_queue_only") @@ -458,7 +458,7 @@ func Test_HandleConvergeModules_global_changed_during_converge(t *testing.T) { func Test_HandleConvergeModules_global_changed(t *testing.T) { g := NewWithT(t) // Mute messages about registration and tasks queueing. - unilogger.SetDefaultLevel(unilogger.LevelError) + log.SetDefaultLevel(log.LevelError) op, res := assembleTestAddonOperator(t, "converge__main_queue_only") @@ -512,7 +512,7 @@ func Test_HandleConvergeModules_global_changed(t *testing.T) { g.Eventually(convergeDone(op), "30s", "200ms").Should(BeTrue()) - unilogger.Infof("Converge done, got %d tasks in history", len(taskHandleHistory)) + log.Infof("Converge done, got %d tasks in history", len(taskHandleHistory)) // Save current history length to ignore first converge tasks later. ignoreTasksCount := len(taskHandleHistory) @@ -533,7 +533,7 @@ func Test_HandleConvergeModules_global_changed(t *testing.T) { g.Expect(cmPatched.Data).Should(HaveKey("global")) g.Expect(cmPatched.Data["global"]).Should(Equal("param: newValue")) - unilogger.Infof("ConfigMap patched, got %d tasks in history", len(taskHandleHistory)) + log.Infof("ConfigMap patched, got %d tasks in history", len(taskHandleHistory)) // Expect ConvergeModules appears in queue. g.Eventually(func() bool { @@ -579,10 +579,10 @@ func Test_HandleConvergeModules_global_changed(t *testing.T) { // g := NewWithT(t) // // Catch all info messages. -// unilogger.SetDefaultLevel(unilogger.LevelError) -// unilogger.SetOutput(io.Discard) +// log.SetDefaultLevel(log.LevelError) +// log.SetOutput(io.Discard) // logHook := new(logrus_test.Hook) -// unilogger.AddHook(logHook) +// log.AddHook(logHook) // op, _ := assembleTestAddonOperator(t, "log_task__wait_for_synchronization") // op.BootstrapMainQueue(op.engine.TaskQueues) @@ -596,7 +596,7 @@ func Test_HandleConvergeModules_global_changed(t *testing.T) { // hasWaitForSynchronizationMessages := false // for _, entry := range logHook.Entries { -// if strings.Contains(entry.Message, "WaitForSynchronization") && entry.Level < unilogger.Level { +// if strings.Contains(entry.Message, "WaitForSynchronization") && entry.Level < log.Level { // hasWaitForSynchronizationMessages = true // } // } diff --git a/pkg/addon-operator/queue.go b/pkg/addon-operator/queue.go index c19dd67e..c411ea4e 100644 --- a/pkg/addon-operator/queue.go +++ b/pkg/addon-operator/queue.go @@ -1,12 +1,12 @@ package addon_operator import ( + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/addon-operator/converge" "github.com/flant/addon-operator/pkg/task" "github.com/flant/addon-operator/pkg/utils" sh_task "github.com/flant/shell-operator/pkg/task" "github.com/flant/shell-operator/pkg/task/queue" - log "github.com/flant/shell-operator/pkg/unilogger" ) // QueueHasPendingModuleRunTask returns true if queue has pending tasks diff --git a/pkg/addon-operator/queue_test.go b/pkg/addon-operator/queue_test.go index 88143ca2..fd076ee7 100644 --- a/pkg/addon-operator/queue_test.go +++ b/pkg/addon-operator/queue_test.go @@ -5,10 +5,10 @@ import ( "github.com/stretchr/testify/require" + "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/task" sh_task "github.com/flant/shell-operator/pkg/task" "github.com/flant/shell-operator/pkg/task/queue" - "github.com/flant/shell-operator/pkg/unilogger" ) func Test_ModuleEnsureCRDsTasksInQueueAfterId(t *testing.T) { @@ -269,7 +269,7 @@ func Test_RemoveAdjacentConvergeModules(t *testing.T) { } require.Equal(t, len(tt.in), q.Length(), "Should add all tasks to the queue.") - RemoveAdjacentConvergeModules(q, tt.afterID, map[string]string{}, unilogger.NewNop()) + RemoveAdjacentConvergeModules(q, tt.afterID, map[string]string{}, log.NewNop()) // Check tasks after remove. require.Equal(t, len(tt.expect), q.Length(), "queue length should match length of expected tasks") @@ -511,7 +511,7 @@ func Test_RemoveCurrentConvergeTasks(t *testing.T) { } // Try to clean the queue. - removed := RemoveCurrentConvergeTasks(queues, map[string]string{}, unilogger.NewNop()) + removed := RemoveCurrentConvergeTasks(queues, map[string]string{}, log.NewNop()) // Check result. if tt.expectRemoved { @@ -634,7 +634,7 @@ func Test_RemoveCurrentConvergeTasksFromId(t *testing.T) { require.Equal(t, len(tt.initialTasks), q.Length(), "Should add all tasks to the queue.") // Try to clean the queue. - removed := RemoveCurrentConvergeTasksFromId(q, currentTaskID, map[string]string{}, unilogger.NewNop()) + removed := RemoveCurrentConvergeTasksFromId(q, currentTaskID, map[string]string{}, log.NewNop()) // Check result. if tt.expectRemoved { diff --git a/pkg/helm/helm.go b/pkg/helm/helm.go index b28a6ff7..706de4d9 100644 --- a/pkg/helm/helm.go +++ b/pkg/helm/helm.go @@ -1,11 +1,11 @@ package helm import ( + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/app" "github.com/flant/addon-operator/pkg/helm/client" "github.com/flant/addon-operator/pkg/helm/helm3" "github.com/flant/addon-operator/pkg/helm/helm3lib" - log "github.com/flant/shell-operator/pkg/unilogger" ) type ClientFactory struct { diff --git a/pkg/helm/helm3/helm3.go b/pkg/helm/helm3/helm3.go index 64bc99a2..cad2558c 100644 --- a/pkg/helm/helm3/helm3.go +++ b/pkg/helm/helm3/helm3.go @@ -10,11 +10,11 @@ import ( k8syaml "sigs.k8s.io/yaml" + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/app" "github.com/flant/addon-operator/pkg/helm/client" "github.com/flant/addon-operator/pkg/utils" "github.com/flant/shell-operator/pkg/executor" - log "github.com/flant/shell-operator/pkg/unilogger" ) var Helm3Path = "helm" diff --git a/pkg/helm/helm3lib/helm3lib.go b/pkg/helm/helm3lib/helm3lib.go index 6386c27a..54e15580 100644 --- a/pkg/helm/helm3lib/helm3lib.go +++ b/pkg/helm/helm3lib/helm3lib.go @@ -22,11 +22,11 @@ import ( "k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/client-go/rest" + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/app" "github.com/flant/addon-operator/pkg/helm/client" "github.com/flant/addon-operator/pkg/helm/post_renderer" "github.com/flant/addon-operator/pkg/utils" - log "github.com/flant/shell-operator/pkg/unilogger" ) var helmPostRenderer *post_renderer.PostRenderer diff --git a/pkg/helm/helm3lib/helm3lib_test.go b/pkg/helm/helm3lib/helm3lib_test.go index 1f937ebf..e35c1073 100644 --- a/pkg/helm/helm3lib/helm3lib_test.go +++ b/pkg/helm/helm3lib/helm3lib_test.go @@ -4,6 +4,7 @@ import ( "io" "testing" + "github.com/deckhouse/deckhouse/go_lib/log" . "github.com/onsi/gomega" "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/chartutil" @@ -12,8 +13,6 @@ import ( "helm.sh/helm/v3/pkg/registry" "helm.sh/helm/v3/pkg/storage" "helm.sh/helm/v3/pkg/storage/driver" - - "github.com/flant/shell-operator/pkg/unilogger" ) func TestHelm3LibEmptyCluster(t *testing.T) { @@ -68,12 +67,12 @@ func initHelmClient(t *testing.T) *LibClient { Namespace: "test-ns", HistoryMax: 10, Timeout: 0, - }, unilogger.NewNop(), map[string]string{}) + }, log.NewNop(), map[string]string{}) actionConfig = actionConfigFixture(t) cl := &LibClient{ - LogEntry: unilogger.NewNop(), + LogEntry: log.NewNop(), Namespace: options.Namespace, } diff --git a/pkg/helm/helm_test.go b/pkg/helm/helm_test.go index 73e1253f..fa3a3e6a 100644 --- a/pkg/helm/helm_test.go +++ b/pkg/helm/helm_test.go @@ -6,10 +6,10 @@ import ( . "github.com/onsi/gomega" + "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/app" "github.com/flant/addon-operator/pkg/helm/helm3" "github.com/flant/addon-operator/pkg/helm/helm3lib" - "github.com/flant/shell-operator/pkg/unilogger" ) func TestHelmFactory(t *testing.T) { @@ -24,11 +24,11 @@ func TestHelmFactory(t *testing.T) { // For integration tests, but should be set before init app.Namespace = os.Getenv("ADDON_OPERATOR_NAMESPACE") // Setup Helm client factory. - helm, err := InitHelmClientFactory(unilogger.NewNop(), map[string]string{}) + helm, err := InitHelmClientFactory(log.NewNop(), map[string]string{}) g.Expect(err).ShouldNot(HaveOccurred()) // Ensure client is a builtin Helm3 library. - helmCl := helm.NewClient(unilogger.NewNop()) + helmCl := helm.NewClient(log.NewNop()) g.Expect(helmCl).To(BeAssignableToTypeOf(clientType), "should create %s client", name) if os.Getenv("ADDON_OPERATOR_HELM_INTEGRATION_TEST") != "yes" { diff --git a/pkg/helm/test/mock/mock.go b/pkg/helm/test/mock/mock.go index 5e460a1f..7742bf4a 100644 --- a/pkg/helm/test/mock/mock.go +++ b/pkg/helm/test/mock/mock.go @@ -1,15 +1,15 @@ package mock import ( + "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/helm" "github.com/flant/addon-operator/pkg/helm/client" "github.com/flant/addon-operator/pkg/utils" - "github.com/flant/shell-operator/pkg/unilogger" ) func NewClientFactory(cl client.HelmClient) *helm.ClientFactory { return &helm.ClientFactory{ - NewClientFn: func(_ *unilogger.Logger, _ ...map[string]string) client.HelmClient { + NewClientFn: func(_ *log.Logger, _ ...map[string]string) client.HelmClient { return cl }, } diff --git a/pkg/helm_resources_manager/helm_resources_manager.go b/pkg/helm_resources_manager/helm_resources_manager.go index 84708cf5..b582ee5c 100644 --- a/pkg/helm_resources_manager/helm_resources_manager.go +++ b/pkg/helm_resources_manager/helm_resources_manager.go @@ -7,11 +7,11 @@ import ( "k8s.io/apimachinery/pkg/labels" cr_cache "sigs.k8s.io/controller-runtime/pkg/cache" + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/app" . "github.com/flant/addon-operator/pkg/helm_resources_manager/types" klient "github.com/flant/kube-client/client" "github.com/flant/kube-client/manifest" - log "github.com/flant/shell-operator/pkg/unilogger" ) type HelmResourcesManager interface { diff --git a/pkg/helm_resources_manager/resources_monitor.go b/pkg/helm_resources_manager/resources_monitor.go index e4851a11..c5eebf7e 100644 --- a/pkg/helm_resources_manager/resources_monitor.go +++ b/pkg/helm_resources_manager/resources_monitor.go @@ -13,10 +13,10 @@ import ( cr_cache "sigs.k8s.io/controller-runtime/pkg/cache" cr_client "sigs.k8s.io/controller-runtime/pkg/client" + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/utils" klient "github.com/flant/kube-client/client" "github.com/flant/kube-client/manifest" - log "github.com/flant/shell-operator/pkg/unilogger" ) const monitorDelayBase = time.Minute*4 + time.Second*30 diff --git a/pkg/kube_config_manager/backend/configmap/configmap.go b/pkg/kube_config_manager/backend/configmap/configmap.go index 68ea3eb4..9476f17d 100644 --- a/pkg/kube_config_manager/backend/configmap/configmap.go +++ b/pkg/kube_config_manager/backend/configmap/configmap.go @@ -14,10 +14,10 @@ import ( corev1 "k8s.io/client-go/informers/core/v1" "k8s.io/client-go/tools/cache" + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/kube_config_manager/config" "github.com/flant/addon-operator/pkg/utils" "github.com/flant/kube-client/client" - log "github.com/flant/shell-operator/pkg/unilogger" ) // Backend implements ConfigMap backend for kube_config_manager diff --git a/pkg/kube_config_manager/kube_config_manager.go b/pkg/kube_config_manager/kube_config_manager.go index 5254bb41..ecf8e9cd 100644 --- a/pkg/kube_config_manager/kube_config_manager.go +++ b/pkg/kube_config_manager/kube_config_manager.go @@ -7,11 +7,11 @@ import ( "strconv" "sync" + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/kube_config_manager/backend" "github.com/flant/addon-operator/pkg/kube_config_manager/config" "github.com/flant/addon-operator/pkg/utils" runtimeConfig "github.com/flant/shell-operator/pkg/config" - log "github.com/flant/shell-operator/pkg/unilogger" ) // KubeConfigManager watches for changes in ConfigMap/addon-operator and provides diff --git a/pkg/kube_config_manager/kube_config_manager_test.go b/pkg/kube_config_manager/kube_config_manager_test.go index 7b25f338..be1f4cd8 100644 --- a/pkg/kube_config_manager/kube_config_manager_test.go +++ b/pkg/kube_config_manager/kube_config_manager_test.go @@ -11,11 +11,11 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/kube_config_manager/backend/configmap" "github.com/flant/addon-operator/pkg/kube_config_manager/config" "github.com/flant/addon-operator/pkg/utils" klient "github.com/flant/kube-client/client" - "github.com/flant/shell-operator/pkg/unilogger" ) const testConfigMapName = "test-addon-operator" @@ -40,8 +40,8 @@ func initKubeConfigManager(t *testing.T, kubeClient *klient.Client, cmData map[s _, err := kubeClient.CoreV1().ConfigMaps("default").Create(context.TODO(), cm, metav1.CreateOptions{}) g.Expect(err).ShouldNot(HaveOccurred(), "ConfigMap should be created") - bk := configmap.New(unilogger.NewNop(), kubeClient, "default", testConfigMapName) - kcm := NewKubeConfigManager(context.Background(), bk, nil, unilogger.NewNop()) + bk := configmap.New(log.NewNop(), kubeClient, "default", testConfigMapName) + kcm := NewKubeConfigManager(context.Background(), bk, nil, log.NewNop()) err = kcm.Init() g.Expect(err).ShouldNot(HaveOccurred(), "KubeConfigManager should init correctly") diff --git a/pkg/module_manager/go_hook/go_hook.go b/pkg/module_manager/go_hook/go_hook.go index 394c1883..13a893a4 100644 --- a/pkg/module_manager/go_hook/go_hook.go +++ b/pkg/module_manager/go_hook/go_hook.go @@ -9,10 +9,10 @@ import ( v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/module_manager/go_hook/metrics" "github.com/flant/shell-operator/pkg/kube/object_patch" "github.com/flant/shell-operator/pkg/kube_events_manager/types" - "github.com/flant/shell-operator/pkg/unilogger" ) type GoHook interface { @@ -54,24 +54,24 @@ type ILogger interface { Errorf(format string, args ...any) Fatal(msg string, args ...any) Fatalf(format string, args ...any) - GetLevel() unilogger.Level + GetLevel() log.Level Handler() slog.Handler Info(msg string, args ...any) InfoContext(ctx context.Context, msg string, args ...any) Infof(format string, args ...any) Log(ctx context.Context, level slog.Level, msg string, args ...any) LogAttrs(ctx context.Context, level slog.Level, msg string, attrs ...slog.Attr) - Logf(ctx context.Context, level unilogger.Level, format string, args ...any) - Named(name string) *unilogger.Logger - SetLevel(level unilogger.Level) + Logf(ctx context.Context, level log.Level, format string, args ...any) + Named(name string) *log.Logger + SetLevel(level log.Level) SetOutput(w io.Writer) Trace(msg string, args ...any) Tracef(format string, args ...any) Warn(msg string, args ...any) WarnContext(ctx context.Context, msg string, args ...any) Warnf(format string, args ...any) - With(args ...any) *unilogger.Logger - WithGroup(name string) *unilogger.Logger + With(args ...any) *log.Logger + WithGroup(name string) *log.Logger } type HookInput struct { @@ -106,7 +106,7 @@ type HookConfig struct { AllowFailure bool Queue string Settings *HookConfigSettings - Logger *unilogger.Logger + Logger *log.Logger } type HookConfigSettings struct { diff --git a/pkg/module_manager/go_hook/patchable_values.go b/pkg/module_manager/go_hook/patchable_values.go index 5dcae99a..55fb7fd0 100644 --- a/pkg/module_manager/go_hook/patchable_values.go +++ b/pkg/module_manager/go_hook/patchable_values.go @@ -7,8 +7,8 @@ import ( "github.com/tidwall/gjson" + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/utils" - log "github.com/flant/shell-operator/pkg/unilogger" ) type PatchableValues struct { diff --git a/pkg/module_manager/loader/fs/fs.go b/pkg/module_manager/loader/fs/fs.go index 476941f3..e4ad4592 100644 --- a/pkg/module_manager/loader/fs/fs.go +++ b/pkg/module_manager/loader/fs/fs.go @@ -9,10 +9,10 @@ import ( "strconv" "strings" + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/app" "github.com/flant/addon-operator/pkg/module_manager/models/modules" "github.com/flant/addon-operator/pkg/utils" - log "github.com/flant/shell-operator/pkg/unilogger" ) type FileSystemLoader struct { diff --git a/pkg/module_manager/loader/fs/fs_test.go b/pkg/module_manager/loader/fs/fs_test.go index a5389749..7cad58c9 100644 --- a/pkg/module_manager/loader/fs/fs_test.go +++ b/pkg/module_manager/loader/fs/fs_test.go @@ -5,11 +5,10 @@ import ( "path/filepath" "testing" + "github.com/deckhouse/deckhouse/go_lib/log" . "github.com/onsi/gomega" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "github.com/flant/shell-operator/pkg/unilogger" ) func TestNewFileSystemLoader(t *testing.T) { @@ -45,7 +44,7 @@ fooBar: `), 0o666) require.NoError(t, err) - loader := NewFileSystemLoader(filepath.Join(tmpDir, "modules"), unilogger.NewNop()) + loader := NewFileSystemLoader(filepath.Join(tmpDir, "modules"), log.NewNop()) modules, err := loader.LoadModules() require.NoError(t, err) m := modules[0] @@ -61,7 +60,7 @@ func TestDirWithSymlinks(t *testing.T) { g := NewWithT(t) dir := "testdata/module_loader/dir1" - ld := NewFileSystemLoader(dir, unilogger.NewNop()) + ld := NewFileSystemLoader(dir, log.NewNop()) mods, err := ld.LoadModules() g.Expect(err).ShouldNot(HaveOccurred()) @@ -73,7 +72,7 @@ func TestLoadMultiDir(t *testing.T) { g := NewWithT(t) dirs := "testdata/module_loader/dir2:testdata/module_loader/dir3" - ld := NewFileSystemLoader(dirs, unilogger.NewNop()) + ld := NewFileSystemLoader(dirs, log.NewNop()) mods, err := ld.LoadModules() g.Expect(err).ShouldNot(HaveOccurred()) diff --git a/pkg/module_manager/models/hooks/kind/gohook.go b/pkg/module_manager/models/hooks/kind/gohook.go index e04d3881..0ee3ca05 100644 --- a/pkg/module_manager/models/hooks/kind/gohook.go +++ b/pkg/module_manager/models/hooks/kind/gohook.go @@ -3,6 +3,7 @@ package kind import ( "context" + "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/module_manager/go_hook" "github.com/flant/addon-operator/pkg/module_manager/go_hook/metrics" "github.com/flant/addon-operator/pkg/utils" @@ -11,7 +12,6 @@ import ( "github.com/flant/shell-operator/pkg/hook/config" "github.com/flant/shell-operator/pkg/hook/controller" "github.com/flant/shell-operator/pkg/kube/object_patch" - "github.com/flant/shell-operator/pkg/unilogger" ) type GoHook struct { @@ -25,7 +25,7 @@ type GoHook struct { func NewGoHook(config *go_hook.HookConfig, f ReconcileFunc) *GoHook { logger := config.Logger if logger == nil { - logger = unilogger.NewLogger(unilogger.Options{}).Named("auto-hook-logger") + logger = log.NewLogger(log.Options{}).Named("auto-hook-logger") } return &GoHook{ diff --git a/pkg/module_manager/models/hooks/kind/shellhook.go b/pkg/module_manager/models/hooks/kind/shellhook.go index a5246ee7..68b8c348 100644 --- a/pkg/module_manager/models/hooks/kind/shellhook.go +++ b/pkg/module_manager/models/hooks/kind/shellhook.go @@ -8,6 +8,7 @@ import ( "github.com/gofrs/uuid/v5" + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/utils" sh_app "github.com/flant/shell-operator/pkg/app" "github.com/flant/shell-operator/pkg/executor" @@ -17,7 +18,6 @@ import ( "github.com/flant/shell-operator/pkg/hook/controller" "github.com/flant/shell-operator/pkg/kube/object_patch" metric_operation "github.com/flant/shell-operator/pkg/metric_storage/operation" - log "github.com/flant/shell-operator/pkg/unilogger" ) type ShellHook struct { diff --git a/pkg/module_manager/models/modules/basic.go b/pkg/module_manager/models/modules/basic.go index 86d633e3..f003cc08 100644 --- a/pkg/module_manager/models/modules/basic.go +++ b/pkg/module_manager/models/modules/basic.go @@ -15,6 +15,7 @@ import ( "github.com/hashicorp/go-multierror" "github.com/kennygrant/sanitize" + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/app" "github.com/flant/addon-operator/pkg/hook/types" "github.com/flant/addon-operator/pkg/module_manager/models/hooks" @@ -26,7 +27,6 @@ import ( "github.com/flant/shell-operator/pkg/executor" "github.com/flant/shell-operator/pkg/hook/binding_context" sh_op_types "github.com/flant/shell-operator/pkg/hook/types" - log "github.com/flant/shell-operator/pkg/unilogger" utils_file "github.com/flant/shell-operator/pkg/utils/file" "github.com/flant/shell-operator/pkg/utils/measure" ) diff --git a/pkg/module_manager/models/modules/basic_test.go b/pkg/module_manager/models/modules/basic_test.go index 58c05545..93f3b5a4 100644 --- a/pkg/module_manager/models/modules/basic_test.go +++ b/pkg/module_manager/models/modules/basic_test.go @@ -7,8 +7,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/utils" - "github.com/flant/shell-operator/pkg/unilogger" ) func TestHandleModulePatch(t *testing.T) { @@ -18,7 +18,7 @@ foo: ` value, err := utils.NewValuesFromBytes([]byte(valuesStr)) require.NoError(t, err) - bm, err := NewBasicModule("test-1", "/tmp/test", 100, value, nil, nil, unilogger.NewNop()) + bm, err := NewBasicModule("test-1", "/tmp/test", 100, value, nil, nil, log.NewNop()) require.NoError(t, err) patch := utils.ValuesPatch{Operations: []*utils.ValuesPatchOperation{ diff --git a/pkg/module_manager/models/modules/global.go b/pkg/module_manager/models/modules/global.go index 68191a07..ddbe7743 100644 --- a/pkg/module_manager/models/modules/global.go +++ b/pkg/module_manager/models/modules/global.go @@ -8,6 +8,7 @@ import ( "sort" "strconv" + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/hook/types" "github.com/flant/addon-operator/pkg/module_manager/models/hooks" "github.com/flant/addon-operator/pkg/module_manager/models/hooks/kind" @@ -16,7 +17,6 @@ import ( "github.com/flant/addon-operator/sdk" "github.com/flant/shell-operator/pkg/hook/binding_context" sh_op_types "github.com/flant/shell-operator/pkg/hook/types" - log "github.com/flant/shell-operator/pkg/unilogger" utils_file "github.com/flant/shell-operator/pkg/utils/file" ) diff --git a/pkg/module_manager/models/modules/helm.go b/pkg/module_manager/models/modules/helm.go index 24c8f7ef..d9599739 100644 --- a/pkg/module_manager/models/modules/helm.go +++ b/pkg/module_manager/models/modules/helm.go @@ -12,12 +12,12 @@ import ( "github.com/gofrs/uuid/v5" "github.com/kennygrant/sanitize" + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/app" "github.com/flant/addon-operator/pkg/helm" "github.com/flant/addon-operator/pkg/helm/client" "github.com/flant/addon-operator/pkg/utils" "github.com/flant/kube-client/manifest" - log "github.com/flant/shell-operator/pkg/unilogger" "github.com/flant/shell-operator/pkg/utils/measure" ) diff --git a/pkg/module_manager/models/modules/synchronization_state.go b/pkg/module_manager/models/modules/synchronization_state.go index c85d0a14..58d10e0c 100644 --- a/pkg/module_manager/models/modules/synchronization_state.go +++ b/pkg/module_manager/models/modules/synchronization_state.go @@ -4,8 +4,8 @@ import ( "fmt" "sync" + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/task" - log "github.com/flant/shell-operator/pkg/unilogger" ) // kubernetesBindingSynchronizationState is a state of the single Synchronization task diff --git a/pkg/module_manager/module_manager.go b/pkg/module_manager/module_manager.go index c5c19178..ca4f3463 100644 --- a/pkg/module_manager/module_manager.go +++ b/pkg/module_manager/module_manager.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/go-multierror" + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/app" "github.com/flant/addon-operator/pkg/helm" "github.com/flant/addon-operator/pkg/helm_resources_manager" @@ -42,7 +43,6 @@ import ( "github.com/flant/shell-operator/pkg/schedule_manager" sh_task "github.com/flant/shell-operator/pkg/task" "github.com/flant/shell-operator/pkg/task/queue" - log "github.com/flant/shell-operator/pkg/unilogger" ) // ModulesState determines which modules should be enabled, disabled or reloaded. diff --git a/pkg/module_manager/module_manager_hooks.go b/pkg/module_manager/module_manager_hooks.go index 0b6a37da..2c529726 100644 --- a/pkg/module_manager/module_manager_hooks.go +++ b/pkg/module_manager/module_manager_hooks.go @@ -6,13 +6,13 @@ import ( "strconv" "strings" + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/module_manager/models/hooks" "github.com/flant/addon-operator/pkg/module_manager/models/modules" dynamic_extender "github.com/flant/addon-operator/pkg/module_manager/scheduler/extenders/dynamically_enabled" "github.com/flant/addon-operator/pkg/utils" "github.com/flant/shell-operator/pkg/hook/controller" sh_op_types "github.com/flant/shell-operator/pkg/hook/types" - log "github.com/flant/shell-operator/pkg/unilogger" ) type globalValues struct { diff --git a/pkg/module_manager/module_manager_test.go b/pkg/module_manager/module_manager_test.go index bbb3029f..74fbaa03 100644 --- a/pkg/module_manager/module_manager_test.go +++ b/pkg/module_manager/module_manager_test.go @@ -4,10 +4,9 @@ import ( "context" "testing" + "github.com/deckhouse/deckhouse/go_lib/log" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "github.com/flant/shell-operator/pkg/unilogger" ) func TestLoadModules(t *testing.T) { @@ -18,7 +17,7 @@ func TestLoadModules(t *testing.T) { }, Dependencies: ModuleManagerDependencies{}, } - mm := NewModuleManager(context.Background(), cfg, unilogger.NewNop()) + mm := NewModuleManager(context.Background(), cfg, log.NewNop()) gv, err := mm.loadGlobalValues() require.NoError(t, err) diff --git a/pkg/module_manager/scheduler/extenders/dynamically_enabled/dynamic.go b/pkg/module_manager/scheduler/extenders/dynamically_enabled/dynamic.go index 93e79ddb..0528103e 100644 --- a/pkg/module_manager/scheduler/extenders/dynamically_enabled/dynamic.go +++ b/pkg/module_manager/scheduler/extenders/dynamically_enabled/dynamic.go @@ -4,8 +4,8 @@ import ( "context" "sync" + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/module_manager/scheduler/extenders" - log "github.com/flant/shell-operator/pkg/unilogger" ) const ( diff --git a/pkg/module_manager/scheduler/extenders/script_enabled/script.go b/pkg/module_manager/scheduler/extenders/script_enabled/script.go index f84e6a5d..8c1042e8 100644 --- a/pkg/module_manager/scheduler/extenders/script_enabled/script.go +++ b/pkg/module_manager/scheduler/extenders/script_enabled/script.go @@ -9,11 +9,11 @@ import ( pointer "k8s.io/utils/ptr" + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/module_manager/scheduler/extenders" exerror "github.com/flant/addon-operator/pkg/module_manager/scheduler/extenders/error" "github.com/flant/addon-operator/pkg/module_manager/scheduler/node" "github.com/flant/addon-operator/pkg/utils" - log "github.com/flant/shell-operator/pkg/unilogger" utils_file "github.com/flant/shell-operator/pkg/utils/file" ) diff --git a/pkg/module_manager/scheduler/extenders/static/static.go b/pkg/module_manager/scheduler/extenders/static/static.go index 4384f1c6..aa3eeff1 100644 --- a/pkg/module_manager/scheduler/extenders/static/static.go +++ b/pkg/module_manager/scheduler/extenders/static/static.go @@ -8,9 +8,9 @@ import ( "github.com/ettle/strcase" "gopkg.in/yaml.v3" + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/module_manager/scheduler/extenders" "github.com/flant/addon-operator/pkg/utils" - log "github.com/flant/shell-operator/pkg/unilogger" ) const ( diff --git a/pkg/module_manager/scheduler/scheduler.go b/pkg/module_manager/scheduler/scheduler.go index 0c856f99..22fee753 100644 --- a/pkg/module_manager/scheduler/scheduler.go +++ b/pkg/module_manager/scheduler/scheduler.go @@ -15,6 +15,7 @@ import ( "github.com/dominikbraun/graph/draw" "github.com/goccy/go-graphviz" + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/module_manager/scheduler/extenders" dynamic_extender "github.com/flant/addon-operator/pkg/module_manager/scheduler/extenders/dynamically_enabled" exerror "github.com/flant/addon-operator/pkg/module_manager/scheduler/extenders/error" @@ -23,7 +24,6 @@ import ( static_extender "github.com/flant/addon-operator/pkg/module_manager/scheduler/extenders/static" "github.com/flant/addon-operator/pkg/module_manager/scheduler/node" "github.com/flant/addon-operator/pkg/utils" - log "github.com/flant/shell-operator/pkg/unilogger" ) var defaultAppliedExtenders = []extenders.ExtenderName{ diff --git a/pkg/module_manager/scheduler/scheduler_test.go b/pkg/module_manager/scheduler/scheduler_test.go index 6e62c699..02f0097b 100644 --- a/pkg/module_manager/scheduler/scheduler_test.go +++ b/pkg/module_manager/scheduler/scheduler_test.go @@ -11,6 +11,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/kube_config_manager/config" "github.com/flant/addon-operator/pkg/module_manager/scheduler/extenders/dynamically_enabled" "github.com/flant/addon-operator/pkg/module_manager/scheduler/extenders/kube_config" @@ -19,7 +20,6 @@ import ( "github.com/flant/addon-operator/pkg/module_manager/scheduler/extenders/static" "github.com/flant/addon-operator/pkg/module_manager/scheduler/node" node_mock "github.com/flant/addon-operator/pkg/module_manager/scheduler/node/mock" - "github.com/flant/shell-operator/pkg/unilogger" ) type kcmMock struct { @@ -62,7 +62,7 @@ nodeLocalDnsEnabled: false tmp, err := os.MkdirTemp(t.TempDir(), "getEnabledTest") require.NoError(t, err) - s := NewScheduler(context.TODO(), unilogger.NewNop()) + s := NewScheduler(context.TODO(), log.NewNop()) valuesFile := filepath.Join(tmp, "values.yaml") err = os.WriteFile(valuesFile, []byte(values), 0o644) @@ -117,7 +117,7 @@ nodeLocalDnsEnabled: true tmp, err := os.MkdirTemp(t.TempDir(), "ApplyExtenders") require.NoError(t, err) - s := NewScheduler(context.TODO(), unilogger.NewNop()) + s := NewScheduler(context.TODO(), log.NewNop()) valuesFile := filepath.Join(tmp, "values.yaml") err = os.WriteFile(valuesFile, []byte(values), 0o644) @@ -197,7 +197,7 @@ kubeDnsEnabled: false tmp, err := os.MkdirTemp(t.TempDir(), "getEnabledByOrderTest") require.NoError(t, err) - s := NewScheduler(context.TODO(), unilogger.NewNop()) + s := NewScheduler(context.TODO(), log.NewNop()) valuesFile := filepath.Join(tmp, "values.yaml") err = os.WriteFile(valuesFile, []byte(values), 0o644) @@ -287,7 +287,7 @@ certManagerEnabled: true tmp, err := os.MkdirTemp(t.TempDir(), "getEnabledTest") require.NoError(t, err) - s := NewScheduler(context.TODO(), unilogger.NewNop()) + s := NewScheduler(context.TODO(), log.NewNop()) valuesFile := filepath.Join(tmp, "values.yaml") err = os.WriteFile(valuesFile, []byte(values), 0o644) @@ -325,7 +325,7 @@ certManagerEnabled: true func TestAddModuleVertex(t *testing.T) { var nodePtr *node.Node - s := NewScheduler(context.TODO(), unilogger.NewNop()) + s := NewScheduler(context.TODO(), log.NewNop()) // no root assert.Equal(t, nodePtr, s.root) basicModuleIngress := &node_mock.MockModule{ @@ -440,7 +440,7 @@ func TestAddModuleVertex(t *testing.T) { } func TestSetExtendersMeta(t *testing.T) { - s := NewScheduler(context.TODO(), unilogger.NewNop()) + s := NewScheduler(context.TODO(), log.NewNop()) err := s.AddExtender(&extender_mock.FilterOne{}) require.NoError(t, err) @@ -531,7 +531,7 @@ kubeDnsEnabled: false EnabledScriptResult: true, }, } - s := NewScheduler(context.TODO(), unilogger.NewNop()) + s := NewScheduler(context.TODO(), log.NewNop()) for _, m := range basicModules { err := s.AddModuleVertex(m) assert.NoError(t, err) @@ -765,7 +765,7 @@ l2LoadBalancerEnabled: false }, } - s := NewScheduler(context.TODO(), unilogger.NewNop()) + s := NewScheduler(context.TODO(), log.NewNop()) for _, m := range basicModules { err := s.AddModuleVertex(m) assert.NoError(t, err) diff --git a/pkg/task/hook_metadata.go b/pkg/task/hook_metadata.go index 59643d5b..39314cc7 100644 --- a/pkg/task/hook_metadata.go +++ b/pkg/task/hook_metadata.go @@ -7,12 +7,12 @@ import ( "strings" "sync" + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/module_manager/scheduler/node" "github.com/flant/shell-operator/pkg/hook/binding_context" "github.com/flant/shell-operator/pkg/hook/task_metadata" "github.com/flant/shell-operator/pkg/hook/types" "github.com/flant/shell-operator/pkg/task" - log "github.com/flant/shell-operator/pkg/unilogger" ) // HookMetadata is a metadata for addon-operator tasks diff --git a/pkg/utils/loader.go b/pkg/utils/loader.go index d2a2af92..96b71936 100644 --- a/pkg/utils/loader.go +++ b/pkg/utils/loader.go @@ -6,8 +6,8 @@ import ( "path/filepath" "strings" + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/app" - log "github.com/flant/shell-operator/pkg/unilogger" ) const ( diff --git a/pkg/utils/merge_labels.go b/pkg/utils/merge_labels.go index cc60143a..1b5aee89 100644 --- a/pkg/utils/merge_labels.go +++ b/pkg/utils/merge_labels.go @@ -3,7 +3,7 @@ package utils import ( "log/slog" - "github.com/flant/shell-operator/pkg/unilogger" + "github.com/deckhouse/deckhouse/go_lib/log" ) // MergeLabels merges several maps into one. Last map keys overrides keys from first maps. @@ -19,7 +19,7 @@ func MergeLabels(labelsMaps ...map[string]string) map[string]string { return labels } -func EnrichLoggerWithLabels(logger *unilogger.Logger, labelsMaps ...map[string]string) *unilogger.Logger { +func EnrichLoggerWithLabels(logger *log.Logger, labelsMaps ...map[string]string) *log.Logger { loggerEntry := logger for _, labels := range labelsMaps { diff --git a/pkg/utils/stdliblogtologrus/adapter.go b/pkg/utils/stdliblogtologrus/adapter.go index 2d449d9f..3cb3ba15 100644 --- a/pkg/utils/stdliblogtologrus/adapter.go +++ b/pkg/utils/stdliblogtologrus/adapter.go @@ -2,20 +2,20 @@ package stdliblogtologrus import ( "io" - "log" + stdlog "log" "strings" - "github.com/flant/shell-operator/pkg/unilogger" + "github.com/deckhouse/deckhouse/go_lib/log" ) -func InitAdapter(logger *unilogger.Logger) { - log.SetOutput(&writer{logger: logger.Named("helm")}) +func InitAdapter(logger *log.Logger) { + stdlog.SetOutput(&writer{logger: logger.Named("helm")}) } var _ io.Writer = (*writer)(nil) type writer struct { - logger *unilogger.Logger + logger *log.Logger } func (w *writer) Write(msg []byte) (n int, err error) { diff --git a/pkg/utils/stdliblogtologrus/adapter_test.go b/pkg/utils/stdliblogtologrus/adapter_test.go index 30a596ea..104f69e9 100644 --- a/pkg/utils/stdliblogtologrus/adapter_test.go +++ b/pkg/utils/stdliblogtologrus/adapter_test.go @@ -5,12 +5,11 @@ import ( "bytes" "encoding/json" "fmt" - "log" + stdlog "log" "testing" + "github.com/deckhouse/deckhouse/go_lib/log" "github.com/stretchr/testify/require" - - "github.com/flant/shell-operator/pkg/unilogger" ) type testLogLine struct { @@ -22,14 +21,14 @@ type testLogLine struct { func TestStdlibLogAdapter(t *testing.T) { t.Run("Simple", func(t *testing.T) { buf := bytes.Buffer{} - logger := unilogger.NewLogger(unilogger.Options{}) + logger := log.NewLogger(log.Options{}) logger.SetOutput(&buf) InitAdapter(logger) - log.Print("test string for a check") - log.Print("another string") + stdlog.Print("test string for a check") + stdlog.Print("another string") scanner := bufio.NewScanner(bytes.NewReader(buf.Bytes())) diff --git a/pkg/utils/values.go b/pkg/utils/values.go index 2fc54f8f..a98859c9 100644 --- a/pkg/utils/values.go +++ b/pkg/utils/values.go @@ -10,7 +10,7 @@ import ( "gopkg.in/yaml.v3" k8syaml "sigs.k8s.io/yaml" - log "github.com/flant/shell-operator/pkg/unilogger" + log "github.com/deckhouse/deckhouse/go_lib/log" utils_checksum "github.com/flant/shell-operator/pkg/utils/checksum" ) diff --git a/pkg/values/validation/schemas.go b/pkg/values/validation/schemas.go index 43b7d3cd..2d7f2e2b 100644 --- a/pkg/values/validation/schemas.go +++ b/pkg/values/validation/schemas.go @@ -14,9 +14,9 @@ import ( "github.com/hashicorp/go-multierror" "sigs.k8s.io/yaml" + log "github.com/deckhouse/deckhouse/go_lib/log" "github.com/flant/addon-operator/pkg/utils" "github.com/flant/addon-operator/pkg/values/validation/schema" - log "github.com/flant/shell-operator/pkg/unilogger" ) /**