- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 364
          Convert impl Condition return signature to Option<bool>
          #1498
        
          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
base: main
Are you sure you want to change the base?
Conversation
Takes advantage of `?` on `Option` to allow simpler `Condition` impls. Not a huge change internally, but it is a breaking change. Signed-off-by: clux <[email protected]>
Condition in terms of option functions
      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.
Lookup of the conditions is one of the most common scenarios in controller code. If anything can make it simpler, I think it is worth implementing.
Signed-off-by: clux <[email protected]>
Signed-off-by: clux <[email protected]>
Condition in terms of option functionsCondition to fns returning Option<bool>
      less breaking for people using it because the signature is the same! Signed-off-by: clux <[email protected]>
Signed-off-by: clux <[email protected]>
| Codecov ReportAttention: Patch coverage is  
 
 Additional details and impacted files@@           Coverage Diff           @@
##            main   #1498     +/-   ##
=======================================
- Coverage   76.1%   76.0%   -0.0%     
=======================================
  Files         84      84             
  Lines       7859    7843     -16     
=======================================
- Hits        5976    5960     -16     
  Misses      1883    1883             
 🚀 New features to boost your workflow:
 | 
Signed-off-by: clux <[email protected]>
| I have revamped this after seeing new verbose  | 
Condition to fns returning Option<bool>impl Condition to return signature to Option<bool>
      impl Condition to return signature to Option<bool>impl Condition return signature to Option<bool>
      | if let Some(spec) = &svc.spec { | ||
| if spec.type_ != Some("LoadBalancer".to_string()) { | ||
| return true; | ||
| } | 
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.
hey @detjensrobert doing a follow-up on conditions. wondering if you had a particular reason to return true here rather than false for this condition. feels to me we shouldn't consider a condition "matching" on a service that's not even of the right type.
also if you have opinions on this pr, happy to hear 🙏
EDIT: sorry about spam, put comment on wrong place with wrong account.
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.
My thought was that since non-LoadBalancer services do not need to wait for a cloud LB, they are (almost) immediately ready and do not need any checks. I can see this wanting to fail on the wrong type of service though.
| The ergonomic improvement is compelling. I don't love the idea of having two separate-but-equivalent values ( I especially don't think  
 I'd still consider this "very breaking", given how the API is designed to make implementing custom  We could avoid the breakage and support multiple alternatives using an intermediate trait (https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=575f74b0a646dd428a25ffb284189850), but I'm not sure the juice is worth the squeeze. | 
| If we want to keep the bool return type, we could use a nested  await_condition(api, &object.name_any(), |d: Option<&Deployment>| {
  // Use a nested function so that we can use Option? returns (the outer closure returns `bool`)
  // TODO: switch to try { } when that is standardized
  
  /// Replicate the upstream deployment complete check
  /// https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#complete-deployment
  fn _inner(d: Option<&Deployment>) -> Option<bool> {
      Some(d?.status.as_ref()?.conditions.as_ref()?.iter().any(|c| {
          c.reason == Some("NewReplicaSetAvailable".to_string()) && c.status == "True"
      }))
  }
  
  _inner(d).unwrap_or(false)
})This doesn't require any changes to the type since this is now all internal to the existing closure, but is getting weird with now two levels of inline functions/closures which kinda feels like a code smell. Related, what was the rationale for conditions returning a lambda instead of the condition function itself implementing the check directly? Is that a limitation of the trait type? | 
| You can also (currently) do  | 
started out as a PR to try out let-chains, but found that it solves the ergonomic problem with the wait API that I tried to solve earlier in #1498 Signed-off-by: clux <[email protected]>
To allow taking advantage of
?onOptionto allow simplerConditionimpls.This also technically allows for distinguishing between;
Generally, this is probably not hugely valuable, but it allows us to have a clearer answer rather than to conflate
missingwith either true or false.Breaking
This is generally not a breaking change. The
matches_objectfn retains its original signature + behavior. It does this by using the new trait methodmatcheswithunwrap_or_default:However;
This is a breaking change only for implementors of
Conditionwho now need to return anOption<bool>rather thanboolforimpl Condition. My thinking is that being able to use option-try makes this worth it. It can be easily communicated that you take the value and put it in aSomeotherwise.This is also a slight breaking change for the newly introduced (#1710)
conditions::is_service_loadbalancer_provisionedwhich was returningtruefor services the condition did not apply for. Now it returnsSome(false)for such services.