k8s

package
v1.1.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Overview

Package k8s is a generated GoMock package.

Package k8s implements the Kubernetes Controller interface to monitor and retrieve information regarding Kubernetes resources such as Namespaces, Services, Pods, Endpoints, and ServiceAccounts.

Index

Constants

View Source
const (
	// DefaultKubeEventResyncInterval is the default resync interval for k8s events
	// This is set to 0 because we do not need resyncs from k8s client, and have our
	// own Ticker to turn on periodic resyncs.
	DefaultKubeEventResyncInterval = 0 * time.Second
)

Variables

This section is empty.

Functions

func DialerToPod

func DialerToPod(conf *rest.Config, clientSet kubernetes.Interface, podName string, namespace string) (httpstream.Dialer, error)

DialerToPod constructs a new httpstream.Dialer to connect to a pod for use with a PortForwarder

func GetEventHandlerFuncs

func GetEventHandlerFuncs(shouldObserve observeFilter, eventTypes EventTypes, msgBroker *messaging.Broker) cache.ResourceEventHandlerFuncs

GetEventHandlerFuncs returns the ResourceEventHandlerFuncs object used to receive events when a k8s object is added/updated/deleted.

func GetFSMControllerPods

func GetFSMControllerPods(clientSet kubernetes.Interface, ns string) *corev1.PodList

GetFSMControllerPods returns a list of fsm-controller pods in the namespace

func GetFSMInjectorPods

func GetFSMInjectorPods(clientSet kubernetes.Interface, ns string) *corev1.PodList

GetFSMInjectorPods returns a list of fsm-injector pods in the namespace

func GetHostnamesForService

func GetHostnamesForService(svc service.MeshService, localNamespace bool) []string

GetHostnamesForService returns the hostnames over which the service is accessible

func GetKubernetesServerVersionNumber

func GetKubernetesServerVersionNumber(kubeClient kubernetes.Interface) ([]int, error)

GetKubernetesServerVersionNumber returns the Kubernetes server version number in chunks, ex. v1.19.3 => [1, 19, 3]

func GetServiceFromHostname

func GetServiceFromHostname(c Controller, host string) string

GetServiceFromHostname returns the service name from its hostname This assumes the default k8s trustDomain: cluster.local

func GetSubdomainFromHostname

func GetSubdomainFromHostname(c Controller, host string) string

GetSubdomainFromHostname returns the service subdomain from its hostname This assumes the default k8s trustDomain: cluster.local

func GetTargetPortFromEndpoints

func GetTargetPortFromEndpoints(endpointName string, endpoints corev1.Endpoints) (endpointPort uint16)

GetTargetPortFromEndpoints returns the endpoint port corresponding to the given endpoint name and endpoints

func IsHeadlessService

func IsHeadlessService(svc corev1.Service) bool

IsHeadlessService determines whether or not a corev1.Service is a headless service

func IsMetricsEnabled

func IsMetricsEnabled(pod *corev1.Pod) bool

IsMetricsEnabled returns true if the pod in the mesh is correctly annotated for prometheus scrapping

func NamespacedNameFrom

func NamespacedNameFrom(name string) (types.NamespacedName, error)

NamespacedNameFrom returns the namespaced name for the given name if possible, otherwise an error

func ServiceToMeshServices

func ServiceToMeshServices(c Controller, svc corev1.Service) []service.MeshService

ServiceToMeshServices translates a k8s service with one or more ports to one or more MeshService objects per port.

func SetTrustDomain

func SetTrustDomain(domain string)

SetTrustDomain sets the trust domain

func WatchAndUpdateLogLevel

func WatchAndUpdateLogLevel(msgBroker *messaging.Broker, stop <-chan struct{})

WatchAndUpdateLogLevel watches for log level changes and updates the global log level

func WatchAndUpdateProxyBootstrapSecret

func WatchAndUpdateProxyBootstrapSecret(kubeClient kubernetes.Interface, msgBroker *messaging.Broker, stop <-chan struct{})

WatchAndUpdateProxyBootstrapSecret watches for new pods being added to the mesh and updates their corresponding proxy bootstrap config Secret's OwnerReferences to point to the associated pod.

Types

type Controller

type Controller interface {

	// ListServices returns a list of all (monitored-namespace filtered) services in the mesh
	ListServices() []*corev1.Service

	// ListServiceAccounts returns a list of all (monitored-namespace filtered) service accounts in the mesh
	ListServiceAccounts() []*corev1.ServiceAccount

	// GetService returns a corev1 Service representation if the MeshService exists in cache, otherwise nil
	GetService(service.MeshService) *corev1.Service

	// IsMonitoredNamespace returns whether a namespace with the given name is being monitored
	// by the mesh
	IsMonitoredNamespace(string) bool

	// ListMonitoredNamespaces returns the namespaces monitored by the mesh
	ListMonitoredNamespaces() ([]string, error)

	// GetNamespace returns k8s namespace present in cache
	GetNamespace(string) *corev1.Namespace

	// ListPods returns a list of pods part of the mesh
	ListPods() []*corev1.Pod

	// ListServiceIdentitiesForService lists ServiceAccounts associated with the given service
	ListServiceIdentitiesForService(service.MeshService) ([]identity.K8sServiceAccount, error)

	// GetEndpoints returns the endpoints for a given service, if found
	GetEndpoints(service.MeshService) (*corev1.Endpoints, error)

	// UpdateStatus updates the status subresource for the given resource and GroupVersionKind
	// The object within the 'interface{}' must be a pointer to the underlying resource
	UpdateStatus(interface{}) (metav1.Object, error)

	// GetPodForProxy returns the pod for the given proxy
	GetPodForProxy(models.Proxy) (*v1.Pod, error)

	GetTargetPortForServicePort(types.NamespacedName, uint16) (uint16, error)
}

Controller is the controller interface for K8s services

func NewKubernetesController

func NewKubernetesController(informerCollection *fsminformers.InformerCollection, policyClient policyv1alpha1Client.Interface, pluginClient pluginv1alpha1Client.Interface, msgBroker *messaging.Broker, selectInformers ...InformerKey) Controller

NewKubernetesController returns a new kubernetes.Controller which means to provide access to locally-cached k8s resources

type EventType

type EventType string

EventType is the type of event we have received from Kubernetes

const (
	// AddEvent is a type of a Kubernetes API event.
	AddEvent EventType = "ADD"

	// UpdateEvent is a type of a Kubernetes API event.
	UpdateEvent EventType = "UPDATE"

	// DeleteEvent is a type of a Kubernetes API event.
	DeleteEvent EventType = "DELETE"
)

func (EventType) String

func (et EventType) String() string

type EventTypes

type EventTypes struct {
	Add    announcements.Kind
	Update announcements.Kind
	Delete announcements.Kind
}

EventTypes is a struct helping pass the correct types to GetEventHandlerFuncs()

type InformerKey

type InformerKey string

InformerKey stores the different Informers we keep for K8s resources

const (
	// Namespaces lookup identifier
	Namespaces InformerKey = "Namespaces"
	// Services lookup identifier
	Services InformerKey = "Services"
	// Pods lookup identifier
	Pods InformerKey = "Pods"
	// Endpoints lookup identifier
	Endpoints InformerKey = "Endpoints"
	// ServiceAccounts lookup identifier
	ServiceAccounts InformerKey = "ServiceAccounts"
	// EndpointSlices lookup identifier
	EndpointSlices InformerKey = "EndpointSlices"
)

type MockController

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

MockController is a mock of Controller interface.

func NewMockController

func NewMockController(ctrl *gomock.Controller) *MockController

NewMockController creates a new mock instance.

func (*MockController) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockController) GetEndpoints

func (m *MockController) GetEndpoints(arg0 service.MeshService) (*v1.Endpoints, error)

GetEndpoints mocks base method.

func (*MockController) GetNamespace

func (m *MockController) GetNamespace(arg0 string) *v1.Namespace

GetNamespace mocks base method.

func (*MockController) GetPodForProxy

func (m *MockController) GetPodForProxy(arg0 models.Proxy) (*v1.Pod, error)

GetPodForProxy mocks base method.

func (*MockController) GetService

func (m *MockController) GetService(arg0 service.MeshService) *v1.Service

GetService mocks base method.

func (*MockController) GetTargetPortForServicePort

func (m *MockController) GetTargetPortForServicePort(arg0 types.NamespacedName, arg1 uint16) (uint16, error)

GetTargetPortForServicePort mocks base method.

func (*MockController) IsMonitoredNamespace

func (m *MockController) IsMonitoredNamespace(arg0 string) bool

IsMonitoredNamespace mocks base method.

func (*MockController) ListMonitoredNamespaces

func (m *MockController) ListMonitoredNamespaces() ([]string, error)

ListMonitoredNamespaces mocks base method.

func (*MockController) ListPods

func (m *MockController) ListPods() []*v1.Pod

ListPods mocks base method.

func (*MockController) ListServiceAccounts

func (m *MockController) ListServiceAccounts() []*v1.ServiceAccount

ListServiceAccounts mocks base method.

func (*MockController) ListServiceIdentitiesForService

func (m *MockController) ListServiceIdentitiesForService(arg0 service.MeshService) ([]identity.K8sServiceAccount, error)

ListServiceIdentitiesForService mocks base method.

func (*MockController) ListServices

func (m *MockController) ListServices() []*v1.Service

ListServices mocks base method.

func (*MockController) UpdateStatus

func (m *MockController) UpdateStatus(arg0 interface{}) (v10.Object, error)

UpdateStatus mocks base method.

type MockControllerMockRecorder

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

MockControllerMockRecorder is the mock recorder for MockController.

func (*MockControllerMockRecorder) GetEndpoints

func (mr *MockControllerMockRecorder) GetEndpoints(arg0 interface{}) *gomock.Call

GetEndpoints indicates an expected call of GetEndpoints.

func (*MockControllerMockRecorder) GetNamespace

func (mr *MockControllerMockRecorder) GetNamespace(arg0 interface{}) *gomock.Call

GetNamespace indicates an expected call of GetNamespace.

func (*MockControllerMockRecorder) GetPodForProxy

func (mr *MockControllerMockRecorder) GetPodForProxy(arg0 interface{}) *gomock.Call

GetPodForProxy indicates an expected call of GetPodForProxy.

func (*MockControllerMockRecorder) GetService

func (mr *MockControllerMockRecorder) GetService(arg0 interface{}) *gomock.Call

GetService indicates an expected call of GetService.

func (*MockControllerMockRecorder) GetTargetPortForServicePort

func (mr *MockControllerMockRecorder) GetTargetPortForServicePort(arg0, arg1 interface{}) *gomock.Call

GetTargetPortForServicePort indicates an expected call of GetTargetPortForServicePort.

func (*MockControllerMockRecorder) IsMonitoredNamespace

func (mr *MockControllerMockRecorder) IsMonitoredNamespace(arg0 interface{}) *gomock.Call

IsMonitoredNamespace indicates an expected call of IsMonitoredNamespace.

func (*MockControllerMockRecorder) ListMonitoredNamespaces

func (mr *MockControllerMockRecorder) ListMonitoredNamespaces() *gomock.Call

ListMonitoredNamespaces indicates an expected call of ListMonitoredNamespaces.

func (*MockControllerMockRecorder) ListPods

func (mr *MockControllerMockRecorder) ListPods() *gomock.Call

ListPods indicates an expected call of ListPods.

func (*MockControllerMockRecorder) ListServiceAccounts

func (mr *MockControllerMockRecorder) ListServiceAccounts() *gomock.Call

ListServiceAccounts indicates an expected call of ListServiceAccounts.

func (*MockControllerMockRecorder) ListServiceIdentitiesForService

func (mr *MockControllerMockRecorder) ListServiceIdentitiesForService(arg0 interface{}) *gomock.Call

ListServiceIdentitiesForService indicates an expected call of ListServiceIdentitiesForService.

func (*MockControllerMockRecorder) ListServices

func (mr *MockControllerMockRecorder) ListServices() *gomock.Call

ListServices indicates an expected call of ListServices.

func (*MockControllerMockRecorder) UpdateStatus

func (mr *MockControllerMockRecorder) UpdateStatus(arg0 interface{}) *gomock.Call

UpdateStatus indicates an expected call of UpdateStatus.

type PortForwarder

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

PortForwarder is a type that implements port forwarding to a pod

func NewPortForwarder

func NewPortForwarder(dialer httpstream.Dialer, portSpec string) (*PortForwarder, error)

NewPortForwarder creates a new port forwarder to a pod

func (*PortForwarder) Done

func (pf *PortForwarder) Done() <-chan struct{}

Done returns a channel that is closed after Stop has been called.

func (*PortForwarder) Start

func (pf *PortForwarder) Start(readyFunc func(pf *PortForwarder) error) error

Start starts the port forwarding and calls the readyFunc callback function when port forwarding is ready

func (*PortForwarder) Stop

func (pf *PortForwarder) Stop()

Stop stops the port forwarding if not stopped already

Directories

Path Synopsis
Package events implements the eventing framework to receive and relay kubernetes events, and a framework to publish events to the Kubernetes API server.
Package events implements the eventing framework to receive and relay kubernetes events, and a framework to publish events to the Kubernetes API server.
Package fake implements Fake's methods.
Package fake implements Fake's methods.
Package informers centralize informers by creating a single object that runs a set of informers, instead of creating different objects that each manage their own informer collections.
Package informers centralize informers by creating a single object that runs a set of informers, instead of creating different objects that each manage their own informer collections.

Jump to

Keyboard shortcuts

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