cluster

package
v0.0.0-...-9a6de97 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Package cluster provides tools to interact with the k8s cluster. These include:

- A k8s client to the remote api server. - The ksync daemonset definition and a way to launch it on the cluster. - Tunnels from the remote pod to the localhost. - Connections between each remote container and the localhost.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Client is used to communicate with the cluster's api server. Make sure to
	// run InitKubeClient() first.
	Client *kubernetes.Clientset
)
View Source
var (
	// ImageName is the docker image to use for running the cluster service.
	ImageName = "ksync/ksync"
)

Functions

func GetKubeConfig

func GetKubeConfig(context string) (*rest.Config, string, error)

GetKubeConfig fetches a config based off a given context.

func InitKubeClient

func InitKubeClient(context string) error

InitKubeClient creates a new k8s client for use in talking to the cluster's api server.

func SetErrorHandlers

func SetErrorHandlers()

SetErrorHandlers modifies the default runtime handlers to replace the default logger with our own.

func SetImage

func SetImage(name string)

SetImage sets the package-wide image to used for running the cluster service.

Types

type Connection

type Connection struct {
	NodeName string
	// contains filtered or unexported fields
}

Connection creates and manages the tunnels and gRPC connection between the local host a ksync pod running on the remote cluster

func NewConnection

func NewConnection(nodeName string) *Connection

NewConnection is the constructor for Connection. You specify the node you'd like to establish a connection to here.

func (*Connection) Fields

func (c *Connection) Fields() log.Fields

Fields returns a set of structured fields for logging.

func (*Connection) Radar

func (c *Connection) Radar() (*grpc.ClientConn, error)

Radar creates a new tunnel and gRPC connection to the radar container running in the ksync pod specified by Container.NodeName

func (*Connection) Stop

func (c *Connection) Stop() error

Stop cleans all the established tunnels up. It should be called when this connection is no longer needed.

func (*Connection) String

func (c *Connection) String() string

func (*Connection) Syncthing

func (c *Connection) Syncthing() (int32, int32, error)

Syncthing creates a tunnel for both the API and sync ports to the syncthing container running in the ksync pod specified by Container.NodeName

type Service

type Service struct {
	Namespace string

	RadarPort         int32
	SyncthingAPI      int32
	SyncthingListener int32
	// contains filtered or unexported fields
}

Service is the remote server component of ksync.

func NewService

func NewService() *Service

NewService constructs a Service to track the ksync daemonset on the cluster.

func (*Service) Fields

func (s *Service) Fields() log.Fields

Fields returns a set of structured fields for logging.

func (*Service) IsHealthy

func (s *Service) IsHealthy(nodeName string) (bool, error)

IsHealthy verifies the target node is running the service container and it is not scheduled for deletion.

func (*Service) IsInstalled

func (s *Service) IsInstalled() (bool, error)

IsInstalled makes sure the cluster service has been installed.

func (*Service) NodeNames

func (s *Service) NodeNames() ([]string, error)

NodeNames returns a list of all the nodes the ksync pod is running on.

func (*Service) PodName

func (s *Service) PodName(nodeName string) (string, error)

PodName takes the name of a node and returns the name of the ksync pod running on that node.

func (*Service) Remove

func (s *Service) Remove() error

Remove provides cleanup for the ksync daemonset on the cluster. Only run this when you want to clean everything up.

func (*Service) Run

func (s *Service) Run(upgrade, withPSP bool) error

Run starts (or upgrades) the ksync daemonset on the remote cluster.

func (*Service) String

func (s *Service) String() string

func (*Service) Version

func (s *Service) Version() (*pb.VersionInfo, error)

Version fetches the binary version from radar running in the remote cluster. It picks the first node that is healthy. If no nodes are healthy, an error is thrown.

type Tunnel

type Tunnel struct {
	LocalPort  int32
	RemotePort int32
	PodName    string
	Namespace  string

	Out *bytes.Buffer
	// contains filtered or unexported fields
}

Tunnel is the connection between the local host and a specific pod in the remote cluster.

func NewTunnel

func NewTunnel(
	namespace string,
	podName string,
	remotePort int32) *Tunnel

NewTunnel constructs a new tunnel for the namespace, pod and port.

func (*Tunnel) Close

func (t *Tunnel) Close()

Close closes an existing tunnel

func (*Tunnel) Fields

func (t *Tunnel) Fields() log.Fields

Fields returns a set of structured fields for logging.

func (*Tunnel) Start

func (t *Tunnel) Start() error

Start starts a given tunnel connection

func (*Tunnel) String

func (t *Tunnel) String() string

Jump to

Keyboard shortcuts

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