Kubernetes - API Machinery

Last Updated: 2022-11-13

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 include k8s.io/kubernetes, k8s.io/client-go, k8s.io/apiserver). For universal lower-level data structures like apiVersion, kind, name, uid, creationTimestamp, etc. Also TypeMeta, 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)



Scheme is the scheme used to resolve runtime.Objects to GroupVersionKinds / Resources.

Every set of controllers needs a Scheme, which provides mappings between Kinds 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)