Skip to content

03 Metadata

Daniel Morinigo edited this page Jan 15, 2020 · 2 revisions

Metadata

Official reference: Metadata

Besides TypeMeta data like kind and apiVersion as mentioned here, another important part is the ObjectMeta:

All common resources needs to have a metadata property to store the most common data among resources:

  • Name
  • Namespace (for namespaced objects)
  • Labels
  • Annotations
  • Other lifecycle management related: resourceVersion, ownerReferences
  • Controller initialization/termination: initializers, finalizers
// Pod is a collection of containers that can run on a host. This resource is created
// by clients and scheduled onto hosts.
type Pod struct {
	metav1.TypeMeta `json:",inline"`
	// Standard object's metadata.
	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
	// +optional
	metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

	// Specification of the desired behavior of the pod.
	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
	// +optional
	Spec PodSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`

	// Most recently observed status of the pod.
	// This data may not be up to date.
	// Populated by the system.
	// Read-only.
	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
	// +optional
	Status PodStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}

Spec and Status

Official reference: Spec/Status

As noted above we can observe that besides ObjectMeta, TypeMeta lots of resource will also adopt a Spec and a Status properties.

This is mostly to have a clear separation of concerns: in Kubernetes adopts a declarative approach, and resources' spec always describes a desired state, and the status always describes the current state in which it is currently located at. Controllers are then responsible to understand what is the desired state and try its best to achieve it, and report it inside the status property.

Clone this wiki locally