client

package
v2.5.0-rc.8 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2022 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ConnectorSocketName is the path used when communicating to the connector process
	ConnectorSocketName = "/tmp/telepresence-connector.socket"

	// DaemonSocketName is the path used when communicating to the daemon process
	DaemonSocketName = "/var/run/telepresence-daemon.socket"
)
View Source
const (
	// APIVersion is the API version of the daemon and connector API
	APIVersion = 3
)

Variables

This section is empty.

Functions

func CheckTimeout added in v2.1.2

func CheckTimeout(ctx context.Context, err error) error

func DialSocket

func DialSocket(ctx context.Context, socketName string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

DialSocket dials the given socket and returns the resulting connection

func DisplayVersion

func DisplayVersion() string

DisplayVersion returns a printable version for `telepresence`

func Executable added in v2.5.0

func Executable() (string, error)

func GetConfigFile added in v2.3.5

func GetConfigFile(c context.Context) string

GetConfigFile gets the path to the configFile as stored in filelocation.AppUserConfigDir

func GetExe

func GetExe() string

GetExe returns the name of the running executable

func GetInstallMechanism added in v2.4.8

func GetInstallMechanism() (string, error)

GetInstallMechanism returns how the executable was installed on the machine.

func GetMechanismFromPath added in v2.4.8

func GetMechanismFromPath(execPath string) (string, error)

GetMechanismFromPath is a helper function that contains most of the logic required for GetInstallMechanism, but enables us to test it since we can control the path passed in.

func ListenSocket added in v2.4.0

func ListenSocket(ctx context.Context, processName, socketName string) (net.Listener, error)

ListenSocket returns a listener for the given socket and returns the resulting connection

func RemoveSocket added in v2.4.0

func RemoveSocket(listener net.Listener) error

RemoveSocket removes any representation of the the socket from the filesystem.

func ReplaceConfig added in v2.5.0

func ReplaceConfig(ctx context.Context, config *Config)

ReplaceConfig replaces the config last stored using WithConfig with the given Config

func Retry

func Retry(c context.Context, text string, f func(context.Context) error, durations ...time.Duration) error

Retry will run the given function repeatedly with an increasing delay until it returns without error.

The function takes 0 to 2 durations with the following meaning

Delay - initial delay, i.e. the delay between the first and the second call.
MaxDelay - maximum delay between calling the functions (delay will never grow beyond this value)

func RunError

func RunError(err error) error

RunError checks if the given err is a *exit.ExitError, and if so, extracts Stderr and the ExitCode from it.

func Semver

func Semver() semver.Version

func SetConfig added in v2.4.0

func SetConfig(ctx context.Context, configDir, configYml string) (context.Context, error)

SetConfig creates a config from the configYml provided and assigns it to a new context which is returned. Use this if you are testing components of the config.yml, otherwise you can use setDefaultConfig.

func SetDefaultConfig added in v2.4.0

func SetDefaultConfig(ctx context.Context, configDir string) (context.Context, error)

SetDefaultConfig creates a config that has the registry set correctly. This ensures that the config on the machine of whatever is running the test, isn't used, which could cause conflict with the tests.

func SetExe

func SetExe(executable string)

SetExe defines the name of the executable (for testing purposes only)

func SocketExists

func SocketExists(name string) (bool, error)

SocketExists returns true if a socket is found with the given name

func Version

func Version() string

Version returns the version of this executable.

func WaitUntilSocketAppears

func WaitUntilSocketAppears(name, path string, ttw time.Duration) error

WaitUntilSocketAppears waits until the socket at the given path comes into existence and returns when that happens. The wait will be max ttw (time to wait) long. An error is returned if that time is exceeded before the socket is removed.

func WaitUntilSocketVanishes

func WaitUntilSocketVanishes(name, path string, ttw time.Duration) error

WaitUntilSocketVanishes waits until the socket at the given path is removed and returns when that happens. The wait will be max ttw (time to wait) long. An error is returned if that time is exceeded before the socket is removed.

func Watch added in v2.5.0

func Watch(c context.Context, onReload func(context.Context) error) error

Watch uses a file system watcher that receives events when the configuration changes and calls the given function when that happens.

func WithConfig added in v2.4.2

func WithConfig(ctx context.Context, config *Config) context.Context

WithConfig returns a context with the given Config

func WithEnsuredState

func WithEnsuredState(ctx context.Context, r EnsuredState, retain bool, f func() error) (err error)

WithEnsuredState ensures the given state, calls the function, and then, if the state was activated, it is deactivated unless the retain flag is true.

func WithEnv added in v2.4.2

func WithEnv(ctx context.Context, env *Env) context.Context

WithEnv returns a context with the given Env

func WrapRecvErr added in v2.3.3

func WrapRecvErr(err error, msg string) error

WrapRecvErr wraps an error from a Recv call. If the error is nil, nil is returned. If the error indicates that the remote end has , a RecvEOF wrapping the error will be returned. Otherwise, the original error will be wrapped as fmt.Errorf("%s: %w", msg, err)

Types

type Cloud added in v2.3.5

type Cloud struct {
	SkipLogin       bool          `json:"skipLogin,omitempty" yaml:"skipLogin,omitempty"`
	RefreshMessages time.Duration `json:"refreshMessages,omitempty" yaml:"refreshMessages,omitempty"`
	SystemaHost     string        `json:"systemaHost,omitempty" yaml:"systemaHost,omitempty"`
	SystemaPort     string        `json:"systemaPort,omitempty" yaml:"systemaPort,omitempty"`
}

func (Cloud) IsZero added in v2.5.0

func (c Cloud) IsZero() bool

IsZero controls whether this element will be included in marshalled output

func (Cloud) MarshalYAML added in v2.4.4

func (c Cloud) MarshalYAML() (interface{}, error)

MarshalYAML is not using pointer receiver here, because Cloud is not pointer in the Config struct

func (*Cloud) UnmarshalYAML added in v2.3.5

func (c *Cloud) UnmarshalYAML(node *yaml.Node) (err error)

UnmarshalYAML parses the images YAML

type Config added in v2.1.2

type Config struct {
	Timeouts        Timeouts        `json:"timeouts,omitempty" yaml:"timeouts,omitempty"`
	LogLevels       LogLevels       `json:"logLevels,omitempty" yaml:"logLevels,omitempty"`
	Images          Images          `json:"images,omitempty" yaml:"images,omitempty"`
	Cloud           Cloud           `json:"cloud,omitempty" yaml:"cloud,omitempty"`
	Grpc            Grpc            `json:"grpc,omitempty" yaml:"grpc,omitempty"`
	TelepresenceAPI TelepresenceAPI `json:"telepresenceAPI,omitempty" yaml:"telepresenceAPI,omitempty"`
	Daemons         Daemons         `json:"daemons,omitempty" yaml:"daemons,omitempty"`
	Intercept       Intercept       `json:"intercept,omitempty" yaml:"intercept,omitempty"`
}

Config contains all configuration values for the telepresence CLI

func GetConfig added in v2.1.2

func GetConfig(ctx context.Context) *Config

func GetDefaultConfig added in v2.4.2

func GetDefaultConfig() Config

GetDefaultConfig returns the default configuration settings

func LoadConfig added in v2.4.2

func LoadConfig(c context.Context) (cfg *Config, err error)

LoadConfig loads and returns the Telepresence configuration as stored in filelocation.AppUserConfigDir or filelocation.AppSystemConfigDirs

func (*Config) Merge added in v2.4.4

func (c *Config) Merge(o *Config)

Merge merges this instance with the non-zero values of the given argument. The argument values take priority.

func (*Config) UnmarshalYAML added in v2.1.2

func (c *Config) UnmarshalYAML(node *yaml.Node) error

type Daemons added in v2.5.0

type Daemons struct {
	UserDaemonBinary string `json:"userDaemonBinary,omitempty" yaml:"userDaemonBinary,omitempty"`
}

type EnsuredState

type EnsuredState interface {
	// EnsureState will check if the state is active and activate it if that is not the case.
	// The boolean return value indicates if the state was activated or not.
	EnsureState(ctx context.Context) (bool, error)

	// Deactivate the state (i.e. quit, remove, disconnect)
	DeactivateState(ctx context.Context) error
}

An EnsuredState represents some state that is needed in order for a function to execute.

type Env

type Env struct {
	// I'd like to set TELEPRESENCE_LOGIN_DOMAIN,default=auth.datawire.io, but
	// sethvargo/go-envconfig doesn't support filling in the default for our later references to
	// it in following settings, so we have to do the hack with maybeSetDefault below.  *sigh* I
	// guess I'm just spoiled by apro/cmd/amb-sidecar/types/internal/envconfig.
	LoginDomain        string `env:"TELEPRESENCE_LOGIN_DOMAIN,required"`
	LoginAuthURL       string `env:"TELEPRESENCE_LOGIN_AUTH_URL,default=https://${TELEPRESENCE_LOGIN_DOMAIN}/auth"`
	LoginTokenURL      string `env:"TELEPRESENCE_LOGIN_TOKEN_URL,default=https://${TELEPRESENCE_LOGIN_DOMAIN}/token"`
	LoginCompletionURL string `env:"TELEPRESENCE_LOGIN_COMPLETION_URL,default=https://${TELEPRESENCE_LOGIN_DOMAIN}/completion"`
	UserInfoURL        string `env:"TELEPRESENCE_USER_INFO_URL,default=https://${TELEPRESENCE_LOGIN_DOMAIN}/api/userinfo"`

	ManagerNamespace string `env:"TELEPRESENCE_MANAGER_NAMESPACE,default=ambassador"`

	// This environment variable becomes the default for the images.registry and images.webhookRegistry
	Registry string `env:"TELEPRESENCE_REGISTRY,default=docker.io/datawire"`

	// This environment variable becomes the default for the images.agentImage and images.webhookAgentImage
	AgentImage string `env:"TELEPRESENCE_AGENT_IMAGE,default="`
	// contains filtered or unexported fields
}

func GetEnv added in v2.4.2

func GetEnv(ctx context.Context) *Env

func LoadEnv

func LoadEnv(ctx context.Context) (*Env, error)

func LoadEnvWith added in v2.4.7

func LoadEnvWith(ctx context.Context, lookuper envconfig.Lookuper) (*Env, error)

func (Env) Get

func (env Env) Get(key string) string

type Grpc added in v2.3.5

type Grpc struct {
	// MaxReceiveSize is the maximum message size in bytes the client can receive in a gRPC call or stream message.
	// Overrides the gRPC default of 4MB.
	MaxReceiveSize resource.Quantity `json:"maxReceiveSize,omitempty" yaml:"maxReceiveSize,omitempty"`
}

func (Grpc) MarshalYAML added in v2.4.4

func (g Grpc) MarshalYAML() (interface{}, error)

MarshalYAML is not using pointer receiver here, because Cloud is not pointer in the Config struct

func (*Grpc) UnmarshalYAML added in v2.3.5

func (g *Grpc) UnmarshalYAML(node *yaml.Node) (err error)

UnmarshalYAML parses the images YAML

type Images added in v2.3.5

type Images struct {
	PrivateRegistry          string `json:"registry,omitempty" yaml:"registry,omitempty"`
	PrivateAgentImage        string `json:"agentImage,omitempty" yaml:"agentImage,omitempty"`
	PrivateWebhookRegistry   string `json:"webhookRegistry,omitempty" yaml:"webhookRegistry,omitempty"`
	PrivateWebhookAgentImage string `json:"webhookAgentImage,omitempty" yaml:"webhookAgentImage,omitempty"`
}

func (*Images) AgentImage added in v2.3.5

func (img *Images) AgentImage(c context.Context) string

func (*Images) Registry added in v2.3.5

func (img *Images) Registry(c context.Context) string

func (*Images) UnmarshalYAML added in v2.3.5

func (img *Images) UnmarshalYAML(node *yaml.Node) (err error)

UnmarshalYAML parses the images YAML

func (*Images) WebhookAgentImage added in v2.3.5

func (img *Images) WebhookAgentImage(c context.Context) string

func (*Images) WebhookRegistry added in v2.3.5

func (img *Images) WebhookRegistry(c context.Context) string

type Intercept added in v2.4.10

type Intercept struct {
	AppProtocolStrategy k8sapi.AppProtocolStrategy `json:"appProtocolStrategy,omitempty" yaml:"appProtocolStrategy,omitempty"`
	DefaultPort         int                        `json:"defaultPort,omitempty" yaml:"defaultPort,omitempty"`
}

func (Intercept) IsZero added in v2.5.0

func (ic Intercept) IsZero() bool

IsZero controls whether this element will be included in marshalled output

func (Intercept) MarshalYAML added in v2.4.10

func (ic Intercept) MarshalYAML() (interface{}, error)

MarshalYAML is not using pointer receiver here, because Intercept is not pointer in the Config struct

type LogLevels added in v2.3.0

type LogLevels struct {
	UserDaemon logrus.Level `json:"userDaemon,omitempty" yaml:"userDaemon,omitempty"`
	RootDaemon logrus.Level `json:"rootDaemon,omitempty" yaml:"rootDaemon,omitempty"`
}

func (LogLevels) IsZero added in v2.5.0

func (ll LogLevels) IsZero() bool

IsZero controls whether this element will be included in marshalled output

func (*LogLevels) UnmarshalYAML added in v2.3.0

func (ll *LogLevels) UnmarshalYAML(node *yaml.Node) (err error)

UnmarshalYAML parses the logrus log-levels

type RecvEOF added in v2.3.3

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

RecvEOF should be returned when a component has returned EOF from a stream. Do not use this if, for example, the initial dial to a stream fails.

func (*RecvEOF) Error added in v2.3.3

func (e *RecvEOF) Error() string

func (*RecvEOF) Unwrap added in v2.3.3

func (e *RecvEOF) Unwrap() error

type TelepresenceAPI added in v2.4.8

type TelepresenceAPI struct {
	Port int `json:"port,omitempty" yaml:"port,omitempty"`
}

type TimeoutID added in v2.3.0

type TimeoutID int
const (
	TimeoutAgentInstall TimeoutID = iota
	TimeoutApply
	TimeoutClusterConnect
	TimeoutEndpointDial
	TimeoutHelm
	TimeoutIntercept
	TimeoutProxyDial
	TimeoutRoundtripLatency
	TimeoutTrafficManagerAPI
	TimeoutTrafficManagerConnect
)

type Timeouts added in v2.1.2

type Timeouts struct {

	// PrivateAgentInstall is how long to wait for an agent to be installed (i.e. apply of service and deploy manifests)
	PrivateAgentInstall time.Duration `json:"agentInstall,omitempty" yaml:"agentInstall,omitempty"`
	// PrivateApply is how long to wait for a k8s manifest to be applied
	PrivateApply time.Duration `json:"apply,omitempty" yaml:"apply,omitempty"`
	// PrivateClusterConnect is the maximum time to wait for a connection to the cluster to be established
	PrivateClusterConnect time.Duration `json:"clusterConnect,omitempty" yaml:"clusterConnect,omitempty"`
	// PrivateEndpointDial is how long to wait for a Dial to a service for which the IP is known.
	PrivateEndpointDial time.Duration `json:"endpointDial,omitempty" yaml:"endpointDial,omitempty"`
	// PrivateHelm is how long to wait for any helm operation.
	PrivateHelm time.Duration `json:"helm,omitempty" yaml:"helm,omitempty"`
	// PrivateIntercept is the time to wait for an intercept after the agents has been installed
	PrivateIntercept time.Duration `json:"intercept,omitempty" yaml:"intercept,omitempty"`
	// PrivateRoundtripLatency is how much to add  to the EndpointDial timeout when establishing a remote connection.
	PrivateRoundtripLatency time.Duration `json:"roundtripLatency,omitempty" yaml:"roundtripLatency,omitempty"`
	// PrivateProxyDial is how long to wait for the proxy to establish an outbound connection
	PrivateProxyDial time.Duration `json:"proxyDial,omitempty" yaml:"proxyDial,omitempty"`
	// PrivateTrafficManagerConnect is how long to wait for the traffic-manager API to connect
	PrivateTrafficManagerAPI time.Duration `json:"trafficManagerAPI,omitempty" yaml:"trafficManagerAPI,omitempty"`
	// PrivateTrafficManagerConnect is how long to wait for the initial port-forwards to the traffic-manager
	PrivateTrafficManagerConnect time.Duration `json:"trafficManagerConnect,omitempty" yaml:"trafficManagerConnect,omitempty"`
}

func (*Timeouts) Get added in v2.4.2

func (t *Timeouts) Get(timeoutID TimeoutID) time.Duration

func (Timeouts) IsZero added in v2.5.0

func (t Timeouts) IsZero() bool

IsZero controls whether this element will be included in marshalled output

func (Timeouts) MarshalYAML added in v2.4.4

func (t Timeouts) MarshalYAML() (interface{}, error)

MarshalYAML is not using pointer receiver here, because Timeouts is not pointer in the Config struct

func (*Timeouts) TimeoutContext added in v2.3.0

func (t *Timeouts) TimeoutContext(ctx context.Context, timeoutID TimeoutID) (context.Context, context.CancelFunc)

func (*Timeouts) UnmarshalYAML added in v2.1.2

func (t *Timeouts) UnmarshalYAML(node *yaml.Node) (err error)

UnmarshalYAML caters for the unfortunate fact that time.Duration doesn't do YAML or JSON at all.

Jump to

Keyboard shortcuts

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