kube
kube copied to clipboard
Allow default values to be set in the top level field of custom resources such as status, specs, etc.
Would you like to work on this feature?
None
What problem are you trying to solve?
I would like to be able to set the default status as follows.
https://raw.githubusercontent.com/kubernetes-sigs/gateway-api/v0.7.1/config/crd/standard/gateway.networking.k8s.io_gateways.yaml
status:
default:
conditions:
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: Waiting for controller
reason: Pending
status: Unknown
type: Accepted
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: Waiting for controller
reason: Pending
status: Unknown
type: Programmed
Describe the solution you'd like
Allow passing the default_status function
Describe alternatives you've considered
It would be nice to be able to set default_status
pub struct HogeStatus { ... }
fn default_status() -> Option<HogeStatus> {
Some(HogeStatus { ... })
}
#[kube(kind = "Hoge", group = "hoge.dev", version = "v1", namespace, status = "HogeStatus")]
#[kube(default_status = "default_status")]
pub struct HogeSpec { ... }
Documentation, Adoption, Migration Strategy
This allows full backward compatibility to be maintained
Target crate for feature
kube-derive
Does defaulting actually work on the apiserver side when you use big default structs like these in the gateway api?
The kubernetes schema default docs are pretty sparse.
If it does work, then something like this could make sense, but i feel like schemars is probably the better place to solve it with schemars supported attributes. They already support #[serde(default)] at both the struct and field level, so it might be worth figuring out what is missing there to get to where we need to go first.
As a starting point, we have an example that explores these attributes a bit in: https://github.com/kube-rs/kube/blob/main/examples/crd_derive_schema.rs#L69-L71
@clux
Does defaulting actually work on the apiserver side when you use big default structs like these in the gateway API?
Yes, I have verified and it does in fact work.
I would like to experience the same level of quality CRD as GatewayAPI with kube-rs.