kube

package
v1.56.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2023 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package kube provides a client to interact with Kubernetes. This package is Tailscale-internal and not meant for external consumption. Further, the API should not be considered stable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetRootPathForTesting added in v1.38.0

func SetRootPathForTesting(p string)

SetRootPathForTesting sets the path to the service account directory.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client handles connections to Kubernetes. It expects to be run inside a cluster.

func New

func New() (*Client, error)

New returns a new client

func (*Client) CheckSecretPermissions added in v1.38.0

func (c *Client) CheckSecretPermissions(ctx context.Context, secretName string) (canPatch bool, err error)

CheckSecretPermissions checks the secret access permissions of the current pod. It returns an error if the basic permissions tailscale needs are missing, and reports whether the patch permission is additionally present.

Errors encountered during the access checking process are logged, but ignored so that the pod tries to fail alive if the permissions exist and there's just something wrong with SelfSubjectAccessReviews. There shouldn't be, pods should always be able to use SSARs to assess their own permissions, but since we didn't use to check permissions this way we'll be cautious in case some old version of k8s deviates from the current behavior.

func (*Client) CreateSecret

func (c *Client) CreateSecret(ctx context.Context, s *Secret) error

CreateSecret creates a secret in the Kubernetes API.

func (*Client) GetSecret

func (c *Client) GetSecret(ctx context.Context, name string) (*Secret, error)

GetSecret fetches the secret from the Kubernetes API.

func (*Client) JSONPatchSecret added in v1.38.0

func (c *Client) JSONPatchSecret(ctx context.Context, name string, patch []JSONPatch) error

JSONPatchSecret updates a secret in the Kubernetes API using a JSON patch. It currently (2023-03-02) only supports the "remove" operation.

func (*Client) SetDialer added in v1.40.0

func (c *Client) SetDialer(dialer func(ctx context.Context, network, addr string) (net.Conn, error))

SetDialer sets the dialer to use when establishing a connection to the Kubernetes API server.

func (*Client) SetURL added in v1.38.0

func (c *Client) SetURL(url string)

SetURL sets the URL to use for the Kubernetes API. This is used only for testing.

func (*Client) StrategicMergePatchSecret added in v1.38.0

func (c *Client) StrategicMergePatchSecret(ctx context.Context, name string, s *Secret, fieldManager string) error

StrategicMergePatchSecret updates a secret in the Kubernetes API using a strategic merge patch. If a fieldManager is provided, it will be used to track the patch.

func (*Client) UpdateSecret

func (c *Client) UpdateSecret(ctx context.Context, s *Secret) error

UpdateSecret updates a secret in the Kubernetes API.

type JSONPatch added in v1.38.0

type JSONPatch struct {
	Op    string `json:"op"`
	Path  string `json:"path"`
	Value any    `json:"value,omitempty"`
}

JSONPatch is a JSON patch operation. It currently (2023-03-02) only supports the "remove" operation.

https://tools.ietf.org/html/rfc6902

type ObjectMeta

type ObjectMeta struct {
	// Name must be unique within a namespace. Is required when creating resources, although
	// some resources may allow a client to request the generation of an appropriate name
	// automatically. Name is primarily intended for creation idempotence and configuration
	// definition.
	// Cannot be updated.
	// More info: http://kubernetes.io/docs/user-guide/identifiers#names
	// +optional
	Name string `json:"name"`

	// Namespace defines the space within which each name must be unique. An empty namespace is
	// equivalent to the "default" namespace, but "default" is the canonical representation.
	// Not all objects are required to be scoped to a namespace - the value of this field for
	// those objects will be empty.
	//
	// Must be a DNS_LABEL.
	// Cannot be updated.
	// More info: http://kubernetes.io/docs/user-guide/namespaces
	// +optional
	Namespace string `json:"namespace"`

	// UID is the unique in time and space value for this object. It is typically generated by
	// the server on successful creation of a resource and is not allowed to change on PUT
	// operations.
	//
	// Populated by the system.
	// Read-only.
	// More info: http://kubernetes.io/docs/user-guide/identifiers#uids
	// +optional
	UID string `json:"uid,omitempty"`

	// An opaque value that represents the internal version of this object that can
	// be used by clients to determine when objects have changed. May be used for optimistic
	// concurrency, change detection, and the watch operation on a resource or set of resources.
	// Clients must treat these values as opaque and passed unmodified back to the server.
	// They may only be valid for a particular resource or set of resources.
	//
	// Populated by the system.
	// Read-only.
	// Value must be treated as opaque by clients and .
	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency
	// +optional
	ResourceVersion string `json:"resourceVersion,omitempty"`

	// A sequence number representing a specific generation of the desired state.
	// Populated by the system. Read-only.
	// +optional
	Generation int64 `json:"generation,omitempty"`

	// CreationTimestamp is a timestamp representing the server time when this object was
	// created. It is not guaranteed to be set in happens-before order across separate operations.
	// Clients may not set this value. It is represented in RFC3339 form and is in UTC.
	//
	// Populated by the system.
	// Read-only.
	// Null for lists.
	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
	// +optional
	CreationTimestamp time.Time `json:"creationTimestamp,omitempty"`

	// DeletionTimestamp is RFC 3339 date and time at which this resource will be deleted. This
	// field is set by the server when a graceful deletion is requested by the user, and is not
	// directly settable by a client. The resource is expected to be deleted (no longer visible
	// from resource lists, and not reachable by name) after the time in this field, once the
	// finalizers list is empty. As long as the finalizers list contains items, deletion is blocked.
	// Once the deletionTimestamp is set, this value may not be unset or be set further into the
	// future, although it may be shortened or the resource may be deleted prior to this time.
	// For example, a user may request that a pod is deleted in 30 seconds. The Kubelet will react
	// by sending a graceful termination signal to the containers in the pod. After that 30 seconds,
	// the Kubelet will send a hard termination signal (SIGKILL) to the container and after cleanup,
	// remove the pod from the API. In the presence of network partitions, this object may still
	// exist after this timestamp, until an administrator or automated process can determine the
	// resource is fully terminated.
	// If not set, graceful deletion of the object has not been requested.
	//
	// Populated by the system when a graceful deletion is requested.
	// Read-only.
	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
	// +optional
	DeletionTimestamp *time.Time `json:"deletionTimestamp,omitempty"`

	// Number of seconds allowed for this object to gracefully terminate before
	// it will be removed from the system. Only set when deletionTimestamp is also set.
	// May only be shortened.
	// Read-only.
	// +optional
	DeletionGracePeriodSeconds *int64 `json:"deletionGracePeriodSeconds,omitempty"`

	// Map of string keys and values that can be used to organize and categorize
	// (scope and select) objects. May match selectors of replication controllers
	// and services.
	// More info: http://kubernetes.io/docs/user-guide/labels
	// +optional
	Labels map[string]string `json:"labels,omitempty"`

	// Annotations is an unstructured key value map stored with a resource that may be
	// set by external tools to store and retrieve arbitrary metadata. They are not
	// queryable and should be preserved when modifying objects.
	// More info: http://kubernetes.io/docs/user-guide/annotations
	// +optional
	Annotations map[string]string `json:"annotations,omitempty"`
}

ObjectMeta is metadata that all persisted resources must have, which includes all objects users must create.

type Secret

type Secret struct {
	TypeMeta   `json:",inline"`
	ObjectMeta `json:"metadata"`

	// Data contains the secret data. Each key must consist of alphanumeric
	// characters, '-', '_' or '.'. The serialized form of the secret data is a
	// base64 encoded string, representing the arbitrary (possibly non-string)
	// data value here. Described in https://tools.ietf.org/html/rfc4648#section-4
	// +optional
	Data map[string][]byte `json:"data,omitempty"`
}

Secret holds secret data of a certain type. The total bytes of the values in the Data field must be less than MaxSecretSize bytes.

type Status

type Status struct {
	TypeMeta `json:",inline"`
	// Status of the operation.
	// One of: "Success" or "Failure".
	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
	// +optional
	Status string `json:"status,omitempty"`

	// A human-readable description of the status of this operation.
	// +optional
	Message string `json:"message,omitempty"`

	// A machine-readable description of why this operation is in the
	// "Failure" status. If this value is empty there
	// is no information available. A Reason clarifies an HTTP status
	// code but does not override it.
	// +optional
	Reason string `json:"reason,omitempty"`

	// Extended data associated with the reason.  Each reason may define its
	// own extended details. This field is optional and the data returned
	// is not guaranteed to conform to any schema except that defined by
	// the reason type.
	// +optional
	Details *struct {
		Name string `json:"name,omitempty"`
		Kind string `json:"kind,omitempty"`
	} `json:"details,omitempty"`

	// Suggested HTTP return code for this status, 0 if not set.
	// +optional
	Code int `json:"code,omitempty"`
}

Status is a return value for calls that don't return other objects.

func (*Status) Error

func (s *Status) Error() string

type TypeMeta

type TypeMeta struct {
	// Kind is a string value representing the REST resource this object represents.
	// Servers may infer this from the endpoint the client submits requests to.
	// Cannot be updated.
	// In CamelCase.
	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
	// +optional
	Kind string `json:"kind,omitempty"`

	// APIVersion defines the versioned schema of this representation of an object.
	// Servers should convert recognized schemas to the latest internal value, and
	// may reject unrecognized values.
	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
	// +optional
	APIVersion string `json:"apiVersion,omitempty"`
}

TypeMeta describes an individual object in an API response or request with strings representing the type of the object and its API schema version. Structures that are versioned or persisted should inline TypeMeta.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL