bootstrapMainQueue adds tasks to run hooks with OnStartup bindings and tasks to enable kubernetes bindings.
(tqs *queue.TaskQueueSet)
| 916 | // bootstrapMainQueue adds tasks to run hooks with OnStartup bindings |
| 917 | // and tasks to enable kubernetes bindings. |
| 918 | func (op *ShellOperator) bootstrapMainQueue(tqs *queue.TaskQueueSet) { |
| 919 | logEntry := op.logger.With(pkg.LogKeyOperatorComponent, "initMainQueue") |
| 920 | |
| 921 | // Prepopulate main queue with 'onStartup' tasks and 'enable kubernetes bindings' tasks. |
| 922 | tqs.WithMainName("main") |
| 923 | tqs.NewNamedQueue("main", |
| 924 | op.taskHandler, |
| 925 | queue.WithCompactableTypes(task_metadata.HookRun), |
| 926 | queue.WithLogger(op.logger.With(pkg.LogKeyOperatorComponent, "mainQueue")), |
| 927 | ) |
| 928 | |
| 929 | mainQueue := tqs.GetMain() |
| 930 | |
| 931 | // Add tasks to run OnStartup bindings |
| 932 | onStartupHooks, err := op.HookManager.GetHooksInOrder(types.OnStartup) |
| 933 | if err != nil { |
| 934 | logEntry.Error("add tasks to run OnStartup bindings", log.Err(err)) |
| 935 | return |
| 936 | } |
| 937 | |
| 938 | for _, hookName := range onStartupHooks { |
| 939 | bc := bindingcontext.BindingContext{ |
| 940 | Binding: string(types.OnStartup), |
| 941 | } |
| 942 | bc.Metadata.BindingType = types.OnStartup |
| 943 | |
| 944 | newTask := task.NewTask(task_metadata.HookRun). |
| 945 | WithMetadata(task_metadata.HookMetadata{ |
| 946 | HookName: hookName, |
| 947 | BindingType: types.OnStartup, |
| 948 | BindingContext: []bindingcontext.BindingContext{bc}, |
| 949 | }). |
| 950 | WithCompactionID(hookName). |
| 951 | WithQueuedAt(time.Now()) |
| 952 | |
| 953 | mainQueue.AddLast(newTask) |
| 954 | logEntry.Info("queue task with hook", |
| 955 | slog.String(pkg.LogKeyTask, newTask.GetDescription()), |
| 956 | slog.String(pkg.LogKeyHook, hookName)) |
| 957 | } |
| 958 | |
| 959 | // Add tasks to enable kubernetes monitors and schedules for each hook |
| 960 | for _, hookName := range op.HookManager.GetHookNames() { |
| 961 | h := op.HookManager.GetHook(hookName) |
| 962 | |
| 963 | if h.GetConfig().HasBinding(types.OnKubernetesEvent) { |
| 964 | newTask := task.NewTask(task_metadata.EnableKubernetesBindings). |
| 965 | WithMetadata(task_metadata.HookMetadata{ |
| 966 | HookName: hookName, |
| 967 | Binding: string(task_metadata.EnableKubernetesBindings), |
| 968 | }). |
| 969 | WithCompactionID(hookName). |
| 970 | WithQueuedAt(time.Now()) |
| 971 | mainQueue.AddLast(newTask) |
| 972 | logEntry.Info("queue task with hook", |
| 973 | slog.String(pkg.LogKeyTask, newTask.GetDescription()), |
| 974 | slog.String(pkg.LogKeyHook, hookName)) |
| 975 | } |