refactor(reload): move resource types and reload decision structs to dedicated files and remove redundant code

This commit is contained in:
TheiLLeniumStudios
2025-12-28 08:47:57 +01:00
parent 3a8c300d35
commit fa60c1d853
9 changed files with 228 additions and 205 deletions
-34
View File
@@ -6,7 +6,6 @@ import (
"github.com/go-logr/logr"
"github.com/stakater/Reloader/internal/pkg/alerting"
"github.com/stakater/Reloader/internal/pkg/config"
"github.com/stakater/Reloader/internal/pkg/events"
"github.com/stakater/Reloader/internal/pkg/metrics"
"github.com/stakater/Reloader/internal/pkg/reload"
@@ -14,8 +13,6 @@ import (
"github.com/stakater/Reloader/internal/pkg/workload"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/predicate"
)
// ReloadHandler handles the common reload workflow.
@@ -154,34 +151,3 @@ func (h *ReloadHandler) applyReloads(
}
}
}
// BuildEventFilter combines a resource-specific predicate with common filters.
func BuildEventFilter(resourcePredicate predicate.Predicate, cfg *config.Config, initialized *bool) predicate.Predicate {
return predicate.And(
resourcePredicate,
reload.NamespaceFilterPredicate(cfg),
reload.LabelSelectorPredicate(cfg),
reload.IgnoreAnnotationPredicate(cfg),
createEventPredicate(cfg, initialized),
)
}
func createEventPredicate(cfg *config.Config, initialized *bool) predicate.Predicate {
return predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool {
if !*initialized && !cfg.SyncAfterRestart {
return false
}
return cfg.ReloadOnCreate
},
UpdateFunc: func(e event.UpdateEvent) bool {
return true
},
DeleteFunc: func(e event.DeleteEvent) bool {
return cfg.ReloadOnDelete
},
GenericFunc: func(e event.GenericEvent) bool {
return false
},
}
}