Comments (3)
Tried to write something that sets .status.conditions
yesterday. I find the setup really awkward to deal with for most of the reasons outline in this comment from the already linked thread.
Regardless, here's some sample code that goes down both the .status.conditions
and .status.phases
path:
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ManifestStatus {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub conditions: Vec<ApplyCondition>,
phase: ApplyPhase,
start_time: String,
}
/// ApplyCondition
///
/// Meant to act like normal kubernetes conditions like PodCondition:
///
/// - lastProbeTime: null
/// lastTransitionTime: "2019-07-31T13:07:30Z"
/// message: 'containers with unready status: [product-config]'
/// reason: ContainersNotReady
/// status: "False"
/// type: ContainersReady
///
/// We do not post lastProbeTime / lastHeartbeatTime because they are expensive.
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct ApplyCondition {
/// Whether or not in a good state
///
/// This must default to true when in a good state
pub status: bool,
/// Error reason type if not in a good state
#[serde(default, skip_serializing_if = "Option::is_none")]
pub reason: Option<String>,
/// One sentence error message if not in a good state
#[serde(default, skip_serializing_if = "Option::is_none")]
pub message: Option<String>,
/// The type of condition we export
///
/// This is an extensible enum. Conditions we don't know about gets thrown away.
#[serde(rename = "type")]
pub type_: ConditionType,
/// When the condition was last written in a RFC 3339 format
///
/// Format == `1996-12-19T16:39:57-08:00`, but we hardcode Utc herein.
#[serde(rename = "lastTransitionTime")]
pub last_transition: String
}
/// Allowed condition types we always export all of.
///
/// This does not describe a state machine. We set conditions as they happen.
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq, Default)]
pub enum ConditionType {
/// Applied to kubernetes
///
/// If this is false, it might contain information about:
/// - invalid yaml, or not passing admission controllers logic
/// - network errors
Applied,
/// Rollout of current shipcatmanifest succeeded
///
/// If this is false, it's likely the deployment(s) failing to come online.
/// Best effort information given in message, but this won't replace DeploymentConditions
RolledOut,
/// Cach all event that we don't emit (forwards compat on api side)
#[serde(other, skip_serializing)]
Unknown
}
/// A high-level summary of where the service is in its lifecycle.
///
/// It is not intended to be a comprehensive rollup of state, nor intended to be
/// a comprehensive state machine.
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)]
pub enum ApplyPhase {
/// The service started the apply process and has passed manifest validation
Pending,
/// The service configuration has been sent to kubernetes without errors.
Running,
/// The applied configuration has rolled out in all resources.
Succeeded,
/// The rollout did not complete successfully
Failed,
/// Cach all event that we don't emit (forwards compat on api side)
#[serde(other, skip_serializing)]
Unknown
}
impl Default for ConditionType {
fn default() -> Self {
ConditionType::Unknown
}
}
which obviously needs to come with a bunch of helper functions to create, get, update, the conditions:
impl ApplyCondition {
fn resolved_secret_ok() -> Self {
ApplyCondition {
status: true,
type_: ConditionType::SecretsResolved,
last_transition: Utc::now().to_rfc3339(),
..Default::default(),
}
}
}
This was my attempt to codify conditions and phases we normally pass through, and follow best practices at the same time.
Funnily, I can use enums in rust to enumerate the known states, even though kube devs are like:
Enums aren't extensible. Every addition is a breaking, non-backward-compatible API change.
Nuh, uh. That's a language assumption.
At any rate, despite all the fuzz in that thread, it doesn't look like conditions are going to be removed. Will write some more code and see if I can port something general in to this library, but this might all need to be at the controller level.
from kube.
Well. Conditions suck.
You cannot really patch_status
to update particular condition entry AFAIKT:
- merge patch obviously won't support this (merges a vector)
- json patch doesn't support this (cannot replace array entry by field name) - see rfc6902
- strategic merge patch support is not even planned to have support for custom resources - kubernetes#58414
I'm gonna have to prod more directly.
from kube.
Have asked around and tested out this a bit now and am just going to say that unless you can wait for at least kubernetes 1.15
for server-side apply (and even that might not do it work custom resources that can't have strategic merge patch support), don't bother with a standard .conditions
vector format for custom resources.
Named field fixes most of the problems, makes your code simpler, and makes consuming them simpler. Optionality give them same API benefits, and are way easier to merge.
From the linked PR, I have been making a struct with named fields for Conditions, and updating the status with merge patch which lets you null things out if you are careful with serde annotations.
Marking this as a WONTFIX.
from kube.
Related Issues (20)
- RUSTSEC-2023-0052: webpki: CPU denial of service in certificate path building HOT 1
- `ApiGroup::recommended_kind` returns `None` while I expected `Some(_)` HOT 1
- Check HTTP status code in `request_stream` HOT 3
- Watch not triggering reconciliation HOT 9
- Authentication fails with custom kubectl plugin HOT 3
- developer meeting experiment HOT 6
- Controller concurrency appears to cause reconciliations to be skipped HOT 4
- Simplify `kubecl get --raw` style custom queries with `Request` HOT 2
- Support for ProvideClusterInfo in exec HOT 2
- 0.87 release planned 🎃 HOT 12
- Minimum supported rustls version is `0.21.4` not `0.21.0`
- Dependency upgrades for `hyper` and `http` 1.0 HOT 11
- HTTP proxy support HOT 1
- Refactoring Version Dependencies
- Better support for `x-kubernetes` properties in schemas HOT 1
- set controller reconciliation period HOT 1
- 404 Not Found HOT 2
- Discovery fails when ApiResourceList is not apiVersion v1 HOT 5
- release planned 0.87.2
- More ergonomic ListParams::labels HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kube.