Weird Api Choices
Map vs. discriminative arrays (map key -> discriminative name)
From docker inspect
:
{
"Networks": {
"bridge": {
"IPAddress": "172.17.0.2"
},
"kind": {
"IPAddress": "172.18.0.2"
}
}
}
versus:
{
Networks: [
{
Name: "bridge"
IPAddress: "172.17.0.2"
},
{
Name: "kind",
IPAddress: "172.18.0.2"
}
]
}
Polymorphic vs. discriminative array (polymorphic object -> discriminative type)
From the Service type in Kubernetes:
status:
loadBalancer:
ingress:
- ip: 35.67.89.10
- ip: 35.67.89.11
- hostname: nginx-test.gcp-1.helix.engineering
It is confusing: can we have an object with both “ip” and “hostname” set? The answer is no: the kubectl describe
code here makes it clear that “ip” and “hostname” are mutually exclusive.
Using a discriminative “type” field helps:
status:
loadBalancer:
ingress:
- type: ip
address: 35.67.89.10
- type: ip
address: 35.67.89.11
- type: hostname
address: nginx-test.gcp-1.helix.engineering