Skip to content

Inconsistent APIs between Api::patch_status and Api::replace_status (unergonomic) #1778

@tgrushka

Description

@tgrushka

Current and expected behavior

Current

Calling replace_status, one must use this unergonomic (and I argue, unnecessary) extra serde_json::to_vec wrapper:

instances
    .replace_status(
        &name,
        &PostParams::default(),
        serde_json::to_vec(&serde_json::json!({ "status": initial_status }))?,
    )
    .await?;

Expected

But patch_status is much more idiomatic and should be the way that replace_status also works:

instances
    .patch_status(
        &name,
        &PatchParams::default(),
        &Patch::Merge(&serde_json::json!({ "status": ready_status })),
    )
    .await?;

Nice to have in the future (but would be a feature request and a major API change)

Why do we need the serde_json::json!({ "status": ready_status }) wrapper at all, when it should just be type-friendly (since Api<K> knows the type) and it could just be: .patch_status(... &Patch::Merge(ready_status)) or similar?

Possible solution

If it must use serde_json::to_vec internally, just make that internal. But I thought the kubernetes API just takes JSON anyway, so why does the API user need to convert it to the u8 vec first?

Additional context

No response

Environment

k3s / k3d -- but not really relevant, this is an API semantics issue

Configuration and features

No response

Affected crates

No response

Would you like to work on fixing this bug?

maybe

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions