k8sapi

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: Apache-2.0 Imports: 25 Imported by: 18

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeploymentImpl

func DeploymentImpl(o Object) (*apps.Deployment, bool)

DeploymentImpl casts the given Object as an *apps.Deployment and returns it together with a status flag indicating whether the cast was possible.

func GetAppProto

func GetAppProto(ctx context.Context, aps AppProtocolStrategy, p *core.ServicePort) string

GetAppProto determines the application protocol of the given ServicePort. The given AppProtocolStrategy used if the port's appProtocol attribute is unset.

func GetClusterID

func GetClusterID(ctx context.Context) (clusterID string, err error)

GetClusterID returns the cluster ID for the given cluster. If there is an error, it still returns a usable ID along with the error.

func GetK8sInterface

func GetK8sInterface(ctx context.Context) kubernetes.Interface

func GetNamespaceID added in v0.1.4

func GetNamespaceID(ctx context.Context, namespace string) (clusterID string, err error)

GetNamespaceID returns the uuid for a given namespace. If there is an error, it still returns a usable ID along with the error.

func GetPort

func GetPort(cn *core.Container, portName string) (*core.ContainerPort, error)

GetPort finds a port with the given name and returns it.

func ObjErrorf

func ObjErrorf(o Object, format string, args ...any) error

func PodImpl

func PodImpl(o Object) (*core.Pod, bool)

PodImpl casts the given Object as an *core.Pod and returns it together with a status flag indicating whether the cast was possible.

func ReplicaSetImpl

func ReplicaSetImpl(o Object) (*apps.ReplicaSet, bool)

ReplicaSetImpl casts the given Object as an *apps.ReplicaSet and returns it together with a status flag indicating whether the cast was possible.

func ServiceImpl

func ServiceImpl(o Object) (*core.Service, bool)

ServiceImpl casts the given Object as an *core.Service and returns it together with a status flag indicating whether the cast was possible.

func StatefulSetImpl

func StatefulSetImpl(o Object) (*apps.StatefulSet, bool)

StatefulSetImpl casts the given Object as an *apps.StatefulSet and returns it together with a status flag indicating whether the cast was possible.

func Subscribe

func Subscribe(c context.Context, cond *sync.Cond) <-chan struct{}

Subscribe writes to the given channel whenever relevant information has changed in the current snapshot

func WithK8sInterface

func WithK8sInterface(ctx context.Context, ki kubernetes.Interface) context.Context

Types

type AppProtocolStrategy

type AppProtocolStrategy int

AppProtocolStrategy specifies how the application protocol for a service port is determined in case the service.spec.ports.appProtocol is not set.

const (
	// Http2Probe means never guess. Choose HTTP/1.1 or HTTP/2 by probing (this is the default behavior).
	Http2Probe AppProtocolStrategy = iota

	// PortName means trust educated guess based on port name when appProtocol is missing and perform a http2 probe
	// if no such guess can be made.
	PortName

	// Http means just assume HTTP/1.1.
	Http

	// Http2 means just assume HTTP/2.
	Http2
)

func NewAppProtocolStrategy

func NewAppProtocolStrategy(s string) (AppProtocolStrategy, error)

func (*AppProtocolStrategy) EnvDecode

func (aps *AppProtocolStrategy) EnvDecode(val string) (err error)

func (AppProtocolStrategy) MarshalYAML

func (aps AppProtocolStrategy) MarshalYAML() (any, error)

func (AppProtocolStrategy) String

func (aps AppProtocolStrategy) String() string

func (*AppProtocolStrategy) UnmarshalYAML

func (aps *AppProtocolStrategy) UnmarshalYAML(node *yaml.Node) (err error)

type Object

type Object interface {
	runtime.Object
	meta.Object
	GetAnnotations() map[string]string
	GetKind() string
	Delete(context.Context) error
	Refresh(context.Context) error
	Selector() (labels.Selector, error)
	Update(context.Context) error
	Patch(context.Context, types.PatchType, []byte, ...string) error
}

func GetPod

func GetPod(c context.Context, name, namespace string) (Object, error)

func GetService

func GetService(c context.Context, name, namespace string) (Object, error)

func Pod

func Pod(d *core.Pod) Object

func Pods

func Pods(c context.Context, namespace string, labelSelector labels.Set) ([]Object, error)

Pods returns all pods found in the given Namespace.

func Service

func Service(d *core.Service) Object

func Services

func Services(c context.Context, namespace string, labelSelector labels.Set) ([]Object, error)

Services returns all services found in the given Namespace.

type StateListener

type StateListener struct {
	Cb func()
}

type UnsupportedWorkloadKindError

type UnsupportedWorkloadKindError string

func (UnsupportedWorkloadKindError) Error

type Watcher

type Watcher[T runtime.Object] struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Watcher watches some resource and can be cancelled.

func NewWatcher

func NewWatcher[T runtime.Object](resource string, getter cache.Getter, cond *sync.Cond, opts ...WatcherOpt[T]) *Watcher[T]

NewWatcher returns a new watcher. It will not do anything until it is started.

resource string: the kind of resouce you want to watch, like "pods"
getter cache.Getter: a kubernetes rest.Interface client, like clientset.CoreV1().RESTClient()
objType T: an object of the resource type, like &corev1.Pod{}
cond *sync.Cond: cond will broadcast when the cache changes. Use k8sapi.Subscribe to subscribe to events

func (*Watcher[T]) Active

func (w *Watcher[T]) Active() bool

Active returns true if the watcher has been started and not yet cancelled.

func (*Watcher[T]) AddStateListener

func (w *Watcher[T]) AddStateListener(l *StateListener)

AddStateListener adds a listener function that will be called when the watcher changes its state (starts or is cancelled).

func (*Watcher[T]) Cancel

func (w *Watcher[T]) Cancel()

func (*Watcher[T]) EnsureStarted

func (w *Watcher[T]) EnsureStarted(c context.Context, cb func(bool)) error

func (*Watcher[T]) Get

func (w *Watcher[T]) Get(c context.Context, obj T) (T, bool, error)

obj T: an object that would generate the same key as the object you want. For our keyfunc, you need to populate name and, if the object is scoped to a namespace, namespace.

func (*Watcher[T]) HasSynced

func (w *Watcher[T]) HasSynced() bool

HasSynced returns true if this Watcher's controller has synced, or if this watcher hasn't started yet.

func (*Watcher[T]) List

func (w *Watcher[T]) List(c context.Context) ([]T, error)

func (*Watcher[T]) RemoveStateListener

func (w *Watcher[T]) RemoveStateListener(rl *StateListener)

RemoveStateListener removes a listener function.

func (*Watcher[T]) Subscribe added in v0.1.1

func (w *Watcher[T]) Subscribe(ctx context.Context) <-chan struct{}

func (*Watcher[T]) Watch

func (w *Watcher[T]) Watch(c context.Context, ready *sync.WaitGroup) error

type WatcherGroup added in v0.0.9

type WatcherGroup[T runtime.Object] map[string]*Watcher[T]

func NewWatcherGroup added in v0.0.9

func NewWatcherGroup[T runtime.Object]() WatcherGroup[T]

func (WatcherGroup[T]) AddWatcher added in v0.0.9

func (w WatcherGroup[T]) AddWatcher(watcher *Watcher[T]) error

func (WatcherGroup[T]) Cancel added in v0.0.9

func (w WatcherGroup[T]) Cancel()

func (WatcherGroup[T]) EnsureStarted added in v0.0.9

func (w WatcherGroup[T]) EnsureStarted(ctx context.Context, cb func(bool))

func (WatcherGroup[T]) Get added in v0.0.9

func (w WatcherGroup[T]) Get(ctx context.Context, namespace string, obj T) (T, bool, error)

func (WatcherGroup[T]) List added in v0.0.9

func (w WatcherGroup[T]) List(ctx context.Context) ([]T, error)

type WatcherOpt added in v0.1.4

type WatcherOpt[T runtime.Object] func(watcher *Watcher[T])

func WithEquals added in v0.1.0

func WithEquals[T runtime.Object](equals func(T, T) bool) WatcherOpt[T]

equals func checks if a new obj is equal to a cached obj. If true is returned, an update is not triggered. If this func is nil, an update is always triggered.

func WithFieldSelector added in v0.1.0

func WithFieldSelector[T runtime.Object](fieldSelector string) WatcherOpt[T]

func WithLabelSelector added in v0.1.0

func WithLabelSelector[T runtime.Object](labelSelector string) WatcherOpt[T]

func WithNamespace added in v0.1.0

func WithNamespace[T runtime.Object](namespace string) WatcherOpt[T]

namespace to be watched. An empty string watches all namespaces.

type Workload

type Workload interface {
	Object
	GetPodTemplate() *core.PodTemplateSpec
	Replicas() int
	Updated(int64) bool
}

func Deployment

func Deployment(d *apps.Deployment) Workload

func Deployments

func Deployments(c context.Context, namespace string, labelSelector labels.Set) ([]Workload, error)

Deployments returns all deployments found in the given Namespace.

func GetDeployment

func GetDeployment(c context.Context, name, namespace string) (Workload, error)

func GetReplicaSet

func GetReplicaSet(c context.Context, name, namespace string) (Workload, error)

func GetStatefulSet

func GetStatefulSet(c context.Context, name, namespace string) (Workload, error)

func GetWorkload

func GetWorkload(c context.Context, name, namespace, workloadKind string) (obj Workload, err error)

GetWorkload returns a workload for the given name, namespace, and workloadKind. The workloadKind is optional. A search is performed in the following order if it is empty:

  1. Deployments
  2. ReplicaSets
  3. StatefulSets

The first match is returned.

func ReplicaSet

func ReplicaSet(d *apps.ReplicaSet) Workload

func ReplicaSets

func ReplicaSets(c context.Context, namespace string, labelSelector labels.Set) ([]Workload, error)

ReplicaSets returns all replica sets found in the given Namespace.

func StatefulSet

func StatefulSet(d *apps.StatefulSet) Workload

func StatefulSets

func StatefulSets(c context.Context, namespace string, labelSelector labels.Set) ([]Workload, error)

StatefulSets returns all stateful sets found in the given Namespace.

func WrapWorkload

func WrapWorkload(workload runtime.Object) (Workload, error)

Jump to

Keyboard shortcuts

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