Skip to content

Commit c751449

Browse files
committed
test out new event recorder interface
for kube-rs/kube#1655 Signed-off-by: clux <[email protected]>
1 parent 80c856e commit c751449

File tree

3 files changed

+49
-31
lines changed

3 files changed

+49
-31
lines changed

Cargo.lock

Lines changed: 19 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ tower-test = "0.4.0"
5353

5454
[dependencies.kube]
5555
features = ["runtime", "client", "derive" ]
56-
version = "0.97.0"
56+
#version = "0.97.0"
5757

5858
# testing new releases - ignore
5959
#git = "https://github.com/kube-rs/kube.git"
6060
#branch = "main"
6161
#rev = "19b90ad3a4dbc83e1dd742847c7707333259b1bb"
62-
#path = "../kube/kube"
62+
path = "../kube/kube"

src/controller.rs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ pub static DOCUMENT_FINALIZER: &str = "documents.kube.rs";
2424
/// Generate the Kubernetes wrapper struct `Document` from our Spec and Status struct
2525
///
2626
/// This provides a hook for generating the CRD yaml (in crdgen.rs)
27+
/// NB: CustomResource generates a pub struct Document here
28+
/// To query for documents.kube.rs with kube, use Api<Document>.
2729
#[derive(CustomResource, Deserialize, Serialize, Clone, Debug, JsonSchema)]
2830
#[cfg_attr(test, derive(Default))]
2931
#[kube(kind = "Document", group = "kube.rs", version = "v1", namespaced)]
@@ -88,7 +90,8 @@ impl Document {
8890
// Reconcile (for non-finalizer related changes)
8991
async fn reconcile(&self, ctx: Arc<Context>) -> Result<Action> {
9092
let client = ctx.client.clone();
91-
let recorder = ctx.diagnostics.read().await.recorder(client.clone(), self);
93+
let recorder = ctx.diagnostics.read().await.recorder(client.clone());
94+
let oref = self.object_ref(&());
9295
let ns = self.namespace().unwrap();
9396
let name = self.name_any();
9497
let docs: Api<Document> = Api::namespaced(client, &ns);
@@ -97,13 +100,16 @@ impl Document {
97100
if !self.was_hidden() && should_hide {
98101
// send an event once per hide
99102
recorder
100-
.publish(Event {
101-
type_: EventType::Normal,
102-
reason: "HideRequested".into(),
103-
note: Some(format!("Hiding `{name}`")),
104-
action: "Hiding".into(),
105-
secondary: None,
106-
})
103+
.publish(
104+
Event {
105+
type_: EventType::Normal,
106+
reason: "HideRequested".into(),
107+
note: Some(format!("Hiding `{name}`")),
108+
action: "Hiding".into(),
109+
secondary: None,
110+
},
111+
&oref,
112+
)
107113
.await
108114
.map_err(Error::KubeError)?;
109115
}
@@ -130,16 +136,20 @@ impl Document {
130136

131137
// Finalizer cleanup (the object was deleted, ensure nothing is orphaned)
132138
async fn cleanup(&self, ctx: Arc<Context>) -> Result<Action> {
133-
let recorder = ctx.diagnostics.read().await.recorder(ctx.client.clone(), self);
139+
let recorder = ctx.diagnostics.read().await.recorder(ctx.client.clone());
140+
let oref = self.object_ref(&());
134141
// Document doesn't have any real cleanup, so we just publish an event
135142
recorder
136-
.publish(Event {
137-
type_: EventType::Normal,
138-
reason: "DeleteRequested".into(),
139-
note: Some(format!("Delete `{}`", self.name_any())),
140-
action: "Deleting".into(),
141-
secondary: None,
142-
})
143+
.publish(
144+
Event {
145+
type_: EventType::Normal,
146+
reason: "DeleteRequested".into(),
147+
note: Some(format!("Delete `{}`", self.name_any())),
148+
action: "Deleting".into(),
149+
secondary: None,
150+
},
151+
&oref,
152+
)
143153
.await
144154
.map_err(Error::KubeError)?;
145155
Ok(Action::await_change())
@@ -163,8 +173,8 @@ impl Default for Diagnostics {
163173
}
164174
}
165175
impl Diagnostics {
166-
fn recorder(&self, client: Client, doc: &Document) -> Recorder {
167-
Recorder::new(client, self.reporter.clone(), doc.object_ref(&()))
176+
fn recorder(&self, client: Client) -> Recorder {
177+
Recorder::new(client, self.reporter.clone())
168178
}
169179
}
170180

0 commit comments

Comments
 (0)