-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Refactor SetStatusConditions logic #3020
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this @catouc! Sorry for the delay in the review, I was off.
I think that the problem is that you are replacing existing conditions on the Status.
} | ||
return e.setCondition(ctx, logger, object, status, reason, message, active) | ||
func (e *scaleExecutor) setReadyCondition(ctx context.Context, object interface{}, status metav1.ConditionStatus, reason string, message string) error { | ||
return util.SetStatusConditions(ctx, e.client, object, &kedav1alpha1.Conditions{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this call will replace all existing conditions of another type that are already defined on the ScaledObject's Status. See how Conditions are being set:
keda/apis/keda/v1alpha1/condition_types.go
Lines 126 to 191 in 98509a8
// SetReadyCondition modifies Ready Condition according to input parameters | |
func (c *Conditions) SetReadyCondition(status metav1.ConditionStatus, reason string, message string) { | |
if *c == nil { | |
c = GetInitializedConditions() | |
} | |
c.setCondition(ConditionReady, status, reason, message) | |
} | |
// SetActiveCondition modifies Active Condition according to input parameters | |
func (c *Conditions) SetActiveCondition(status metav1.ConditionStatus, reason string, message string) { | |
if *c == nil { | |
c = GetInitializedConditions() | |
} | |
c.setCondition(ConditionActive, status, reason, message) | |
} | |
// SetFallbackCondition modifies Fallback Condition according to input parameters | |
func (c *Conditions) SetFallbackCondition(status metav1.ConditionStatus, reason string, message string) { | |
if *c == nil { | |
c = GetInitializedConditions() | |
} | |
c.setCondition(ConditionFallback, status, reason, message) | |
} | |
// GetActiveCondition returns Condition of type Active | |
func (c *Conditions) GetActiveCondition() Condition { | |
if *c == nil { | |
c = GetInitializedConditions() | |
} | |
return c.getCondition(ConditionActive) | |
} | |
// GetReadyCondition returns Condition of type Ready | |
func (c *Conditions) GetReadyCondition() Condition { | |
if *c == nil { | |
c = GetInitializedConditions() | |
} | |
return c.getCondition(ConditionReady) | |
} | |
// GetFallbackCondition returns Condition of type Ready | |
func (c *Conditions) GetFallbackCondition() Condition { | |
if *c == nil { | |
c = GetInitializedConditions() | |
} | |
return c.getCondition(ConditionFallback) | |
} | |
func (c Conditions) getCondition(conditionType ConditionType) Condition { | |
for i := range c { | |
if c[i].Type == conditionType { | |
return c[i] | |
} | |
} | |
return Condition{} | |
} | |
func (c Conditions) setCondition(conditionType ConditionType, status metav1.ConditionStatus, reason string, message string) { | |
for i := range c { | |
if c[i].Type == conditionType { | |
c[i].Status = status | |
c[i].Reason = reason | |
c[i].Message = message | |
break | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that's a good catch - I put in a first idea that seems to pass that one failing test, I'm currently only on my chromebook that can't run the full test suit without blowing up.
I haven't really thought about the implementation too much on that one and it's copying essentially the same switch statement for the two types there are.
One question for this I suppose is how much does performance matter on this code path? Do we need to worry about allocs or speed necessarily here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late reply, I have been really busy, Kubecon and other stuff.
We should really care about performance on this. Status might be updated quite often and there might be tons of ScaledObjects to update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will definitely be a bit more involved with that in mind 🤔 the last implementation I wrote broke something else, I'm feeling the ways the two functions are originally designed are subtly different so I'll have to spend more time understanding - pretty busy myself currently so have not made any significant progress at this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, let's keep this open :)
933be34
to
9193daf
Compare
hey @catouc , |
Signed-off-by: Philipp Böschen <catouc@philipp.boeschen.me>
Signed-off-by: Philipp Böschen <catouc@philipp.boeschen.me>
Signed-off-by: Philipp Böschen <catouc@philipp.boeschen.me>
9193daf
to
8476947
Compare
Should be fine now - but I am having issues with functional tests now, I don't think my implementation actually works - which is odd since I'm just passing through to the original setter methods on the Conditions slice 🤔
|
Any update on this? |
I'll likely not get around to this so if someone wants to actually pick this up instead you're very welcome. |
Closing this in favor of: #4487 |
Signed-off-by: Philipp Böschen catouc@philipp.boeschen.me
A first try at implementing #2906 - moving the conditions setting logic into the
pkg/util
package.Checklist
Fixes #2906