From a55a20a55ac2f7cb456dc50701e2b31f227377e2 Mon Sep 17 00:00:00 2001 From: Jeff Ortel Date: Tue, 11 Feb 2025 16:48:48 -0800 Subject: [PATCH] :bug: Extension addon (ref) regex fix. Signed-off-by: Jeff Ortel --- task/manager.go | 58 +++++++++++++++++++++++++---------------------- task/task_test.go | 2 +- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/task/manager.go b/task/manager.go index 9db802dbf..59dfb22c6 100644 --- a/task/manager.go +++ b/task/manager.go @@ -560,7 +560,7 @@ func (m *Manager) selectExtensions(task *Task, addon *crd.Addon) (err error) { matched := false selector := NewSelector(m.DB, task) for _, extension := range m.cluster.Extensions() { - matched, err = m.matchAddon(extension, addon) + matched, err = task.matchAddon(extension, addon) if err != nil { return } @@ -579,30 +579,6 @@ func (m *Manager) selectExtensions(task *Task, addon *crd.Addon) (err error) { return } -// matchAddon - returns true when the extension's `addon` -// (ref) matches the addon name. -// The `ref` is matched as a REGEX when it contains -// characters other than: [0-9A-Za-z_]. -func (m *Manager) matchAddon(extension *crd.Extension, addon *crd.Addon) (matched bool, err error) { - ref := strings.TrimSpace(extension.Spec.Addon) - p := IsRegex - if p.MatchString(ref) { - p, err = regexp.Compile(ref) - if err != nil { - err = &ExtAddonNotValid{ - Extension: extension.Name, - Reason: err.Error(), - } - return - } - matched = p.MatchString(addon.Name) - } else { - - matched = addon.Name == ref - } - return -} - // postpone Postpones a task as needed based on rules. // postpone order: // - priority (lower) @@ -1361,7 +1337,12 @@ func (r *Task) Run(cluster *Cluster) (started bool, err error) { return } for _, extension := range extensions { - if r.Addon != extension.Spec.Addon { + matched := false + matched, err = r.matchAddon(&extension, addon) + if err != nil { + return + } + if !matched { err = &ExtensionNotValid{ Name: extension.Name, Addon: addon.Name, @@ -1620,7 +1601,7 @@ func (r *Task) podFailed(pod *core.Pod, client k8s.Client) { } } -// getExtensions by name. +// getExtensions returns defined extensions. func (r *Task) getExtensions(client k8s.Client) (extensions []crd.Extension, err error) { for _, name := range r.Extensions { extension := crd.Extension{} @@ -1646,6 +1627,29 @@ func (r *Task) getExtensions(client k8s.Client) (extensions []crd.Extension, err return } +// matchAddon - returns true when the extension's `addon` +// (ref) matches the addon name. +// The `ref` is matched as a REGEX when it contains +// characters other than: [0-9A-Za-z_]. +func (r *Task) matchAddon(extension *crd.Extension, addon *crd.Addon) (matched bool, err error) { + ref := strings.TrimSpace(extension.Spec.Addon) + p := IsRegex + if p.MatchString(ref) { + p, err = regexp.Compile(ref) + if err != nil { + err = &ExtAddonNotValid{ + Extension: extension.Name, + Reason: err.Error(), + } + return + } + matched = p.MatchString(addon.Name) + } else { + matched = addon.Name == ref + } + return +} + // pod build the pod. func (r *Task) pod( addon *crd.Addon, diff --git a/task/task_test.go b/task/task_test.go index 611383e2a..16a31cdf8 100644 --- a/task/task_test.go +++ b/task/task_test.go @@ -138,7 +138,7 @@ func TestPriorityGraph(t *testing.T) { func TestAddonRegex(t *testing.T) { g := gomega.NewGomegaWithT(t) - m := Manager{} + m := Task{} addonA := &crd.Addon{} addonA.Name = "A" addonB := &crd.Addon{}