Skip to content
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

Allow default values to be set in the top level field of custom resources such as status, specs, etc. #1239

Open
kahirokunn opened this issue Jul 4, 2023 · 3 comments
Labels
derive kube-derive proc_macro related help wanted Not immediately prioritised, please help! question Direction unclear; possibly a bug, possibly could be improved.

Comments

@kahirokunn
Copy link

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

@clux
Copy link
Member

clux commented Jul 4, 2023

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 clux added help wanted Not immediately prioritised, please help! question Direction unclear; possibly a bug, possibly could be improved. derive kube-derive proc_macro related labels Jul 4, 2023
@kahirokunn
Copy link
Author

@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.

@kahirokunn
Copy link
Author

I would like to experience the same level of quality CRD as GatewayAPI with kube-rs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
derive kube-derive proc_macro related help wanted Not immediately prioritised, please help! question Direction unclear; possibly a bug, possibly could be improved.
Projects
None yet
Development

No branches or pull requests

2 participants