mit einem Klick
design-kubernetes-api
// Designs a best-practice, extensible Kubernetes API resource. Use when designing new API resources for Calico.
// Designs a best-practice, extensible Kubernetes API resource. Use when designing new API resources for Calico.
Reproduce CI test failures on a GCP VM matching the CI environment. Use when a CI job fails and the issue cannot be reproduced locally (e.g., kernel-dependent BPF verifier failures, kernel version-specific bugs).
Implements a new Calico API resource by plumbing it through all layers of the codebase. Use after API design is complete (see design-kubernetes-api skill).
| name | design-kubernetes-api |
| description | Designs a best-practice, extensible Kubernetes API resource. Use when designing new API resources for Calico. |
This is a common pattern in Kubernetes APIs that allows extension over time. It avoids bloating a parent struct with many fields that are mutually exclusive. For example, the various flavours of port/protocol match in a network policy rule may be expressed like this:
port:
number: 8080
or
port:
range:
min: 8000
max: 8080
or
port:
name: some-named-port
Pros:
// +kubebuilder:validation:MaxProperties=1
// +kubebuilder:validation:MinProperties=1 // If one must be provided
port:
mustMatchAll:
- range:
min: 8000
max: 8080
- portRemainder:
modulo: 3
remainder: 1
Calico API's typically use our selector syntax instead of Kubernetes matchLabels and similar.
New APIs should avoid matching multiple resource types with the same selector. We've learned that matching workload endpoints, host endpoints and network sets with the same selector is confusing, for example. Prefer one selector per type of thing that is matched.
Be critical of the need for a selector, referencing a single item by name/namespace is often simpler for the user. For example, we've found that most uses of network sets simply use a name label on the network set and select on that.
When selecting namespaced resources, use split namespaceSelector and itemTypeSelector.
port:
number: 8080
# Or...
range:
min: 8000
max: 8080
# Or...
namedPort: foo