client

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: MPL-2.0 Imports: 51 Imported by: 23

Documentation

Overview

Package client provides Talos API client.

Index

Constants

This section is empty.

Variables

View Source
var ErrEventNotSupported = fmt.Errorf("event is not supported")

ErrEventNotSupported is returned from the event decoder when we encounter an unknown event.

Functions

func AddrFromPeer

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

AddrFromPeer extracts peer address from grpc Peer.

func CertificateFromConfigContext

func CertificateFromConfigContext(context *clientconfig.Context) (*tls.Certificate, error)

CertificateFromConfigContext constructs the client Credentials from the given configuration Context.

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 Status

func Status(err error) *status.Status

Status returns the status if it is a Status error, nil otherwise.

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 WithGRPCBasicAuth

func WithGRPCBasicAuth(username, password string) grpc.DialOption

WithGRPCBasicAuth returns gRPC credentials for basic auth.

func WithNode

func WithNode(ctx context.Context, node string) context.Context

WithNode wraps the context with metadata to send request to a single node.

Request will be proxied by the endpoint to the specified node without any further processing.

func WithNodes

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

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

Responses from all nodes are aggregated by the `apid` service and sent back as a single response.

func WithPowerCycle

func WithPowerCycle(req *machineapi.RebootRequest)

WithPowerCycle option runs the Reboot fun in powercycle mode.

Types

type BasicAuth

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

BasicAuth implements the credentials.PerRPCCredentials interface and holds credentials for Basic Auth.

func (BasicAuth) GetRequestMetadata

func (c BasicAuth) GetRequestMetadata(ctx context.Context, url ...string) (map[string]string, error)

GetRequestMetadata implements credentials.PerGRPCCredentials.

func (BasicAuth) RequireTransportSecurity

func (c BasicAuth) RequireTransportSecurity() bool

RequireTransportSecurity implements credentials.PerRPCCredentials.

type Client

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

	// Deprecated: use COSI client.
	Resources      *ResourcesClient
	ResourceClient resourceapi.ResourceServiceClient //nolint:staticcheck

	COSI state.State

	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 (*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) Conn

func (c *Client) Conn() *grpc.ClientConn

Conn returns underlying client connection.

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) EtcdAlarmDisarm added in v1.4.0

func (c *Client) EtcdAlarmDisarm(ctx context.Context, opts ...grpc.CallOption) (*machineapi.EtcdAlarmDisarmResponse, error)

EtcdAlarmDisarm disarms etcd alarms for the current node.

This method is available only on control plane nodes (which run etcd).

func (*Client) EtcdAlarmList added in v1.4.0

func (c *Client) EtcdAlarmList(ctx context.Context, opts ...grpc.CallOption) (*machineapi.EtcdAlarmListResponse, error)

EtcdAlarmList lists etcd alarms for the current node.

This method is available only on control plane nodes (which run etcd).

func (*Client) EtcdDefragment added in v1.4.0

func (c *Client) EtcdDefragment(ctx context.Context, opts ...grpc.CallOption) (*machineapi.EtcdDefragmentResponse, error)

EtcdDefragment defragments etcd data directory for the current node.

Defragmentation is a resource-heavy operation, so it should only run on a specific node.

This method is available only on control plane nodes (which run etcd).

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 deprecated

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

EtcdRemoveMember removes a node from etcd cluster by member hostname.

Deprecated: Use EtcdRemoveMemberByID instead.

func (*Client) EtcdRemoveMemberByID

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

EtcdRemoveMemberByID removes a node from etcd cluster by etcd member ID.

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) EtcdStatus added in v1.4.0

func (c *Client) EtcdStatus(ctx context.Context, opts ...grpc.CallOption) (*machineapi.EtcdStatusResponse, error)

EtcdStatus returns etcd status for the current member.

This method is available only on control plane nodes (which run etcd).

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) EventsWatchV2

func (c *Client) EventsWatchV2(ctx context.Context, ch chan<- EventResult, opts ...EventsOptionFunc) error

EventsWatchV2 watches events of a single node and wraps the Events by providing a simpler interface. It blocks until the first (empty) event is received, then spawns a goroutine that sends events to the given channel. EventResult objects sent into the channel contain either the errors or the received events.

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) GetClusterName

func (c *Client) GetClusterName() string

GetClusterName returns the client's cluster name from the override set with WithClustername or from the configuration.

func (*Client) GetConfigContext

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

GetConfigContext returns resolved config context.

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) MetaDelete added in v1.4.0

func (c *Client) MetaDelete(ctx context.Context, key uint8, callOptions ...grpc.CallOption) error

MetaDelete deletes a key from META storage.

func (*Client) MetaWrite added in v1.4.0

func (c *Client) MetaWrite(ctx context.Context, key uint8, value []byte, callOptions ...grpc.CallOption) error

MetaWrite writes a key to META storage.

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) Netstat added in v1.4.0

func (c *Client) Netstat(ctx context.Context, req *machineapi.NetstatRequest, callOptions ...grpc.CallOption) (*machineapi.NetstatResponse, error)

Netstat lists the network sockets on the current node.

func (*Client) PacketCapture

func (c *Client) PacketCapture(ctx context.Context, req *machineapi.PacketCaptureRequest) (io.ReadCloser, <-chan error, error)

PacketCapture 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) error

Reboot implements the proto.MachineServiceClient interface.

func (*Client) RebootWithResponse

func (c *Client) RebootWithResponse(ctx context.Context, opts ...RebootMode) (*machineapi.RebootResponse, error)

RebootWithResponse reboots the machine and returns the response.

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) error

ResetGeneric implements the proto.MachineServiceClient interface.

func (*Client) ResetGenericWithResponse

func (c *Client) ResetGenericWithResponse(ctx context.Context, req *machineapi.ResetRequest) (*machineapi.ResetResponse, error)

ResetGenericWithResponse resets the machine and returns the response.

func (*Client) ResolveResourceKind

func (c *Client) ResolveResourceKind(ctx context.Context, resourceNamespace *resource.Namespace, resourceType resource.Type) (*meta.ResourceDefinition, error)

ResolveResourceKind resolves potentially aliased 'resourceType' and replaces empty 'resourceNamespace' with the default namespace for the resource.

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, opts ...ShutdownOption) error

Shutdown implements the proto.MachineServiceClient interface.

func (*Client) ShutdownWithResponse

func (c *Client) ShutdownWithResponse(ctx context.Context, opts ...ShutdownOption) (*machineapi.ShutdownResponse, error)

ShutdownWithResponse shuts down the machine and returns the response.

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 Event

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

Event as received from the API.

func UnmarshalEvent

func UnmarshalEvent(event *machineapi.Event) (*Event, error)

UnmarshalEvent decodes the event coming from the gRPC stream from any to the exact type.

type EventResult

type EventResult struct {
	// Event is the event that was received.
	Event Event
	// Err is the error that occurred.
	Error error
}

EventResult is the result of an event watch, containing either an Event or an error.

type EventsOptionFunc

type EventsOptionFunc func(opts *machineapi.EventsRequest)

EventsOptionFunc defines the options for the Events API.

func WithActorID

func WithActorID(actorID string) EventsOptionFunc

WithActorID sets up Watcher to return events with the specified actor ID.

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 WithCluster

func WithCluster(cluster string) OptionFunc

WithCluster creates a Client which connects to the named cluster.

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

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 deprecated

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

ResourcesClient provides access to resource API.

Deprecated: use COSI client.

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 ShutdownOption

type ShutdownOption func(*machineapi.ShutdownRequest)

ShutdownOption provides shutdown API options.

func WithShutdownForce

func WithShutdownForce(force bool) ShutdownOption

WithShutdownForce forces the shutdown even if the Kubernetes API is down.

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