Merged
Conversation
Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
…vance-architecture-refactor Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Extract interfaces and named types to decouple
ShellOperator's core components, replace an untyped task-type switch with a registry, and remove dead code. All changes are backward-compatible; no public API is broken.What this PR does / why we need it
HookManagerinterface (pkg/hook/hook_manager.go)HookManagerinterface capturing the 10 methods used byShellOperator.ShellOperator.HookManagerfrom*hook.Manager(concrete) tohook.HookManager(interface).var _ HookManager = (*Manager)(nil)compile-time assertion.ShellOperatorno longer imports the concreteManager; tests can inject a stub with zero real dependencies.HookDiscoveryinterface (pkg/hook/hook_manager.go)HookDiscoveryinterface with a singleDiscover(workingDir string) ([]string, error)method.FileSystemHookDiscoveryas the default implementation (wraps the existingutils_file.RecursiveGetExecutablePathscall).Manager.Init()now callshm.hookDiscovery.Discover(...)instead of the utility function directly.ManagerConfig.HookDiscoveryfield added;nildefaults toFileSystemHookDiscovery{}.Manager.Init; tests can provide a deterministic stub without touching the real filesystem.Named webhook event handler types (
pkg/shell-operator/webhook_handlers.go, new file)TaskRunnertype alias (func(ctx, task) TaskResult).AdmissionEventHandlerstruct with constructorNewAdmissionEventHandler(hm, runner, logger)andHandlemethod matching theWithAdmissionEventHandlersignature.ConversionEventHandlerstruct with constructorNewConversionEventHandler(hm, runner, logger)andHandlemethod matchingEventHandlerFn.initValidatingWebhookManagerwithNewAdmissionEventHandler(...).Handle.conversionEventHandlermethod (which also had areturn resundefined-variable compile error from the merge) and the inline-style call ininitConversionWebhookManagerwithNewConversionEventHandler(...).Handle.TaskHandlerRegistry(pkg/shell-operator/task_handler_registry.go, new file)TaskHandlerFuncandTaskHandlerRegistry(map fromtask.TaskTypeto handler).NewTaskHandlerRegistry(),Register(taskType, handler),Handle(ctx, task) (TaskResult, bool).taskHandlerRegistry *TaskHandlerRegistryfield toShellOperator.taskHandler(ctx, task) TaskResultdispatcher method (thin wrapper over the registry).RegisterBuiltinTaskHandlers()method registeringHookRun,EnableKubernetesBindings, andEnableScheduleBindings; called fromassembleShellOperatorinbootstrap.go.taskHandleEnableScheduleBindingsfrom the switch as a proper method alongside the existingtaskHandleHookRunandtaskHandleEnableKubernetesBindings.addon-operatorcan callRegister()to extend without forking.Dead code removal
CommonHookinterface (pkg/hook/hook.go): was never referenced outside its own declaration — removed.FlagInfo.Define boolfield (pkg/app/app.go): all callers always passedtrue; theif flag.Define { }branches were unconditional in practice — field and branches removed, flag registration is now always unconditional.conversionEventHandlermethod onShellOperator: superseded byConversionEventHandler— removed.v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"import inoperator.go: became unused after the above removal — removed.