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

Add EventRecorder abstraction. #653

Merged
merged 18 commits into from
Oct 17, 2021
Merged

Conversation

LukeMathWalker
Copy link
Contributor

Closes #249.

Signed-off-by: Luca Palmieri <lpalmieri@truelayer.com>
Luca Palmieri added 2 commits October 16, 2021 13:09
Signed-off-by: Luca Palmieri <lpalmieri@truelayer.com>
Signed-off-by: Luca Palmieri <lpalmieri@truelayer.com>
@LukeMathWalker LukeMathWalker marked this pull request as ready for review October 16, 2021 12:29
Copy link
Member

@clux clux left a comment

Choose a reason for hiding this comment

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

looks great! thanks a lot for doing this!

i've left a couple of minor comments on organisation and validation, but looks great right out of the bat!

kube-runtime/src/event_recorder/instance_name.rs Outdated Show resolved Hide resolved
kube-runtime/src/event_recorder/event.rs Outdated Show resolved Hide resolved
kube-runtime/src/event_recorder/recorder.rs Outdated Show resolved Hide resolved
kube-runtime/src/lib.rs Outdated Show resolved Hide resolved
kube-runtime/src/event_recorder/mod.rs Outdated Show resolved Hide resolved
LukeMathWalker added 8 commits October 17, 2021 10:27
Signed-off-by: Luca Palmieri <lpalmieri@truelayer.com>
Rename `instance_name` to `controller_pod_name`, including related structs.

Signed-off-by: Luca Palmieri <lpalmieri@truelayer.com>
Signed-off-by: Luca Palmieri <lpalmieri@truelayer.com>
…he Debug representation.

Signed-off-by: Luca Palmieri <lpalmieri@truelayer.com>
Signed-off-by: Luca Palmieri <lpalmieri@truelayer.com>
Signed-off-by: Luca Palmieri <lpalmieri@truelayer.com>
Signed-off-by: Luca Palmieri <lpalmieri@truelayer.com>
Signed-off-by: Luca Palmieri <lpalmieri@truelayer.com>
Luca Palmieri added 2 commits October 17, 2021 11:04
Signed-off-by: Luca Palmieri <lpalmieri@truelayer.com>
Signed-off-by: Luca Palmieri <lpalmieri@truelayer.com>
Copy link
Member

@clux clux left a comment

Choose a reason for hiding this comment

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

validation comments

Comment on lines +112 to +120
pub struct ControllerPodName(String);

impl TryFrom<&str> for ControllerPodName {
type Error = ControllerPodNameParsingError;

fn try_from(value: &str) -> Result<Self, Self::Error> {
Self::try_from(value.to_string())
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I am slightly unsure of whether we should provide this type of convenience validation here. On one hand it is nice and can catch things early, but on the other hand we have no way to know to enforce that the constants we put inside our code matches the kubernetes source (and i would rather rely on the api-server rejecting this, than reject things that are valid in the future).

In this particular case as well; if people get the pod name from the downward api (as in your documentation), it would be impossible to get an illegal name here, so I'm leaning towards just having an unchecked String here.

Copy link
Member

Choose a reason for hiding this comment

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

That said, it's nice for users to know as they are programming this. The event reason is very helpful for the user to know.

Copy link
Member

Choose a reason for hiding this comment

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

This might be a question for maintainers for later on how we can do better client-side validation (without it getting out of date). For now, happy to leave this in. It's a nice convenience.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally this validation should live inside k8s_openapi, so that it can be associated to a specific version of the API server and can be changed to match when new versions are released.
Happy to remove if you prefer to delegate to k8s API server.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Or Kubernetes packages up its validation stuff into a target that can be bound against multiple programming languages, ensuring consistent and up-to-date validation across the entire ecosystem for each version. Can a man dream?)

Copy link
Member

Choose a reason for hiding this comment

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

The sources that's used to generate the structs unfortunately does not have the information we need to do any type of newtype magic inside k8s-openapi or k8s-pb. So I think it's going to be a best-effort setup either way.

In this case, we are presenting an api on top of core::v1::Event though, so it's probably better to leave the validation herein.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then this is ready to go 😁

Copy link
Member

Choose a reason for hiding this comment

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

Thank you very much! Merged it in. Started a discussion internally around the future of client-side validation in #654

Will otherwise release this in the next version (after the super-crate issue gets resolved I am thinking).

kube-runtime/src/events/event.rs Outdated Show resolved Hide resolved
kube-runtime/src/events/event.rs Outdated Show resolved Hide resolved
Luca Palmieri added 3 commits October 17, 2021 11:14
Signed-off-by: Luca Palmieri <lpalmieri@truelayer.com>
Signed-off-by: Luca Palmieri <lpalmieri@truelayer.com>
Signed-off-by: Luca Palmieri <lpalmieri@truelayer.com>
@clux
Copy link
Member

clux commented Oct 17, 2021

cargo deny failures are #650 - don't worry about it for now.

Luca Palmieri added 2 commits October 17, 2021 11:18
Signed-off-by: Luca Palmieri <lpalmieri@truelayer.com>
Signed-off-by: Luca Palmieri <lpalmieri@truelayer.com>
@clux clux merged commit 14033ba into kube-rs:master Oct 17, 2021
nightkr added a commit to nightkr/kube-rs that referenced this pull request Oct 18, 2021
A bunch of Clippy errors slipped in with kube-rs#653, which weren't picked up since
Clippy was set up to only cover the main `kube` crate.
nightkr added a commit to nightkr/kube-rs that referenced this pull request Oct 18, 2021
A bunch of Clippy errors slipped in with kube-rs#653, which weren't picked up since
Clippy was set up to only cover the main `kube` crate.

Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>
nightkr added a commit to nightkr/kube-rs that referenced this pull request Oct 18, 2021
A bunch of Clippy errors slipped in with kube-rs#653, which weren't picked up since
Clippy was set up to only cover the main `kube` crate.

Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>
nightkr added a commit to nightkr/kube-rs that referenced this pull request Oct 18, 2021
Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>
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.

Adding EventRecorder api
2 participants