client

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2022 License: MPL-2.0 Imports: 40 Imported by: 0

Documentation

Overview

Package client provides Talos API client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddrFromPeer

func AddrFromPeer(remote *peer.Peer) (peerHost string)

AddrFromPeer extracts peer address from grpc Peer.

func FilterMessages

func FilterMessages(resp interface{}, err error) (interface{}, error)

FilterMessages removes error Messages from resp and builds multierror.

func ReadStream

func ReadStream(stream MachineStream) (io.ReadCloser, <-chan error, error)

ReadStream converts grpc stream into io.Reader.

func RemotePeer

func RemotePeer(ctx context.Context) (peerHost string)

RemotePeer parses remote peer address from grpc stream context.

func StatusCode

func StatusCode(err error) codes.Code

StatusCode returns the Code of the error if it is a Status error, codes.OK if err is nil, or codes.Unknown otherwise correctly unwrapping wrapped errors.

StatusCode is mostly equivalent to grpc `status.Code` method, but it correctly unwraps wrapped errors including `multierror.Error` used when parsing multi-node responses.

func WithNodes

func WithNodes(ctx context.Context, nodes ...string) context.Context

WithNodes wraps the context with metadata to send request to set of nodes.

func WithPowerCycle added in v0.14.0

func WithPowerCycle(req *machineapi.RebootRequest)

WithPowerCycle option runs the Reboot fun in powercycle mode.

Types

type Client

type Client struct {
	MachineClient  machineapi.MachineServiceClient
	TimeClient     timeapi.TimeServiceClient
	ClusterClient  clusterapi.ClusterServiceClient
	StorageClient  storageapi.StorageServiceClient
	ResourceClient resourceapi.ResourceServiceClient
	InspectClient  inspectapi.InspectServiceClient

	Resources *ResourcesClient
	Inspect   *InspectClient
	// contains filtered or unexported fields
}

Client implements the proto.MachineServiceClient interface. It serves as the concrete type with the required methods.

func New

func New(ctx context.Context, opts ...OptionFunc) (c *Client, err error)

New returns a new Client.

func NewClient deprecated

func NewClient(cfg *tls.Config, endpoints []string, port int, opts ...grpc.DialOption) (c *Client, err error)

NewClient initializes a Client.

Deprecated: use client.NewFromConfigContext() instead.

func (*Client) ApplyConfiguration

func (c *Client) ApplyConfiguration(ctx context.Context, req *machineapi.ApplyConfigurationRequest, callOptions ...grpc.CallOption) (resp *machineapi.ApplyConfigurationResponse, err error)

ApplyConfiguration implements proto.MachineServiceClient interface.

func (*Client) Bootstrap

func (c *Client) Bootstrap(ctx context.Context, req *machineapi.BootstrapRequest) (err error)

Bootstrap implements the proto.MachineServiceClient interface.

func (*Client) Close

func (c *Client) Close() error

Close shuts down client protocol.

func (*Client) ClusterHealthCheck

func (c *Client) ClusterHealthCheck(ctx context.Context, waitTimeout time.Duration, clusterInfo *clusterapi.ClusterInfo) (clusterapi.ClusterService_HealthCheckClient, error)

ClusterHealthCheck runs a Talos cluster health check.

func (*Client) Containers

func (c *Client) Containers(ctx context.Context, namespace string, driver common.ContainerDriver, callOptions ...grpc.CallOption) (resp *machineapi.ContainersResponse, err error)

Containers implements the proto.MachineServiceClient interface.

func (*Client) Copy

func (c *Client) Copy(ctx context.Context, rootPath string) (io.ReadCloser, <-chan error, error)

Copy implements the proto.MachineServiceClient interface.

func (*Client) DiskUsage

DiskUsage implements the proto.MachineServiceClient interface.

func (*Client) Disks

func (c *Client) Disks(ctx context.Context, callOptions ...grpc.CallOption) (resp *storageapi.DisksResponse, err error)

Disks returns the list of block devices.

func (*Client) Dmesg

func (c *Client) Dmesg(ctx context.Context, follow, tail bool) (machineapi.MachineService_DmesgClient, error)

Dmesg implements the proto.MachineServiceClient interface.

func (*Client) EtcdForfeitLeadership

EtcdForfeitLeadership makes node forfeit leadership in the etcd cluster.

func (*Client) EtcdLeaveCluster

func (c *Client) EtcdLeaveCluster(ctx context.Context, req *machineapi.EtcdLeaveClusterRequest, callOptions ...grpc.CallOption) error

EtcdLeaveCluster makes node leave etcd cluster.

func (*Client) EtcdMemberList

EtcdMemberList lists etcd members of the cluster.

func (*Client) EtcdRecover

func (c *Client) EtcdRecover(ctx context.Context, snapshot io.Reader, callOptions ...grpc.CallOption) (*machineapi.EtcdRecoverResponse, error)

EtcdRecover uploads etcd snapshot created with EtcdSnapshot to the node.

func (*Client) EtcdRemoveMember

func (c *Client) EtcdRemoveMember(ctx context.Context, req *machineapi.EtcdRemoveMemberRequest, callOptions ...grpc.CallOption) error

EtcdRemoveMember removes a node from etcd cluster.

func (*Client) EtcdSnapshot

func (c *Client) EtcdSnapshot(ctx context.Context, req *machineapi.EtcdSnapshotRequest, callOptions ...grpc.CallOption) (io.ReadCloser, <-chan error, error)

EtcdSnapshot receives a snapshot of the etcd from the node.

func (*Client) Events

func (c *Client) Events(ctx context.Context, opts ...EventsOptionFunc) (stream machineapi.MachineService_EventsClient, err error)

Events implements the proto.OSClient interface.

func (*Client) EventsWatch

func (c *Client) EventsWatch(ctx context.Context, watchFunc func(<-chan Event), opts ...EventsOptionFunc) error

EventsWatch wraps Events by providing more simple interface.

func (*Client) GenerateClientConfiguration

func (c *Client) GenerateClientConfiguration(ctx context.Context, req *machineapi.GenerateClientConfigurationRequest, callOptions ...grpc.CallOption) (resp *machineapi.GenerateClientConfigurationResponse, err error)

GenerateClientConfiguration implements proto.MachineServiceClient interface.

func (*Client) GenerateConfiguration

func (c *Client) GenerateConfiguration(ctx context.Context, req *machineapi.GenerateConfigurationRequest, callOptions ...grpc.CallOption) (resp *machineapi.GenerateConfigurationResponse, err error)

GenerateConfiguration implements proto.MachineServiceClient interface.

func (*Client) GetConfigContext

func (c *Client) GetConfigContext() *clientconfig.Context

GetConfigContext returns resolved config context.

func (*Client) GetConn

func (c *Client) GetConn(ctx context.Context, opts ...grpc.DialOption) (*grpc.ClientConn, error)

GetConn creates new gRPC connection.

func (*Client) GetEndpoints

func (c *Client) GetEndpoints() []string

GetEndpoints returns the client's endpoints from the override set with WithEndpoints or from the configuration.

func (*Client) Kubeconfig

func (c *Client) Kubeconfig(ctx context.Context) ([]byte, error)

Kubeconfig returns K8s client config (kubeconfig).

func (*Client) KubeconfigRaw

func (c *Client) KubeconfigRaw(ctx context.Context) (io.ReadCloser, <-chan error, error)

KubeconfigRaw returns K8s client config (kubeconfig).

func (*Client) LS

LS implements the proto.MachineServiceClient interface.

func (*Client) Logs

func (c *Client) Logs(ctx context.Context, namespace string, driver common.ContainerDriver, id string, follow bool, tailLines int32) (stream machineapi.MachineService_LogsClient, err error)

Logs implements the proto.MachineServiceClient interface.

func (*Client) Memory

func (c *Client) Memory(ctx context.Context, callOptions ...grpc.CallOption) (resp *machineapi.MemoryResponse, err error)

Memory implements the proto.MachineServiceClient interface.

func (*Client) Mounts

func (c *Client) Mounts(ctx context.Context, callOptions ...grpc.CallOption) (resp *machineapi.MountsResponse, err error)

Mounts implements the proto.MachineServiceClient interface.

func (*Client) Processes

func (c *Client) Processes(ctx context.Context, callOptions ...grpc.CallOption) (resp *machineapi.ProcessesResponse, err error)

Processes implements the proto.MachineServiceClient interface.

func (*Client) Read

func (c *Client) Read(ctx context.Context, path string) (io.ReadCloser, <-chan error, error)

Read reads a file.

func (*Client) Reboot

func (c *Client) Reboot(ctx context.Context, opts ...RebootMode) (err error)

Reboot implements the proto.MachineServiceClient interface.

func (*Client) Reset

func (c *Client) Reset(ctx context.Context, graceful, reboot bool) (err error)

Reset implements the proto.MachineServiceClient interface.

func (*Client) ResetGeneric

func (c *Client) ResetGeneric(ctx context.Context, req *machineapi.ResetRequest) (err error)

ResetGeneric implements the proto.MachineServiceClient interface.

func (*Client) Restart

func (c *Client) Restart(ctx context.Context, namespace string, driver common.ContainerDriver, id string, callOptions ...grpc.CallOption) (err error)

Restart implements the proto.MachineServiceClient interface.

func (*Client) Rollback

func (c *Client) Rollback(ctx context.Context) (err error)

Rollback implements the proto.MachineServiceClient interface.

func (*Client) ServiceInfo

func (c *Client) ServiceInfo(ctx context.Context, id string, callOptions ...grpc.CallOption) (services []ServiceInfo, err error)

ServiceInfo returns info about a single service

This is implemented via service list API, as we don't have many services If service with given id is not registered, function returns nil.

func (*Client) ServiceList

func (c *Client) ServiceList(ctx context.Context, callOptions ...grpc.CallOption) (resp *machineapi.ServiceListResponse, err error)

ServiceList returns list of services with their state.

func (*Client) ServiceRestart

func (c *Client) ServiceRestart(ctx context.Context, id string, callOptions ...grpc.CallOption) (resp *machineapi.ServiceRestartResponse, err error)

ServiceRestart restarts a service.

func (*Client) ServiceStart

func (c *Client) ServiceStart(ctx context.Context, id string, callOptions ...grpc.CallOption) (resp *machineapi.ServiceStartResponse, err error)

ServiceStart starts a service.

func (*Client) ServiceStop

func (c *Client) ServiceStop(ctx context.Context, id string, callOptions ...grpc.CallOption) (resp *machineapi.ServiceStopResponse, err error)

ServiceStop stops a service.

func (*Client) Shutdown

func (c *Client) Shutdown(ctx context.Context) (err error)

Shutdown implements the proto.MachineServiceClient interface.

func (*Client) Stats

func (c *Client) Stats(ctx context.Context, namespace string, driver common.ContainerDriver, callOptions ...grpc.CallOption) (resp *machineapi.StatsResponse, err error)

Stats implements the proto.MachineServiceClient interface.

func (*Client) Time

func (c *Client) Time(ctx context.Context, callOptions ...grpc.CallOption) (resp *timeapi.TimeResponse, err error)

Time returns the time.

func (*Client) TimeCheck

func (c *Client) TimeCheck(ctx context.Context, server string, callOptions ...grpc.CallOption) (resp *timeapi.TimeResponse, err error)

TimeCheck returns the time compared to the specified ntp server.

func (*Client) Upgrade

func (c *Client) Upgrade(ctx context.Context, image string, preserve, stage, force bool, callOptions ...grpc.CallOption) (resp *machineapi.UpgradeResponse, err error)

Upgrade initiates a Talos upgrade ... and implements the proto.MachineServiceClient interface.

func (*Client) Version

func (c *Client) Version(ctx context.Context, callOptions ...grpc.CallOption) (resp *machineapi.VersionResponse, err error)

Version implements the proto.MachineServiceClient interface.

type Credentials

type Credentials struct {
	CA  []byte
	Crt tls.Certificate
}

Credentials represents the set of values required to initialize a valid Client.

func CredentialsFromConfigContext

func CredentialsFromConfigContext(context *clientconfig.Context) (*Credentials, error)

CredentialsFromConfigContext constructs the client Credentials from the given configuration Context.

func NewClientContextAndCredentialsFromConfig deprecated

func NewClientContextAndCredentialsFromConfig(p, ctx string) (context *clientconfig.Context, creds *Credentials, err error)

NewClientContextAndCredentialsFromConfig initializes Credentials from config file.

Deprecated: use Option-based methods for client creation.

func NewClientContextAndCredentialsFromParsedConfig deprecated

func NewClientContextAndCredentialsFromParsedConfig(c *clientconfig.Config, ctx string) (context *clientconfig.Context, creds *Credentials, err error)

NewClientContextAndCredentialsFromParsedConfig initializes Credentials from parsed configuration.

Deprecated: use Option-based methods for client creation.

type Event

type Event struct {
	Node    string
	TypeURL string
	ID      string
	Payload proto.Message
}

Event as received from the API.

type EventsOptionFunc

type EventsOptionFunc func(opts *machineapi.EventsRequest)

EventsOptionFunc defines the options for the Events API.

func WithTailDuration

func WithTailDuration(dur time.Duration) EventsOptionFunc

WithTailDuration sets up Watcher to return events with timestamp >= (now - tailDuration).

func WithTailEvents

func WithTailEvents(number int32) EventsOptionFunc

WithTailEvents sets up Events API to return specified number of past events.

If number is negative, all the available past events are returned.

func WithTailID

func WithTailID(id string) EventsOptionFunc

WithTailID sets up Events API to return events with ID > TailID.

type InspectClient

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

InspectClient provides access to inspect API.

func (*InspectClient) ControllerRuntimeDependencies

func (c *InspectClient) ControllerRuntimeDependencies(ctx context.Context, callOptions ...grpc.CallOption) (*inspectapi.ControllerRuntimeDependenciesResponse, error)

ControllerRuntimeDependencies returns graph describing dependencies between controllers.

type MachineStream

type MachineStream interface {
	Recv() (*common.Data, error)
	grpc.ClientStream
}

MachineStream is a common interface for streams returned by streaming APIs.

type NodeError

type NodeError struct {
	Node string
	Err  error
}

NodeError is RPC error from some node.

func (*NodeError) Error

func (ne *NodeError) Error() string

func (*NodeError) Unwrap

func (ne *NodeError) Unwrap() error

Unwrap implements errors.Unwrap interface.

type OptionFunc

type OptionFunc func(*Options) error

OptionFunc sets an option for the creation of the Client.

func WithConfig

func WithConfig(cfg *clientconfig.Config) OptionFunc

WithConfig configures the Client with the configuration provided. Additionally use WithContextName to override the default context in the Config.

func WithConfigContext

func WithConfigContext(cfg *clientconfig.Context) OptionFunc

WithConfigContext configures the Client with the configuration context provided.

func WithConfigFromFile

func WithConfigFromFile(fn string) OptionFunc

WithConfigFromFile creates a Client with its configuration extracted from the given file. Additionally use WithContextName to select a context other than the default.

func WithContextName

func WithContextName(name string) OptionFunc

WithContextName overrides the default context inside a provided client Config.

func WithDefaultConfig

func WithDefaultConfig() OptionFunc

WithDefaultConfig creates a Client with its configuration sourced from the default config file location. Additionally use WithContextName to select a context other than the default.

func WithEndpoints

func WithEndpoints(endpoints ...string) OptionFunc

WithEndpoints overrides the default endpoints with the provided list.

func WithGRPCDialOptions

func WithGRPCDialOptions(opts ...grpc.DialOption) OptionFunc

WithGRPCDialOptions adds the given grpc.DialOptions to a Client.

func WithTLSConfig

func WithTLSConfig(tlsConfig *tls.Config) OptionFunc

WithTLSConfig overrides the default TLS configuration with the one provided.

func WithUnixSocket

func WithUnixSocket(path string) OptionFunc

WithUnixSocket creates a Client which connects to apid over local file socket.

This option disables config parsing and TLS.

Connection over unix socket is only used within the Talos node.

type Options

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

Options contains the set of client configuration options.

type RebootMode added in v0.14.0

type RebootMode func(*machineapi.RebootRequest)

RebootMode provides various mode through which the reboot process can be done.

type ResourceListClient

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

ResourceListClient wraps gRPC list client.

func (*ResourceListClient) Recv

func (client *ResourceListClient) Recv() (ResourceResponse, error)

Recv next item from the list.

type ResourceResponse

type ResourceResponse struct {
	Metadata   *common.Metadata
	Definition resource.Resource
	Resource   resource.Resource
}

ResourceResponse is a parsed resource response.

type ResourceWatchClient

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

ResourceWatchClient wraps gRPC watch client.

func (*ResourceWatchClient) Recv

func (client *ResourceWatchClient) Recv() (WatchResponse, error)

Recv next item from the list.

type ResourcesClient

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

ResourcesClient provides access to resource API.

func (*ResourcesClient) Get

func (c *ResourcesClient) Get(ctx context.Context, resourceNamespace, resourceType, resourceID string, callOptions ...grpc.CallOption) ([]ResourceResponse, error)

Get a specified resource.

func (*ResourcesClient) List

func (c *ResourcesClient) List(ctx context.Context, resourceNamespace, resourceType string, callOptions ...grpc.CallOption) (*ResourceListClient, error)

List resources by kind.

func (*ResourcesClient) Watch

func (c *ResourcesClient) Watch(ctx context.Context, resourceNamespace, resourceType, resourceID string, callOptions ...grpc.CallOption) (*ResourceWatchClient, error)

Watch resources by kind or by kind and ID.

func (*ResourcesClient) WatchRequest

func (c *ResourcesClient) WatchRequest(ctx context.Context, request *resourceapi.WatchRequest, callOptions ...grpc.CallOption) (*ResourceWatchClient, error)

WatchRequest resources by watch request.

type ServiceInfo

type ServiceInfo struct {
	Metadata *common.Metadata
	Service  *machineapi.ServiceInfo
}

ServiceInfo provides info about a service and node metadata.

type WatchResponse

type WatchResponse struct {
	ResourceResponse
	EventType state.EventType
}

WatchResponse is a parsed resource watch response.

Directories

Path Synopsis
Package resolver implements gRPC resolvers.
Package resolver implements gRPC resolvers.

Jump to

Keyboard shortcuts

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