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
3 changes: 2 additions & 1 deletion pkg/conditions/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ func (c *conditionUpdater) WithEventRecorder(recorder record.EventRecorder, verb
func (c *conditionUpdater) UpdateCondition(conType string, status metav1.ConditionStatus, observedGeneration int64, reason, message string) *conditionUpdater {
if reason == "" {
// the metav1.Condition type requires a reason, so let's add a dummy if none is given
reason = conType + string(status)
// the type field allows dots ('.'), while the reason field does not, so replace them with colons (':') (which are not allowed in the type field)
reason = strings.ReplaceAll(conType, ".", ":") + "_" + string(status)
}
con := metav1.Condition{
Type: conType,
Expand Down
20 changes: 20 additions & 0 deletions pkg/conditions/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,26 @@ var _ = Describe("Conditions", func() {
Expect(updater.HasCondition("true")).To(BeTrue())
})

It("should correctly add a reason if not given and replace invalid characters from the type", func() {
cons := []metav1.Condition{}
updated, _ := conditions.ConditionUpdater(cons, false).
UpdateCondition("TestCondition", conditions.FromBool(true), 0, "", "").
UpdateCondition("TestCondition.Test", conditions.FromBool(false), 0, "", "").
Conditions()
Expect(updated).To(ConsistOf(
MatchCondition(TestCondition().
WithType("TestCondition").
WithStatus(metav1.ConditionTrue).
WithReason("TestCondition_True").
WithMessage("")),
MatchCondition(TestCondition().
WithType("TestCondition.Test").
WithStatus(metav1.ConditionFalse).
WithReason("TestCondition:Test_False").
WithMessage("")),
))
})

})

Context("EventRecorder", func() {
Expand Down