api.go 8.3 KB

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