api.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Package kubeapi contains Kubernetes API types for internal consumption.
  4. // These types are split into a separate package for consumption of
  5. // non-Kubernetes shared libraries and binaries. Be mindful of not increasing
  6. // dependency size for those consumers when adding anything new here.
  7. package kubeapi
  8. import (
  9. "time"
  10. )
  11. // Note: The API types are copied from k8s.io/api{,machinery} to not introduce a
  12. // module dependency on the Kubernetes API as it pulls in many more dependencies.
  13. // TypeMeta describes an individual object in an API response or request with
  14. // strings representing the type of the object and its API schema version.
  15. // Structures that are versioned or persisted should inline TypeMeta.
  16. type TypeMeta struct {
  17. // Kind is a string value representing the REST resource this object represents.
  18. // Servers may infer this from the endpoint the client submits requests to.
  19. // Cannot be updated.
  20. // In CamelCase.
  21. // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
  22. // +optional
  23. Kind string `json:"kind,omitempty"`
  24. // APIVersion defines the versioned schema of this representation of an object.
  25. // Servers should convert recognized schemas to the latest internal value, and
  26. // may reject unrecognized values.
  27. // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
  28. // +optional
  29. APIVersion string `json:"apiVersion,omitempty"`
  30. }
  31. // ObjectMeta is metadata that all persisted resources must have, which
  32. // includes all objects users must create.
  33. type ObjectMeta struct {
  34. // Name must be unique within a namespace. Is required when creating resources, although
  35. // some resources may allow a client to request the generation of an appropriate name
  36. // automatically. Name is primarily intended for creation idempotence and configuration
  37. // definition.
  38. // Cannot be updated.
  39. // More info: http://kubernetes.io/docs/user-guide/identifiers#names
  40. // +optional
  41. Name string `json:"name"`
  42. // Namespace defines the space within which each name must be unique. An empty namespace is
  43. // equivalent to the "default" namespace, but "default" is the canonical representation.
  44. // Not all objects are required to be scoped to a namespace - the value of this field for
  45. // those objects will be empty.
  46. //
  47. // Must be a DNS_LABEL.
  48. // Cannot be updated.
  49. // More info: http://kubernetes.io/docs/user-guide/namespaces
  50. // +optional
  51. Namespace string `json:"namespace"`
  52. // UID is the unique in time and space value for this object. It is typically generated by
  53. // the server on successful creation of a resource and is not allowed to change on PUT
  54. // operations.
  55. //
  56. // Populated by the system.
  57. // Read-only.
  58. // More info: http://kubernetes.io/docs/user-guide/identifiers#uids
  59. // +optional
  60. UID string `json:"uid,omitempty"`
  61. // An opaque value that represents the internal version of this object that can
  62. // be used by clients to determine when objects have changed. May be used for optimistic
  63. // concurrency, change detection, and the watch operation on a resource or set of resources.
  64. // Clients must treat these values as opaque and passed unmodified back to the server.
  65. // They may only be valid for a particular resource or set of resources.
  66. //
  67. // Populated by the system.
  68. // Read-only.
  69. // Value must be treated as opaque by clients and .
  70. // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency
  71. // +optional
  72. ResourceVersion string `json:"resourceVersion,omitempty"`
  73. // A sequence number representing a specific generation of the desired state.
  74. // Populated by the system. Read-only.
  75. // +optional
  76. Generation int64 `json:"generation,omitempty"`
  77. // CreationTimestamp is a timestamp representing the server time when this object was
  78. // created. It is not guaranteed to be set in happens-before order across separate operations.
  79. // Clients may not set this value. It is represented in RFC3339 form and is in UTC.
  80. //
  81. // Populated by the system.
  82. // Read-only.
  83. // Null for lists.
  84. // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
  85. // +optional
  86. CreationTimestamp time.Time `json:"creationTimestamp,omitempty"`
  87. // DeletionTimestamp is RFC 3339 date and time at which this resource will be deleted. This
  88. // field is set by the server when a graceful deletion is requested by the user, and is not
  89. // directly settable by a client. The resource is expected to be deleted (no longer visible
  90. // from resource lists, and not reachable by name) after the time in this field, once the
  91. // finalizers list is empty. As long as the finalizers list contains items, deletion is blocked.
  92. // Once the deletionTimestamp is set, this value may not be unset or be set further into the
  93. // future, although it may be shortened or the resource may be deleted prior to this time.
  94. // For example, a user may request that a pod is deleted in 30 seconds. The Kubelet will react
  95. // by sending a graceful termination signal to the containers in the pod. After that 30 seconds,
  96. // the Kubelet will send a hard termination signal (SIGKILL) to the container and after cleanup,
  97. // remove the pod from the API. In the presence of network partitions, this object may still
  98. // exist after this timestamp, until an administrator or automated process can determine the
  99. // resource is fully terminated.
  100. // If not set, graceful deletion of the object has not been requested.
  101. //
  102. // Populated by the system when a graceful deletion is requested.
  103. // Read-only.
  104. // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
  105. // +optional
  106. DeletionTimestamp *time.Time `json:"deletionTimestamp,omitempty"`
  107. // Number of seconds allowed for this object to gracefully terminate before
  108. // it will be removed from the system. Only set when deletionTimestamp is also set.
  109. // May only be shortened.
  110. // Read-only.
  111. // +optional
  112. DeletionGracePeriodSeconds *int64 `json:"deletionGracePeriodSeconds,omitempty"`
  113. // Map of string keys and values that can be used to organize and categorize
  114. // (scope and select) objects. May match selectors of replication controllers
  115. // and services.
  116. // More info: http://kubernetes.io/docs/user-guide/labels
  117. // +optional
  118. Labels map[string]string `json:"labels,omitempty"`
  119. // Annotations is an unstructured key value map stored with a resource that may be
  120. // set by external tools to store and retrieve arbitrary metadata. They are not
  121. // queryable and should be preserved when modifying objects.
  122. // More info: http://kubernetes.io/docs/user-guide/annotations
  123. // +optional
  124. Annotations map[string]string `json:"annotations,omitempty"`
  125. }
  126. // Secret holds secret data of a certain type. The total bytes of the values
  127. // in the Data field must be less than MaxSecretSize bytes.
  128. type Secret struct {
  129. TypeMeta `json:",inline"`
  130. ObjectMeta `json:"metadata"`
  131. // Data contains the secret data. Each key must consist of alphanumeric
  132. // characters, '-', '_' or '.'. The serialized form of the secret data is a
  133. // base64 encoded string, representing the arbitrary (possibly non-string)
  134. // data value here. Described in https://tools.ietf.org/html/rfc4648#section-4
  135. // +optional
  136. Data map[string][]byte `json:"data,omitempty"`
  137. }
  138. // SecretList is a list of Secret objects.
  139. type SecretList struct {
  140. TypeMeta `json:",inline"`
  141. ObjectMeta `json:"metadata"`
  142. Items []Secret `json:"items,omitempty"`
  143. }
  144. // Event contains a subset of fields from corev1.Event.
  145. // https://github.com/kubernetes/api/blob/6cc44b8953ae704d6d9ec2adf32e7ae19199ea9f/core/v1/types.go#L7034
  146. // It is copied here to avoid having to import kube libraries.
  147. type Event struct {
  148. TypeMeta `json:",inline"`
  149. ObjectMeta `json:"metadata"`
  150. Message string `json:"message,omitempty"`
  151. Reason string `json:"reason,omitempty"`
  152. Source EventSource `json:"source,omitempty"` // who is emitting this Event
  153. Type string `json:"type,omitempty"` // Normal or Warning
  154. // InvolvedObject is the subject of the Event. `kubectl describe` will, for most object types, display any
  155. // currently present cluster Events matching the object (but you probably want to set UID for this to work).
  156. InvolvedObject ObjectReference `json:"involvedObject"`
  157. Count int32 `json:"count,omitempty"` // how many times Event was observed
  158. FirstTimestamp time.Time `json:"firstTimestamp,omitempty"`
  159. LastTimestamp time.Time `json:"lastTimestamp,omitempty"`
  160. }
  161. // EventSource includes a subset of fields from corev1.EventSource.
  162. // https://github.com/kubernetes/api/blob/6cc44b8953ae704d6d9ec2adf32e7ae19199ea9f/core/v1/types.go#L7007
  163. // It is copied here to avoid having to import kube libraries.
  164. type EventSource struct {
  165. // Component is the name of the component that is emitting the Event.
  166. Component string `json:"component,omitempty"`
  167. }
  168. // ObjectReference contains a subset of fields from corev1.ObjectReference.
  169. // https://github.com/kubernetes/api/blob/6cc44b8953ae704d6d9ec2adf32e7ae19199ea9f/core/v1/types.go#L6902
  170. // It is copied here to avoid having to import kube libraries.
  171. type ObjectReference struct {
  172. // Kind of the referent.
  173. // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
  174. // +optional
  175. Kind string `json:"kind,omitempty"`
  176. // Namespace of the referent.
  177. // More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
  178. // +optional
  179. Namespace string `json:"namespace,omitempty"`
  180. // Name of the referent.
  181. // More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
  182. // +optional
  183. Name string `json:"name,omitempty"`
  184. // UID of the referent.
  185. // More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids
  186. // +optional
  187. UID string `json:"uid,omitempty"`
  188. // API version of the referent.
  189. // +optional
  190. APIVersion string `json:"apiVersion,omitempty"`
  191. }
  192. // Status is a return value for calls that don't return other objects.
  193. type Status struct {
  194. TypeMeta `json:",inline"`
  195. // Status of the operation.
  196. // One of: "Success" or "Failure".
  197. // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
  198. // +optional
  199. Status string `json:"status,omitempty"`
  200. // A human-readable description of the status of this operation.
  201. // +optional
  202. Message string `json:"message,omitempty"`
  203. // A machine-readable description of why this operation is in the
  204. // "Failure" status. If this value is empty there
  205. // is no information available. A Reason clarifies an HTTP status
  206. // code but does not override it.
  207. // +optional
  208. Reason string `json:"reason,omitempty"`
  209. // Extended data associated with the reason. Each reason may define its
  210. // own extended details. This field is optional and the data returned
  211. // is not guaranteed to conform to any schema except that defined by
  212. // the reason type.
  213. // +optional
  214. Details *struct {
  215. Name string `json:"name,omitempty"`
  216. Kind string `json:"kind,omitempty"`
  217. } `json:"details,omitempty"`
  218. // Suggested HTTP return code for this status, 0 if not set.
  219. // +optional
  220. Code int `json:"code,omitempty"`
  221. }
  222. func (s Status) Error() string {
  223. return s.Message
  224. }