Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 31 additions & 27 deletions task/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}

Copy link
Contributor Author

@jortel jortel Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hint: ^ moved to Task for better reuse.

// postpone Postpones a task as needed based on rules.
// postpone order:
// - priority (lower)
Expand Down Expand Up @@ -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)
Copy link
Contributor Author

@jortel jortel Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hint: Missed this validation in the original PR.

if err != nil {
return
}
if !matched {
err = &ExtensionNotValid{
Name: extension.Name,
Addon: addon.Name,
Expand Down Expand Up @@ -1620,7 +1601,7 @@ func (r *Task) podFailed(pod *core.Pod, client k8s.Client) {
}
}

// getExtensions by name.
// getExtensions returns defined extensions.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hint: incidental. noticed it was incorrect.

func (r *Task) getExtensions(client k8s.Client) (extensions []crd.Extension, err error) {
for _, name := range r.Extensions {
extension := crd.Extension{}
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion task/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
Loading