-
Notifications
You must be signed in to change notification settings - Fork 10
feat: migrate to Server-Side Apply (SSA) and enforce controller owner… #269
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,13 +30,31 @@ use conditions::*; | |
| use k8s_openapi::apimachinery::pkg::apis::meta::v1::{Condition, OwnerReference, Time}; | ||
| use kube::Resource; | ||
|
|
||
| pub const FIELD_MANAGER: &str = "trusted-cluster-operator"; | ||
|
|
||
| // 2 arms for updating status, one for normal updates and one for force updates. | ||
| #[macro_export] | ||
| macro_rules! update_status { | ||
| ($api:ident, $name:expr, $status:expr) => {{ | ||
| let patch = kube::api::Patch::Merge(serde_json::json!({"status": $status})); | ||
| $api.patch_status($name, &Default::default(), &patch).await | ||
| ($api:ident, $name:expr, $status:expr, $type:ty, $field_manager:expr) => {{ | ||
| let patch = kube::api::Patch::Apply(serde_json::json!({ | ||
| "apiVersion": <$type as kube::Resource>::api_version(&()), | ||
| "kind": <$type as kube::Resource>::kind(&()), | ||
| "status": $status | ||
| })); | ||
| let params = kube::api::PatchParams::apply($field_manager); | ||
| $api.patch_status($name, ¶ms, &patch).await | ||
| .map_err(Into::<anyhow::Error>::into) | ||
| }}; | ||
| ($api:ident, $name:expr, $status:expr, $type:ty, $field_manager:expr, force) => {{ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this sets the component (operator, compute-pcrs) as field manager for the status, but also just uses
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously, we had multiple writers to the Status Field of the ApprovedImage. the ComputePCR also updated the status with committed_condition (while status as PCR's are computing), and the operator requeued every 10 seconds to check whether the computation had completed and then updated the same field. To fix this, ideally we should have only the operator update the status of the field. We can discuss this design decision in detail with Alice.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Field manager is inherently a SSA concept, initially we had 2 writers to the same field, and updated it client side. There was no concept of field managers, because the client patch would overwrite any changes, even if written previously by another writer.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, we need to revisit the design of the approved images ideally, there should be a single writer. Let's discuss it today |
||
| let patch = kube::api::Patch::Apply(serde_json::json!({ | ||
| "apiVersion": <$type as kube::Resource>::api_version(&()), | ||
| "kind": <$type as kube::Resource>::kind(&()), | ||
| "status": $status | ||
| })); | ||
| let params = kube::api::PatchParams::apply($field_manager).force(); | ||
| $api.patch_status($name, ¶ms, &patch).await | ||
| .map_err(Into::<anyhow::Error>::into) | ||
| }} | ||
| }}; | ||
| } | ||
|
|
||
| pub fn condition_status(status: bool) -> String { | ||
|
|
@@ -108,8 +126,8 @@ pub fn committed_condition( | |
| } | ||
| } | ||
|
|
||
| /// Generate an OwnerReference for any Kubernetes resource | ||
| pub fn generate_owner_reference<T: Resource<DynamicType = ()>>( | ||
| /// OwnerReference with `controller: true` for lifecycle and garbage collection. | ||
| pub fn generate_owner_controller_reference<T: Resource<DynamicType = ()>>( | ||
|
Comment on lines
-111
to
+130
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure why this is necessary, it's not like there's a new function that this function's name must disambiguate from
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mainly to disambiguate between a controller owner, and a linking owner. |
||
| object: &T, | ||
| ) -> anyhow::Result<OwnerReference> { | ||
| let name = object.meta().name.clone(); | ||
|
|
||
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.
What's an owner-controller?
Uh oh!
There was an error while loading. Please reload this page.
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.
Previously, we had the function
generate_owner_referencewhich set controller to true.This is ambiguous, because not all owners are controllers. A k8s object can have only 1 controller in its set of owner references (here). It can however have multiple non-controller linking owner references.
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.
if we keep these renames and comment changes, I think they should be a separate commit. not sure if we do though, cc @alicefr
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.
yes, please try to generate clean commits it gets easier to review