common

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2022 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Overview

Package common contains common definition and utils used across liqoctl

Index

Constants

View Source
const (
	// Cluster1Name name used in output messages for cluster passed as first argument.
	Cluster1Name = "cluster1"
	// Cluster1Color color used in output messages for cluster passed as first argument.
	Cluster1Color = pterm.FgLightBlue
	// Cluster2Name name used in output messages for cluster passed as second argument.
	Cluster2Name = "cluster2"
	// Cluster2Color color used in output messages for cluster passed as second argument.
	Cluster2Color = pterm.FgLightMagenta
)
View Source
const (
	// UnpeeringEvent name of the unpeering event.
	UnpeeringEvent fcEventType = "unpeer"
	// AuthEvent name of the authentication event.
	AuthEvent fcEventType = "authentication"
)
View Source
const LiqoctlLongHelp = `` /* 612-byte string literal not displayed */

LiqoctlLongHelp contains the long help message for root Liqoctl command.

View Source
const LiqoctlShortHelp = "liqoctl - the Liqo Command Line Interface"

LiqoctlShortHelp contains the short help message for root Liqoctl command.

Variables

View Source
var (
	// UnpeerChecker checks if the two clusters are unpeered.
	UnpeerChecker fcEventChecker = func(fc *discoveryv1alpha1.ForeignCluster) bool {
		return foreigncluster.IsIncomingPeeringNone(fc) && foreigncluster.IsOutgoingPeeringNone(fc)
	}

	// AuthChecker checks if the authentication has been completed.
	AuthChecker fcEventChecker = foreigncluster.IsAuthenticated
)
View Source
var (

	// GenericPrinter used to print generic output.
	GenericPrinter = pterm.PrefixPrinter{
		Prefix: pterm.Prefix{},
		Scope: pterm.Scope{
			Text:  "cmd",
			Style: pterm.NewStyle(pterm.FgGray),
		},
		MessageStyle: pterm.NewStyle(pterm.FgDefault),
	}

	// SuccessPrinter used to print success output.
	SuccessPrinter = GenericPrinter.WithPrefix(pterm.Prefix{
		Text:  "[SUCCESS]",
		Style: pterm.NewStyle(pterm.FgGreen),
	})

	// WarningPrinter used to print warning output.
	WarningPrinter = GenericPrinter.WithPrefix(pterm.Prefix{
		Text:  "[WARNING]",
		Style: pterm.NewStyle(pterm.FgYellow),
	})

	// ErrorPrinter used to print error output.
	ErrorPrinter = GenericPrinter.WithPrefix(pterm.Prefix{
		Text:  "[ERROR]",
		Style: pterm.NewStyle(pterm.FgRed),
	})
)
View Source
var (
	// Scheme used for the controller runtime clients.
	Scheme *runtime.Scheme
)

Functions

func ExtractValueFromArgumentList

func ExtractValueFromArgumentList(key string, argumentList []string) (string, error)

ExtractValueFromArgumentList extracts the argument value from an argument list.

func GetLiqoctlRestConf added in v0.3.1

func GetLiqoctlRestConf() (*rest.Config, error)

GetLiqoctlRestConf gets a valid REST config and set a default value for the RateLimiters.

func WaitForEventOnForeignCluster added in v0.4.0

func WaitForEventOnForeignCluster(ctx context.Context, remoteClusterID *discoveryv1alpha1.ClusterIdentity,
	event fcEventType, checker fcEventChecker, timeout time.Duration, cl client.Client) error

WaitForEventOnForeignCluster given the remote cluster identity if waits for the given event to be verified on the associated foreigncluster.

Types

type Cluster added in v0.4.0

type Cluster struct {
	PortForwardOpts *PortForwardOptions
	// contains filtered or unexported fields
}

Cluster struct that models a k8s cluster for connect and disconnect commands.

func NewCluster added in v0.4.0

func NewCluster(localK8sClient k8s.Interface, localCtrlRunClient, remoteCtrlRunClient client.Client,
	restConfig *rest.Config, namespace, name string, printerColor pterm.Color) *Cluster

NewCluster returns a new cluster object. The cluster has to be initialized before being consumed.

func (*Cluster) DeleteForeignCluster added in v0.4.0

func (c *Cluster) DeleteForeignCluster(ctx context.Context, remoteClusterID *discoveryv1alpha1.ClusterIdentity) error

DeleteForeignCluster deletes the foreignclusters instance for the given remote cluster.

func (*Cluster) DisablePeering added in v0.4.0

func (c *Cluster) DisablePeering(ctx context.Context, remoteClusterID *discoveryv1alpha1.ClusterIdentity) error

DisablePeering disables the peering for the remote cluster by patching the foreigncusters resource.

func (*Cluster) EnforceForeignCluster added in v0.4.0

func (c *Cluster) EnforceForeignCluster(ctx context.Context, remoteClusterID *discoveryv1alpha1.ClusterIdentity,
	token, authURL, proxyURL string) error

EnforceForeignCluster enforces the presence of the foreignclusters instance for a given remote cluster. The newly created foreigncluster has the following fields set to:

  • ForeignAuthURL -> the remapped ip address for the local cluster of the auth service living in the remote cluster;
  • ForeignProxyURL -> the remapped ip address for the local cluster of the proxy service living in the remote cluster;
  • OutgoingPeeringEnabled -> Yes
  • NetworkingEnabled -> No, we do not want the networking to be handled by the peering process. Networking is handled manually by the licoctl connect/disconnect commands.

func (*Cluster) ExchangeNetworkCfg added in v0.4.0

func (c *Cluster) ExchangeNetworkCfg(ctx context.Context, remoteClusterID *discoveryv1alpha1.ClusterIdentity) error

ExchangeNetworkCfg creates the local networkconfigs resource for the remote cluster, replicates it into the remote cluster, waits for the remote cluster to populate the status of the resource and then sets the remote status in the local networkconfigs resource.

func (*Cluster) GetAuthToken added in v0.4.0

func (c *Cluster) GetAuthToken() string

GetAuthToken returns the authentication token of the local cluster.

func (*Cluster) GetAuthURL added in v0.4.0

func (c *Cluster) GetAuthURL() string

GetAuthURL returns the authentication URL of the local cluster.

func (*Cluster) GetClusterID added in v0.4.0

func (c *Cluster) GetClusterID() *discoveryv1alpha1.ClusterIdentity

GetClusterID returns the cluster identity.

func (*Cluster) GetLocTenantNS added in v0.4.0

func (c *Cluster) GetLocTenantNS() string

GetLocTenantNS returns the tenant namespace created for the remote cluster.

func (*Cluster) GetProxyURL added in v0.4.0

func (c *Cluster) GetProxyURL() string

GetProxyURL returns the proxy URL of the local cluster.

func (*Cluster) Init added in v0.4.0

func (c *Cluster) Init(ctx context.Context) error

Init initializes the cluster struct.

func (*Cluster) MapAuthIPForCluster added in v0.4.0

func (c *Cluster) MapAuthIPForCluster(ctx context.Context, ipamClient ipam.IpamClient, remoteCluster *discoveryv1alpha1.ClusterIdentity) error

MapAuthIPForCluster maps the ClusterIP address of the local auth service on the local external CIDR as seen by the remote cluster.

func (*Cluster) MapProxyIPForCluster added in v0.4.0

func (c *Cluster) MapProxyIPForCluster(ctx context.Context, ipamClient ipam.IpamClient, remoteCluster *discoveryv1alpha1.ClusterIdentity) error

MapProxyIPForCluster maps the ClusterIP address of the local proxy on the local external CIDR as seen by the remote cluster.

func (*Cluster) NewIPAMClient added in v0.4.0

func (c *Cluster) NewIPAMClient(ctx context.Context) (ipam.IpamClient, error)

NewIPAMClient creates and returns a client to the IPAM service.

func (*Cluster) PortForwardIPAM added in v0.4.0

func (c *Cluster) PortForwardIPAM(ctx context.Context) error

PortForwardIPAM starts the port forwarding for the IPAM service.

func (*Cluster) SetRemTenantNS added in v0.4.0

func (c *Cluster) SetRemTenantNS(remTenantNamespace string)

SetRemTenantNS sets the tenant namespace of the local cluster created by the remote cluster.

func (*Cluster) SetUpTenantNamespace added in v0.4.0

func (c *Cluster) SetUpTenantNamespace(ctx context.Context, remoteClusterID *discoveryv1alpha1.ClusterIdentity) error

SetUpTenantNamespace creates the tenant namespace in the local custer for the given remote cluster.

func (*Cluster) StopPortForwardIPAM added in v0.4.0

func (c *Cluster) StopPortForwardIPAM()

StopPortForwardIPAM stops the port forwarding for the IPAM service.

func (*Cluster) TearDownTenantNamespace added in v0.4.0

func (c *Cluster) TearDownTenantNamespace(ctx context.Context, remoteClusterID *discoveryv1alpha1.ClusterIdentity, timeout time.Duration) error

TearDownTenantNamespace deletes the tenant namespace in the local cluster for the given remote cluster.

func (*Cluster) UnmapAuthIPForCluster added in v0.4.0

func (c *Cluster) UnmapAuthIPForCluster(ctx context.Context, ipamClient ipam.IpamClient, remoteCluster *discoveryv1alpha1.ClusterIdentity) error

UnmapAuthIPForCluster unmaps the ClusterIP address of the local auth service on the local external CIDR as seen by the remote cluster.

func (*Cluster) UnmapProxyIPForCluster added in v0.4.0

func (c *Cluster) UnmapProxyIPForCluster(ctx context.Context, ipamClient ipam.IpamClient, remoteCluster *discoveryv1alpha1.ClusterIdentity) error

UnmapProxyIPForCluster unmaps the ClusterIP address of the local proxy on the local external CIDR as seen by the remote cluster.

func (*Cluster) WaitForAuth added in v0.4.0

func (c *Cluster) WaitForAuth(ctx context.Context, remoteClusterID *discoveryv1alpha1.ClusterIdentity, timeout time.Duration) error

WaitForAuth waits until the authentication has been established with the remote cluster or the timeout expires.

func (*Cluster) WaitForUnpeering added in v0.4.0

func (c *Cluster) WaitForUnpeering(ctx context.Context, remoteClusterID *discoveryv1alpha1.ClusterIdentity, timeout time.Duration) error

WaitForUnpeering waits until the status on the foreiglcusters resource states that the in/outgoing peering has been successfully set to None or the timeout expires.

type DefaultPortForwarder added in v0.4.0

type DefaultPortForwarder struct {
	genericclioptions.IOStreams
}

DefaultPortForwarder default forwarder implementation used to forward ports.

func (*DefaultPortForwarder) ForwardPorts added in v0.4.0

func (f *DefaultPortForwarder) ForwardPorts(method string, podURL *url.URL, opt *PortForwardOptions) error

ForwardPorts forwards the ports given in the options for the given pod url.

type Endpoint added in v0.4.0

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

Endpoint maps a service that has to be accessed by a remote cluster.

func (*Endpoint) GetHTTPSURL added in v0.4.0

func (ep *Endpoint) GetHTTPSURL() string

GetHTTPSURL return the https url for the endpoint.

func (*Endpoint) GetHTTPURL added in v0.4.0

func (ep *Endpoint) GetHTTPURL() string

GetHTTPURL returns the http url for the endpoint.

func (*Endpoint) GetIP added in v0.4.0

func (ep *Endpoint) GetIP() string

GetIP returns the ip address that has on the cluster where the endpoint lives.

func (*Endpoint) SetRemappedIP added in v0.4.0

func (ep *Endpoint) SetRemappedIP(ip string)

SetRemappedIP sets the ip address as seen by the remote cluster.

type PortForwardOptions added in v0.4.0

type PortForwardOptions struct {
	Namespace     string
	Selector      *metav1.LabelSelector
	Config        *restclient.Config
	Client        client.Client
	PortForwarder PortForwarder
	RemotePort    int
	LocalPort     int
	Ports         []string
	StopChannel   chan struct{}
	ReadyChannel  chan struct{}
}

PortForwardOptions contains all the options in order to port-forward a pod's port.

func (*PortForwardOptions) RunPortForward added in v0.4.0

func (o *PortForwardOptions) RunPortForward(ctx context.Context) error

RunPortForward starts the forwarding.

func (*PortForwardOptions) StopPortForward added in v0.4.0

func (o *PortForwardOptions) StopPortForward()

StopPortForward stops the forwarding.

type PortForwarder added in v0.4.0

type PortForwarder interface {
	ForwardPorts(method string, podURL *url.URL, opts *PortForwardOptions) error
}

PortForwarder interface that a port forwarder needs to implement.

type Printer added in v0.4.0

type Printer struct {
	Info        *pterm.PrefixPrinter
	Success     *pterm.PrefixPrinter
	Warning     *pterm.PrefixPrinter
	Error       *pterm.PrefixPrinter
	Spinner     *pterm.SpinnerPrinter
	InfoMessage string
}

Printer manages all kinds of outputs.

func NewPrinter added in v0.4.0

func NewPrinter(name string, printerColor pterm.Color) *Printer

NewPrinter creates a new printer.

type WireGuardConfig added in v0.4.0

type WireGuardConfig struct {
	PubKey       string
	EndpointIP   string
	EndpointPort string
	BackEndType  string
}

WireGuardConfig holds the WireGuard configuration.

Jump to

Keyboard shortcuts

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