Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dedupe for events FailedToSchedule nodes #372

Merged
merged 1 commit into from
Jun 16, 2023
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
4 changes: 3 additions & 1 deletion pkg/controllers/provisioning/scheduling/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package events
import (
"fmt"
"strings"
"time"

v1 "k8s.io/api/core/v1"
"k8s.io/client-go/util/flowcontrol"
Expand Down Expand Up @@ -52,6 +53,7 @@ func PodFailedToSchedule(pod *v1.Pod, err error) events.Event {
Type: v1.EventTypeWarning,
Reason: "FailedScheduling",
Message: fmt.Sprintf("Failed to schedule pod, %s", err),
DedupeValues: []string{string(pod.UID), err.Error()},
DedupeValues: []string{string(pod.UID)},
DedupeTimeout: 5 * time.Minute,
}
}
4 changes: 3 additions & 1 deletion pkg/scheduling/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,7 @@ func (r Requirements) Labels() map[string]string {

func (r Requirements) String() string {
engedaam marked this conversation as resolved.
Show resolved Hide resolved
requirements := lo.Reject(r.Values(), func(requirement *Requirement, _ int) bool { return v1alpha5.RestrictedLabels.Has(requirement.Key) })
return strings.Join(lo.Map(requirements, func(requirement *Requirement, _ int) string { return requirement.String() }), ", ")
stringRequirements := lo.Map(requirements, func(requirement *Requirement, _ int) string { return requirement.String() })
engedaam marked this conversation as resolved.
Show resolved Hide resolved
engedaam marked this conversation as resolved.
Show resolved Hide resolved
sort.Strings(stringRequirements)
return strings.Join(stringRequirements, ", ")
}
22 changes: 22 additions & 0 deletions pkg/scheduling/requirements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,28 @@ var _ = Describe("Requirements", func() {
Expect(reqs.NodeSelectorRequirements()).To(HaveLen(14))
})
})
Context("Stringify Requirements", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for adding a UT!

It("should print Requirements in the same order", func() {
reqs := NewRequirements(
NewRequirement("exists", v1.NodeSelectorOpExists),
NewRequirement("doesNotExist", v1.NodeSelectorOpDoesNotExist),
NewRequirement("inA", v1.NodeSelectorOpIn, "A"),
NewRequirement("inB", v1.NodeSelectorOpIn, "B"),
NewRequirement("inAB", v1.NodeSelectorOpIn, "A", "B"),
NewRequirement("notInA", v1.NodeSelectorOpNotIn, "A"),
NewRequirement("in1", v1.NodeSelectorOpIn, "1"),
NewRequirement("in9", v1.NodeSelectorOpIn, "9"),
NewRequirement("in19", v1.NodeSelectorOpIn, "1", "9"),
NewRequirement("notIn12", v1.NodeSelectorOpNotIn, "1", "2"),
NewRequirement("greaterThan1", v1.NodeSelectorOpGt, "1"),
NewRequirement("greaterThan9", v1.NodeSelectorOpGt, "9"),
NewRequirement("lessThan1", v1.NodeSelectorOpLt, "1"),
NewRequirement("lessThan9", v1.NodeSelectorOpLt, "9"),
)

Expect(reqs.String()).To(Equal("doesNotExist DoesNotExist, exists Exists, greaterThan1 Exists >1, greaterThan9 Exists >9, in1 In [1], in19 In [1 9], in9 In [9], inA In [A], inAB In [A B], inB In [B], lessThan1 Exists <1, lessThan9 Exists <9, notIn12 NotIn [1 2], notInA NotIn [A]"))
})
})
})

// Keeping this in case we need it, I ran for 1m+ samples and had no issues
Expand Down