k8sapi

package
v2.22.0-test.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	KnownKinds         = Kinds{ServiceKind, PodKind, DeploymentKind, StatefulSetKind, ReplicaSetKind, RolloutKind} //nolint:gochecknoglobals // constant
	KnownWorkloadKinds = Kinds{DeploymentKind, ReplicaSetKind, StatefulSetKind, RolloutKind}                       //nolint:gochecknoglobals // constant
)

Functions

func CanI

func CanI(ctx context.Context, ras ...*auth.ResourceAttributes) (bool, error)

func CanWatch

func CanWatch(ctx context.Context, group, resource, name, ns string) bool

func CanWatchNamespaces

func CanWatchNamespaces(ctx context.Context) bool

CanWatchNamespaces answers the question if this client has the RBAC permissions necessary to watch namespaces. The answer is likely false when using a namespaces scoped installation.

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 GetArgoRolloutsInterface

func GetArgoRolloutsInterface(ctx context.Context) argoRollouts.Interface

func GetK8sInterface

func GetK8sInterface(ctx context.Context) kubernetes.Interface

func GetNamespaceID

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 RolloutImpl

func RolloutImpl(o Object) (*argoRollouts.Rollout, bool)

RolloutImpl casts the given Object as an *argoRollout.Rollout 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 WithArgoRolloutsInterface

func WithArgoRolloutsInterface(ctx context.Context, ari argoRollouts.Interface) context.Context

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 ClientConfigProvider

type ClientConfigProvider interface {
	ClientConfig() (clientcmd.ClientConfig, error)
}

type JoinedClientSetInterface

type JoinedClientSetInterface interface {
	kubernetes.Interface
	argoRollouts.Interface
}

func GetJoinedClientSetInterface

func GetJoinedClientSetInterface(ctx context.Context) JoinedClientSetInterface

type Kind

type Kind string
const (
	ServiceKind     Kind = "Service"
	PodKind         Kind = "Pod"
	DeploymentKind  Kind = "Deployment"
	StatefulSetKind Kind = "StatefulSet"
	ReplicaSetKind  Kind = "ReplicaSet"
	RolloutKind     Kind = "Rollout"
)

func (Kind) IsValid

func (w Kind) IsValid() bool

type Kinds

type Kinds []Kind

func (Kinds) Contains

func (k Kinds) Contains(kind Kind) bool

type Object

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

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 UnsupportedWorkloadKindError added in v2.6.2

type UnsupportedWorkloadKindError Kind

func (UnsupportedWorkloadKindError) Error added in v2.6.2

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 GetRollout

func GetRollout(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 string, kind Kind) (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
  4. Rollouts (Argo Rollouts)

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 Rollout

func Rollout(r *argoRollouts.Rollout) Workload

func Rollouts

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

Rollouts returns all rollouts 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