-
Notifications
You must be signed in to change notification settings - Fork 49
Description
Having .metadata.name and .metadata.namespace as optional causes us headaches all over our code. We either have to decide unwrap because we know the value will be there, or implement Result for the case of a missing value that will never be missing.
In reality a Kubernetes object without a name (baring the edge case of asking Kubernetes to generate the name) is invalid; likewise a namespace scoped Kubernetes object without a namespace is invalid. As mentioned above this means unnecessary error handle, and allows the creation of resources without a name and/or namespace which appear to be perfectly valid until you attempt to submit them to Kubernetes.
I propose that there should be four versions of ObjectMeta to cover the valid cases and simplify the 99% usage cases.
For namespaced resources:
mod namespaced {
struct ObjectMeta {
name: String,
namespace: String,
...
}
}
For cluster resources:
mod cluster {
struct ObjectMeta {
name: String,
// no namespace field
...
}
}
For namespaced resources which can take generate_name
mod namespaced_with_generate_name {
struct ObjectMeta {
name: Option<String>,
namespace: String,
...
}
}
mod cluster_with_generate_name {
struct ObjectMeta {
name: Option<String>,
// no namespace field
...
}
}
Alternatively each resource could generate its own version of ObjectMeta which is valid and correct for that resource.