Skip to content

feat: Add ProbeBuilder #1078

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

feat: Add ProbeBuilder #1078

wants to merge 6 commits into from

Conversation

sbernauer
Copy link
Member

@sbernauer sbernauer commented Aug 13, 2025

Description

Adds a builder for a Probe similar to the ResourceRequirementsBuilder
Needed for stackabletech/superset-operator#654

Definition of Done Checklist

  • Not all of these items are applicable to all PRs, the author should update this template to only leave the boxes in that are relevant
  • Please make sure all these things are done and tick the boxes

Author

  • Changes are OpenShift compatible
  • CRD changes approved
  • CRD documentation for all fields, following the style guide.
  • Integration tests passed (for non trivial changes)
  • Changes need to be "offline" compatible

Reviewer

  • Code contains useful comments
  • Code contains useful logging statements
  • (Integration-)Test cases added
  • Documentation added or updated. Follows the style guide.
  • Changelog updated
  • Cargo.toml only contains references to git tags (not specific commits or branches)

Acceptance

  • Feature Tracker has been updated
  • Proper release label has been added

@sbernauer sbernauer requested a review from NickLarsenNZ August 15, 2025 09:58
Copy link
Member

@NickLarsenNZ NickLarsenNZ left a comment

Choose a reason for hiding this comment

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

Mostly reviewed, but I'd like to discuss the change I commented on.

Comment on lines +26 to +27
#[derive(Debug)]
pub struct ProbeBuilder<Action, Period> {
Copy link
Member

Choose a reason for hiding this comment

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

I do think we should have docs on pub items.

It doesn't have to be super comprehensive, and examples can be added to the module level docs.

Suggested change
#[derive(Debug)]
pub struct ProbeBuilder<Action, Period> {
/// Valid Kubernetes probe builder
///
/// The upstream struct [NameOfStruct] does not prevent invalid probe configurations
/// which leads to surprises at runtime which can be deeply hidden.
#[derive(Debug)]
pub struct ProbeBuilder<Action, Period> {

#[derive(Debug, Snafu)]
pub enum Error {
#[snafu(display(
"The probe's {field:?} duration of {duration} is too long, as it's seconds doesn't fit into an i32"
Copy link
Member

Choose a reason for hiding this comment

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

How does that appear? Does it look like human time?
Eg:

  • duration of 4,734e+8 is too long
  • duration of 15 is too long, or
  • duration of 15 years is too long

}
}

pub enum ProbeAction {
Copy link
Member

Choose a reason for hiding this comment

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

To save documenting each variant, we can refer to upstream docs.

Suggested change
pub enum ProbeAction {
/// Available probes
///
/// Only one probe can be configured at a time. For more details about each
/// type, see [container-probes] documentation.
///
/// [container-probes]: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes
pub enum ProbeAction {

Comment on lines +73 to +74
/// There is a convenience helper: [`Self::with_exec_action_helper`].
pub fn with_exec_action(self, exec_action: ExecAction) -> ProbeBuilder<ProbeAction, ()> {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// There is a convenience helper: [`Self::with_exec_action_helper`].
pub fn with_exec_action(self, exec_action: ExecAction) -> ProbeBuilder<ProbeAction, ()> {
/// Set an exec probe with the given configuration.
///
/// For simple cases, there is a a convenience helper: [`Self::with_exec_action_helper`].
pub fn with_exec_action(self, exec_action: ExecAction) -> ProbeBuilder<ProbeAction, ()> {

Copy link
Member

Choose a reason for hiding this comment

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

I'll stop adding documenting comments, but this should apply to other pub methods too.

Comment on lines +300 to +302
let probe = ProbeBuilder::default()
.with_exec_action_helper(["sleep", "1"])
.with_period(Duration::from_secs(5))
Copy link
Member

@NickLarsenNZ NickLarsenNZ Aug 15, 2025

Choose a reason for hiding this comment

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

Part of me feels like the word "helper" should be replaced with what it does.

But actually, I have a different recommendation overall...

Since there are a small finite set of probe types that can be created, we should drop the default impl... and make the developer choose one...

        let probe = ProbeBuilder::exec_with_command(["sleep", "1"])
            .with_period(Duration::from_secs(5))

and for the non "helper" case, it could just be:

        let probe = ProbeBuilder::exec(the_exec_stuff)
            .with_period(Duration::from_secs(5))

Copy link
Member

Choose a reason for hiding this comment

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

To expand on things... I don't believe there is a good "default" probe, and therefore there shouldn't be a default method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants