Skip to content

Commit

Permalink
✨ Support extenion compat with addon as regex.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Ortel <jortel@redhat.com>
  • Loading branch information
jortel committed Feb 10, 2025
1 parent 0986cad commit 7c42c85
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion task/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"os"
"path"
"regexp"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -88,6 +89,10 @@ const (
Cache = "cache"
)

var (
AddonIsRegex = regexp.MustCompile("[^0-9A-Za-z_-]")
)

var (
Settings = &settings.Settings
Log = logr.WithName("task-scheduler")
Expand Down Expand Up @@ -555,7 +560,11 @@ func (m *Manager) selectExtensions(task *Task, addon *crd.Addon) (err error) {
matched := false
selector := NewSelector(m.DB, task)
for _, extension := range m.cluster.Extensions() {
if extension.Spec.Addon != addon.Name {
matched, err = m.matchAddon(extension, addon)
if err != nil {
return
}
if !matched {
continue
}
matched, err = selector.Match(extension.Spec.Selector)
Expand All @@ -570,6 +579,30 @@ 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) (match bool, err error) {
ref := strings.TrimSpace(extension.Spec.Addon)
p := AddonIsRegex
if p.MatchString(ref) {
p, err = regexp.Compile(ref)
if err != nil {
err = &SelectorNotValid{
Selector: ref,
Reason: err.Error(),
}
return
}
match = p.MatchString(addon.Name)
} else {

match = addon.Name == ref
}
return
}

// postpone Postpones a task as needed based on rules.
// postpone order:
// - priority (lower)
Expand Down

0 comments on commit 7c42c85

Please # to comment.