const NodeUnreachablePodReason = k8s_util_node.NodeUnreachablePodReason
const ResourceCPU = corev1.ResourceCPU
const ResourceMemory = corev1.ResourceMemory
const SecretTypeServiceAccountToken = corev1.SecretTypeServiceAccountToken
const SecretTypeTLS = corev1.SecretTypeTLS
var ( JSONPatchType = types.JSONPatchType MergePatchType = types.MergePatchType StrategicMergePatchType = types.StrategicMergePatchType ApplyPatchType = types.ApplyPatchType )
var ConditionTrue = xv1.ConditionTrue
var CoreConditionTrue = corev1.ConditionTrue
var Established = xv1.Established
var Int = intstr.Int
var IsConflict = apierrors.IsConflict
var IsNotFound = apierrors.IsNotFound
var MustParseQuantity = resource.MustParse
var NamesAccepted = xv1.NamesAccepted
var NamespaceAll = metav1.NamespaceAll
var NamespaceNone = metav1.NamespaceNone
var NewConfigFlags = genericclioptions.NewConfigFlags
var ParseSelector = labels.Parse
var PodFailed = corev1.PodFailed
var PodReady = corev1.PodReady
var PodSucceeded = corev1.PodSucceeded
var ProtocolSCTP = corev1.ProtocolSCTP
var ProtocolTCP = corev1.ProtocolTCP
var ProtocolUDP = corev1.ProtocolUDP
var ServiceTypeClusterIP = corev1.ServiceTypeClusterIP
var ServiceTypeLoadBalancer = corev1.ServiceTypeLoadBalancer
var TolerationOpEqual = corev1.TolerationOpEqual
var TolerationOpExists = corev1.TolerationOpExists
func ConvertObject(scheme *runtime.Scheme, src, dst runtime.Object) error
func HasOwnerReference(owner, other Object) bool
func InCluster() bool
The InCluster function returns true if the process is running inside a kubernetes cluster, and false if it is running outside the cluster. This is determined by heuristics, however it uses the exact same heuristics as client-go does. This is copied from (client-go/tools/clientcmd/client_config.go), as it is not publically invocable in its original place. This should be re-copied if the original code changes.
func MergeUpdate(target *Unstructured, source *Unstructured)
func NewClientFactory(flags *pflag.FlagSet) func() (*Client, error)
NewClientFactory adds flags to a flagset (i.e. before flagset.Parse()), and returns a function to be called after flagset.Parse() that uses the parsed flags to construct a *Client.
func NewRESTMapper(config *ConfigFlags) (meta.RESTMapper, discovery.CachedDiscoveryInterface, error)
func SetOwnerReferences(owner Object, objects ...Object)
type APIResource = metav1.APIResource
The Accumulator struct is used to efficiently maintain an in-memory copy of kubernetes resources present in a cluster in a form that is easy for business logic to process. It functions as a bridge between delta-based kubernetes watches on individual Kinds and the complete/consistent set of objects on which business logic needs to operate. In that sense it accumulates both multiple kinds of kubernetes resources into a single snapshot, as well as accumulating deltas on individual objects into relevant sets of objects.
The Goals/Requirements below are based heavily on the needs of Ambassador as they have evolved over the years. A lot of this comes down to the fact that unlike the exemplary deployment/replicaset controller examples which typically operate on a single resource and render it into another (deployment -> N replicasets, replicaset -> N pods), Ambassador's controller logic has some additional requirements:
Complete knowledge of resources in a cluster. Because many thousands of Mappings are ultimately assembled into a single envoy configuration responsible for ingress into the cluster, the consequences of producing an envoy configuration when you e.g. know about only half of those Mappings is catastrophic (you are black-holing half your traffic).
Complete knowledge of multiple resources. Instead of having one self contained input like a deployment or a replicaset, Ambassador's business logic has many inputs, and the consequence of producing an envoy without knowledge of *all* of those inputs is equally catastrophic, e.g. it's no use knowing about all the Mappings if you don't know about any of the Hosts yet.
Goals/Requirements:
Bootstrap of a single Kind: the Accumulator will ensure that all pre-existing resources of that Kind have been loaded into memory prior to triggering any notifications. This guarantees we will never trigger business logic on an egregiously incomplete view of the cluster (e.g. when 500 out of 1000 Mappings have been loaded) and makes it safe for the business logic to assume complete knowledge of the cluster.
When multiple Kinds are needed by a controller, the Accumulator will not notify the controller until all the Kinds have been fully bootstrapped.
Graceful load shedding: When the rate of change of resources is very fast, the API and implementation are structured so that individual object deltas get coalesced into a single snapshot update. This prevents excessively triggering business logic to process an entire snapshot for each individual object change that occurs.
type Accumulator struct {
// contains filtered or unexported fields
}
func (a *Accumulator) Changed() <-chan struct{}
func (a *Accumulator) FilteredUpdate(ctx context.Context, target interface{}, deltas *[]*Delta, predicate func(*Unstructured) bool) (bool, error)
The FilteredUpdate method updates the target snapshot with only those resources for which "predicate" returns true. The predicate is only called when objects are added/updated, it is not repeatedly called on objects that have not changed. The predicate must not modify its argument.
func (a *Accumulator) Listen(ctx context.Context, rawUpdateCh <-chan rawUpdate, interval time.Duration)
Listen for updates from rawUpdateCh and sends notifications, coalescing reads as neccessary. This loop along with the logic in storeField isused to satisfy the 3 Goals/Requirements listed in the documentation for the Accumulator struct, i.e. Ensuring all Kinds are bootstrapped before any notification occurs, as well as ensuring that we continue to coalesce updates in the background while business logic is executing in order to ensure graceful load shedding.
func (a *Accumulator) Update(ctx context.Context, target interface{}) (bool, error)
func (a *Accumulator) UpdateWithDeltas(ctx context.Context, target interface{}, deltas *[]*Delta) (bool, error)
The Client struct provides an interface to interact with the kubernetes api-server. You can think of it like a programatic version of the familiar kubectl command line tool. In fact a goal of these APIs is that where possible, your knowledge of kubectl should translate well into using these APIs. It provides a golang-friendly way to perform basic CRUD and Watch operations on kubernetes resources, as well as providing some additional capabilities.
Differences from kubectl:
The biggest difference from kubectl (and also from using client-go directly) is the Read/Write coherence it provides. Kubernetes Watches are inherently asynchronous. This means that if a kubernetes resource is modified at time T0, a client won't find out about it until some later time T1. It is normally difficult to notice this since the delay may be quite small, however if you are writing a controller that uses watches in combination with modifying the resources it is watching, the delay is big enough that a program will often be "notified" with versions of resources that do not included updates made by the program itself. This even happens when a program has a lock and is guaranteed to be the only process modifying a given resource. Needless to say, programming against an API like this can make for some brain twisting logic. The Client struct allows for much simpler code by tracking what changes have been made locally and updating all Watch results with the most recent version of an object, thereby providing the guarantee that your Watch results will *always* include any changes you have made via the Client performing the watch.
Additionally, the Accumulator API provides two key pieces of watch related functionality:
By coalescing multiple updates behind the scenes, the Accumulator API provides a natural form of load shedding if a user of the API cannot keep up with every single update.
The Accumulator API is guaranteed to bootstrap (i.e. perform an initial List operation) on all watches prior to notifying the user that resources are available to process.
type Client struct {
// contains filtered or unexported fields
}
func NewClient(options ClientConfig) (*Client, error)
The NewClient function constructs a new client with the supplied ClientConfig.
func NewClientFromConfigFlags(config *ConfigFlags) (*Client, error)
func (c *Client) Create(ctx context.Context, resource interface{}, target interface{}) error
func (c *Client) Delete(ctx context.Context, resource interface{}, target interface{}) error
func (c *Client) DynamicInterface() dynamic.Interface
DynamicInterface is an accessor method to the k8s dynamic client
func (c *Client) Get(ctx context.Context, resource interface{}, target interface{}) error
func (c *Client) InvalidateCache() error
func (c *Client) List(ctx context.Context, query Query, target interface{}) error
func (c *Client) MaxAccumulatorInterval(interval time.Duration) error
Sets the max interval to wait before sending changes for snapshot updates. The interval must be non-negative, otherwise it will return an error.
func (c *Client) Patch(ctx context.Context, resource interface{}, pt PatchType, data []byte, target interface{}) error
func (c *Client) PodLogs(ctx context.Context, pod *Pod, options *PodLogOptions, events chan<- LogEvent) error
The PodLogs method accesses the log output of a given pod by sending LogEvent structs down the supplied channel. The LogEvent struct is designed to hold enough information that it is feasible to invoke PodLogs multiple times with a single channel in order to multiplex log output from many pods, e.g.:
events := make(chan LogEvent) client.PodLogs(ctx, pod1, options, events) client.PodLogs(ctx, pod2, options, events) client.PodLogs(ctx, pod3, options, events) for event := range events { fmt.Printf("%s: %s: %s", event.PodId, event.Timestamp, event.Output) }
The above code will print log output from all 3 pods.
func (c *Client) ServerPreferredResources() ([]APIResource, error)
ServerPreferredResources returns the list of resource types that the server supports.
If a resource type supports multiple versions, then *only* the preferred version is returned. Use ServerResources to return a list that includes all versions.
func (c *Client) ServerResources() ([]APIResource, error)
ServerResources returns the list of resource types that the server supports.
If a resource type supports multiple versions, then a list entry for *each* version is returned. Use ServerPreferredResources to return a list that includes just the preferred version.
func (c *Client) ServerVersion() (*VersionInfo, error)
The ServerVersion() method returns a struct with information about the kubernetes api-server version.
func (c *Client) Update(ctx context.Context, resource interface{}, target interface{}) error
func (c *Client) UpdateStatus(ctx context.Context, resource interface{}, target interface{}) error
func (c *Client) Upsert(ctx context.Context, resource interface{}, source interface{}, target interface{}) error
func (c *Client) WaitFor(ctx context.Context, kindOrResource string) error
func (c *Client) Watch(ctx context.Context, queries ...Query) (*Accumulator, error)
The ClientConfig struct holds all the parameters and configuration that can be passed upon construct of a new Client.
type ClientConfig struct { Kubeconfig string Context string Namespace string }
type ClusterRole = rbacv1.ClusterRole
type ClusterRoleBinding = rbacv1.ClusterRoleBinding
type ConfigFlags = genericclioptions.ConfigFlags
type ConfigMap = corev1.ConfigMap
type Container = corev1.Container
type ContainerMetrics = metrics.ContainerMetrics
type CreateOptions = metav1.CreateOptions
type CustomResourceDefinition = xv1.CustomResourceDefinition
type DeleteOptions = metav1.DeleteOptions
type Delta struct { TypeMeta `json:""` ObjectMeta `json:"metadata,omitempty"` DeltaType DeltaType `json:"deltaType"` }
func NewDelta(deltaType DeltaType, obj *Unstructured) *Delta
func NewDeltaFromObject(deltaType DeltaType, obj Object) (*Delta, error)
type DeltaType int
const ( ObjectAdd DeltaType = iota ObjectUpdate ObjectDelete )
func (dt DeltaType) MarshalJSON() ([]byte, error)
func (dt *DeltaType) UnmarshalJSON(b []byte) error
type Deployment = appsv1.Deployment
type EndpointAddress = corev1.EndpointAddress
type EndpointPort = corev1.EndpointPort
type EndpointSubset = corev1.EndpointSubset
type Endpoints = corev1.Endpoints
type EnvVar = corev1.EnvVar
type Event = corev1.Event
type GetOptions = metav1.GetOptions
type IntOrString = intstr.IntOrString
type LabelSelector = metav1.LabelSelector
type LabelSet = labels.Set
type ListOptions = metav1.ListOptions
type LocalObjectReference = corev1.LocalObjectReference
The LogEvent struct is used to communicate log output from a pod. It includes PodID and Timestamp information so that LogEvents from different pods can be interleaved without losing information about total ordering and/or pod identity.
type LogEvent struct { // The PodID field indicates what pod the log output is associated with. PodID string `json:"podID"` // The Timestamp field indicates when the log output was created. Timestamp string `json:"timestamp"` // The Output field contains log output from the pod. Output string `json:"output,omitempty"` // The Closed field is true if the supply of log events from the given pod was terminated. This does not // necessarily mean there is no more log data. Closed bool // The Error field contains error information if the log events were terminated due to an error. Error error `json:"error,omitempty"` }
type Namespace = corev1.Namespace
type Node = corev1.Node
type NodeMetrics = metrics.NodeMetrics
type Object interface { // runtime.Object gives the following methods: // // GetObjectKind() k8s.io/apimachinery/pkg/runtime/schema.ObjectKind // DeepCopyObject() k8s.io/apimachinery/pkg/runtime.Object runtime.Object // metav1.Object gives the following methods: // // GetNamespace() string // SetNamespace(namespace string) // GetName() string // SetName(name string) // GetGenerateName() string // SetGenerateName(name string) // GetUID() k8s.io/apimachinery/pkg/types.UID // SetUID(uid k8s.io/apimachinery/pkg/types.UID) // GetResourceVersion() string // SetResourceVersion(version string) // GetGeneration() int64 // SetGeneration(generation int64) // GetSelfLink() string // SetSelfLink(selfLink string) // GetCreationTimestamp() metav1.Time // SetCreationTimestamp(timestamp metav1.Time) // GetDeletionTimestamp() *metav1.Time // SetDeletionTimestamp(timestamp *metav1.Time) // GetDeletionGracePeriodSeconds() *int64 // SetDeletionGracePeriodSeconds(*int64) // GetLabels() map[string]string // SetLabels(labels map[string]string) // GetAnnotations() map[string]string // SetAnnotations(annotations map[string]string) // GetFinalizers() []string // SetFinalizers(finalizers []string) // GetOwnerReferences() []metav1.OwnerReference // SetOwnerReferences([]metav1.OwnerReference) // GetClusterName() string // SetClusterName(clusterName string) // GetManagedFields() []metav1.ManagedFieldsEntry // SetManagedFields(managedFields []metav1.ManagedFieldsEntry) metav1.Object }
func NewObject(kind, version string) (Object, error)
func NewObjectFromUnstructured(unstructured *Unstructured) (Object, error)
NewObjectFromUnstructured will construct a new specialized object based on the runtime schema ambassador uses. This gaurantees any types defined by or used by ambassador will be constructed as the proper golang type.
func ParseManifests(text string) ([]Object, error)
func ParseManifestsToUnstructured(text string) ([]Object, error)
type ObjectMeta = metav1.ObjectMeta
type ObjectReference = corev1.ObjectReference
type PatchOptions = metav1.PatchOptions
type PatchType = types.PatchType
type PersistentVolumeClaim = corev1.PersistentVolumeClaim
type PersistentVolumeClaimVolumeSource = corev1.PersistentVolumeClaimVolumeSource
type Pod = corev1.Pod
type PodCondition = corev1.PodCondition
type PodLogOptions = corev1.PodLogOptions
type PodMetrics = metrics.PodMetrics
type PodSpec = corev1.PodSpec
type PodTemplateSpec = corev1.PodTemplateSpec
type Protocol = corev1.Protocol
type Quantity = resource.Quantity
A Query holds all the information needed to List or Watch a set of kubernetes resources.
type Query struct { // The Name field holds the name of the Query. This is used by // Watch to determine how multiple queries are unmarshaled by // Accumulator.Update(). This is ignored for List. Name string // The Kind field indicates what sort of resource is being queried. Kind string // The Namespace field holds the namespace to Query. Namespace string // The FieldSelector field holds a string in selector syntax // that is used to filter results based on field values. The // only field values supported are metadata.name and // metadata.namespace. This is only supported for List. FieldSelector string // The LabelSelector field holds a string in selector syntax // that is used to filter results based on label values. LabelSelector string }
type ReplicaSet = appsv1.ReplicaSet
type ResourceList = corev1.ResourceList
type ResourceRequirements = corev1.ResourceRequirements
type Role = rbacv1.Role
type RoleBinding = rbacv1.RoleBinding
type Secret = corev1.Secret
type SecurityContext = corev1.SecurityContext
type Selector = labels.Selector
type Service = corev1.Service
type ServiceAccount = corev1.ServiceAccount
type ServicePort = corev1.ServicePort
type ServiceSpec = corev1.ServiceSpec
type StatefulSet = appsv1.StatefulSet
type Time = metav1.Time
type Toleration = corev1.Toleration
type TolerationOperator = corev1.TolerationOperator
type TypeMeta = metav1.TypeMeta
type Unstructured = unstructured.Unstructured
func NewUnstructured(kind, version string) *Unstructured
func NewUnstructuredFromObject(obj Object) (result *Unstructured, err error)
Convert a potentially typed Object to an *Unstructured object.
type UpdateOptions = metav1.UpdateOptions
A Validator may be used in concert with a Client to perform validate of freeform jsonish data structures as kubernetes CRDs.
type Validator struct {
// contains filtered or unexported fields
}
func NewValidator(client *Client, staticCRDs []Object) (*Validator, error)
The NewValidator constructor returns a *Validator that uses the provided *Client to fetch CustomResourceDefinitions from kubernetes on demand as needed to validate data passed to the Validator.Validate() method.
func (v *Validator) Validate(ctx context.Context, resource interface{}) error
The Validate method validates the supplied jsonish object as a kubernetes CRD instance.
If the supplied object is *not* a CRD instance but instead a regular kubernetes instance, the Validate method will assume that the supplied object is valid.
If the supplied object is not a valid kubernetes resource at all, the Validate method will return an error.
Typically the Validate method will perform only local operations, however the first time an instance of a given Kind is supplied, the Validator needs to query the cluster to figure out if it is a CRD and if so to fetch the schema needed to perform validation. All subsequent Validate() calls for that Kind will be local.
type VersionInfo = version.Info
type Volume = corev1.Volume
type VolumeMount = corev1.VolumeMount
type VolumeSource = corev1.VolumeSource
Name | Synopsis |
---|---|
.. | |
k8s_resource_types |