Kubernetes - API Machinery
To make sure that working with one Kubernetes resource feels exactly the same as with any other Kubernetes resources, including custom resources.
It's achieved through common k8s.io/api
and k8s.io/apimachinery
modules that are used on both client- (client-go, kubectl, etc.) and server-side (api-server), as well as in the majority of the third-party tools and controllers.
k8s.io/apimachinery
: a shared dependency for servers and clients to work with Kubernetes APIs. (Consumers includek8s.io/kubernetes
,k8s.io/client-go
,k8s.io/apiserver
). For universal lower-level data structures likeapiVersion
,kind
,name
,uid
,creationTimestamp
, etc. AlsoTypeMeta
,ObjectMeta
.- Object Serialization to JSON, YAML, or Protobuf
- Scheme (
runtime.Scheme
) and RESTMapper - Field and Label Selectors (
k8s.io/apimachinery/pkg/labels
) - API Error Handling(
k8s.io/apimachinery/pkg/api/errors
) - Utils (
apimachinery/pkg/util
)
https://kubernetespodcast.com/episode/073-crds-extensibility-api-machinery/
Scheme
Scheme
is the scheme used to resolve runtime.Objects
to GroupVersionKind
s / Resources.
Every set of controllers needs a Scheme
, which provides mappings between Kind
s and their corresponding Go types.
create a new Scheme: var scheme = runtime.NewScheme()
The runtime.Scheme
struct is such a registry containing the kind to type and type to kind mappings for all kinds of Kubernetes objects.
How to check conditions
// "k8s.io/apimachinery/pkg/api/meta"
conds := Foo.Status.Conditions
meta.IsStatusConditionTrue(conds, conditionType)