kubeclient

package
v0.0.0-...-c438d58 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KubeClient

type KubeClient struct {
	Clientset *kubernetes.Clientset
}

func NewKubeClient

func NewKubeClient(kubeconfig *string, clientset *kubernetes.Clientset) (*KubeClient, error)

InitKubeClient initializes a Kubernetes clientset with the given kubeconfig

func (*KubeClient) AddSvcToEndpoint

func (kc *KubeClient) AddSvcToEndpoint(ctx context.Context, epClient v1.EndpointsInterface, ep *apiv1.Endpoints, svcInfo *reg.ServiceInfo) (*reg.RegistrationResult, error)

AddSvcToEndpoint is a function that adds the service given in svcInfo in the corresponding endpoints object of that service. This function makes the following assumptions: * the namespace given in nsName already exists * a headless service as provided in svcInfo.ServiceName has already been created * an existing non-nil endpoints object ep is being passed in

We have to consider the following cases:

  1. The endpoints object already exists and a. the Ipaddress:Ports already exists: we do nothing since the svcInfo has already been registered b. the Ipaddress:ports already exists in the notReadyAddresses array: move the EndpointAddress to the addresses array
  2. The endpoints object already exists and the service endpoint does not exist yet. There are two subcases to be considered: a. the given svcInfo.Ports already exists: we then have to add the new svcInfo to the addresses array b. the given svcInfo.Ports does not exist: we have to create a new endpointsSubset object with the Ipaddress:Ports

TODO: in a future refactoring, we might want to explore if we can benefit from this library: https://github.com/banzaicloud/k8s-objectmatcher

func (*KubeClient) CreateNewEndpoint

func (kc *KubeClient) CreateNewEndpoint(ctx context.Context, svcInfo *reg.ServiceInfo) (*reg.RegistrationResult, error)

CreateNewEndpoint is a function that creates a new endpoints object and adds the service given in svcInfo to it. This function makes the following assumptions: * the namespace given in nsName already exists * a headless service as provided in svcInfo.ServiceName has already been created

func (*KubeClient) GetOrCreateNamespace

func (kc *KubeClient) GetOrCreateNamespace(ctx context.Context, nsName string, errorIfNotExist bool) (*apiv1.Namespace, error)

GetOrCreateNamespace will try to get the namespace object named 'nsName', or if it doesn't exist, will create it.

func (*KubeClient) GetOrCreateService

func (kc *KubeClient) GetOrCreateService(ctx context.Context, ns string, svcName string, ports []*reg.NamedPort, errorIfNotExist bool) (*apiv1.Service, error)

GetOrCreateService will try to get a service with the name 'svcName' in the namespace 'ns'. If it doesn't exist, it will create the object.

func (*KubeClient) RegisterEndpoint

func (kc *KubeClient) RegisterEndpoint(ctx context.Context, svcInfo *reg.ServiceInfo) (*reg.RegistrationResult, error)

RegisterEndpoint is a function that will ensure that the service given in svcInfo will be registered in the corresponding endpoints object of that service. This function makes the following assumptions: * the namespace given in nsName already exists * a headless service as provided in svcInfo.ServiceName has already been created

We have to consider the following cases:

  1. This is the first service endpoint to be registered: the endpoints object does not exist so we create the endpoints object with the svcInfo added
  2. The endpoints object already exists and a. the Ipaddress:Ports already exists: we do nothing since the svcInfo has already been registered b. the Ipaddress:ports already exists in the notReadyAddresses array: move the EndpointAddress to the addresses array
  3. The endpoints object already exists and the service endpoint does not exist yet. There are two subcases to be considered: a. the given svcInfo.Ports already exists: we then have to add the new svcInfo to the addresses array b. the given svcInfo.Ports does not exist: we have to create a new endpointsSubset object with the Ipaddress:Ports

TODO: in a future refactoring, we might want to explore if we can benefit from this library: https://github.com/banzaicloud/k8s-objectmatcher

func (*KubeClient) UnregisterEndpoint

func (kc *KubeClient) UnregisterEndpoint(ctx context.Context, svcInfo *reg.ServiceInfo) (*reg.RegistrationResult, error)

UnregisterEndpoint is a function that will ensure that the service given in svcInfo will be unregistered from the corresponding endpoints object of that service. This function makes the following assumptions: * the namespace given in nsName already exists * a headless service as provided in svcInfo.ServiceName exists

TODO: in a future refactoring, we might want to explore if we can benefit from this library: https://github.com/banzaicloud/k8s-objectmatcher

func (*KubeClient) UnregisterWithEndpoint

func (kc *KubeClient) UnregisterWithEndpoint(ctx context.Context, epClient v1.EndpointsInterface, ep *apiv1.Endpoints, svcInfo *reg.ServiceInfo) (*reg.RegistrationResult, error)

UnregisterWithEndpoint is a function that will remove the service given in svcInfo from the passed in endpoints object ep of that service. This function makes the following assumptions: * the namespace given in nsName already exists * a headless service as provided in svcInfo.ServiceName exists * an existing non-nil endpoints object ep is being passed in

TODO: in a future refactoring, we might want to explore if we can benefit from this library: https://github.com/banzaicloud/k8s-objectmatcher

Jump to

Keyboard shortcuts

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