Skip to content

Commit

Permalink
0.73.0 sync (#29)
Browse files Browse the repository at this point in the history
* Use kube-rs/kube#910

Signed-off-by: clux <[email protected]>

* PoC Predicates for kube-rs/kube#52

Signed-off-by: clux <[email protected]>

* remove predicate stuff

Signed-off-by: clux <[email protected]>

* undo crd update

Signed-off-by: clux <[email protected]>

* build from branch

Signed-off-by: clux <[email protected]>

* kube bump

Signed-off-by: clux <[email protected]>

* bump

Signed-off-by: clux <[email protected]>
  • Loading branch information
clux authored May 23, 2022
1 parent 607d824 commit 2976e04
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 32 deletions.
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "controller"
version = "0.12.1"
version = "0.12.2"
authors = ["clux <[email protected]>"]
edition = "2021"
default-run = "controller"
Expand Down Expand Up @@ -29,7 +29,7 @@ telemetry = ["tonic", "opentelemetry-otlp"]
actix-web = "4.0.1"
futures = "0.3.21"
tokio = { version = "1.18.2", features = ["macros", "rt-multi-thread"] }
k8s-openapi = { version = "0.14.0", features = ["v1_22"], default-features = false }
k8s-openapi = { version = "0.15.0", features = ["v1_23"], default-features = false }
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.79"
chrono = { version = "0.4.19", features = ["serde"] }
Expand All @@ -51,8 +51,9 @@ tonic = { version = "0.6.2", optional = true }

[dependencies.kube]
features = ["runtime", "client", "derive"]
version = "0.72.0"
version = "0.73.0"

# testing new releases - ignore
#git = "https://github.com/kube-rs/kube-rs.git"
#rev = "7715cabd4d1976493e6b8949471f283df927a79e"
#rev = "8dcd5c0865ad0a40520519032119fbe4ea5f85f7"
#path = "../kube-rs/kube"
28 changes: 13 additions & 15 deletions src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use kube::{
api::{Api, ListParams, Patch, PatchParams, ResourceExt},
client::Client,
runtime::{
controller::{Action, Context, Controller},
controller::{Action, Controller},
events::{Event, EventType, Recorder, Reporter},
},
CustomResource, Resource,
Expand Down Expand Up @@ -38,7 +38,6 @@ pub struct DocumentSpec {
#[derive(Deserialize, Serialize, Clone, Debug, JsonSchema)]
pub struct DocumentStatus {
hidden: bool,
//last_updated: Option<DateTime<Utc>>,
}

impl Document {
Expand All @@ -62,19 +61,20 @@ struct Data {
metrics: Metrics,
}


#[instrument(skip(ctx, doc), fields(trace_id))]
async fn reconcile(doc: Arc<Document>, ctx: Context<Data>) -> Result<Action, Error> {
async fn reconcile(doc: Arc<Document>, ctx: Arc<Data>) -> Result<Action, Error> {
let trace_id = telemetry::get_trace_id();
Span::current().record("trace_id", &field::display(&trace_id));
let start = Instant::now();
ctx.get_ref().metrics.reconciliations.inc();
ctx.metrics.reconciliations.inc();

let client = ctx.get_ref().client.clone();
ctx.get_ref().state.write().await.last_event = Utc::now();
let reporter = ctx.get_ref().state.read().await.reporter.clone();
let client = ctx.client.clone();
ctx.state.write().await.last_event = Utc::now();
let reporter = ctx.state.read().await.reporter.clone();
let recorder = Recorder::new(client.clone(), reporter, doc.object_ref(&()));
let name = ResourceExt::name(doc.as_ref());
let ns = ResourceExt::namespace(doc.as_ref()).expect("doc is namespaced");
let name = doc.name();
let ns = doc.namespace().unwrap();
let docs: Api<Document> = Api::namespaced(client, &ns);

let should_hide = doc.spec.hide;
Expand All @@ -97,7 +97,6 @@ async fn reconcile(doc: Arc<Document>, ctx: Context<Data>) -> Result<Action, Err
"kind": "Document",
"status": DocumentStatus {
hidden: should_hide,
//last_updated: Some(Utc::now()),
}
}));
let ps = PatchParams::apply("cntrlr").force();
Expand All @@ -108,8 +107,7 @@ async fn reconcile(doc: Arc<Document>, ctx: Context<Data>) -> Result<Action, Err

let duration = start.elapsed().as_millis() as f64 / 1000.0;
//let ex = Exemplar::new_with_labels(duration, HashMap::from([("trace_id".to_string(), trace_id)]);
ctx.get_ref()
.metrics
ctx.metrics
.reconcile_duration
.with_label_values(&[])
.observe(duration);
Expand All @@ -120,9 +118,9 @@ async fn reconcile(doc: Arc<Document>, ctx: Context<Data>) -> Result<Action, Err
Ok(Action::requeue(Duration::from_secs(30 * 60)))
}

fn error_policy(error: &Error, ctx: Context<Data>) -> Action {
fn error_policy(error: &Error, ctx: Arc<Data>) -> Action {
warn!("reconcile failed: {:?}", error);
ctx.get_ref().metrics.failures.inc();
ctx.metrics.failures.inc();
Action::requeue(Duration::from_secs(5 * 60))
}

Expand Down Expand Up @@ -190,7 +188,7 @@ impl Manager {
let client = Client::try_default().await.expect("create client");
let metrics = Metrics::new();
let state = Arc::new(RwLock::new(State::new()));
let context = Context::new(Data {
let context = Arc::new(Data {
client: client.clone(),
metrics: metrics.clone(),
state: state.clone(),
Expand Down

0 comments on commit 2976e04

Please sign in to comment.