client

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2025 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CaddyServiceName = "caddy"
	// CaddyImage is the official Caddy Docker image on Docker Hub: https://hub.docker.com/_/caddy
	CaddyImage = "caddy"
)

Variables

View Source
var ErrNoReachableMachines = errors.New("no internet-reachable machines running service containers")

Functions

func LatestCaddyImage

func LatestCaddyImage() (reference.NamedTagged, error)

LatestCaddyImage returns the latest image of the official Caddy Docker image on Docker Hub. The latest image is determined by the latest version tag 2.x.x.

func MachineMatchesFilter added in v0.6.0

func MachineMatchesFilter(machine *pb.MachineMember, filter *api.MachineFilter) bool

func PrintWarning added in v0.6.0

func PrintWarning(msg string)

Types

type Client

type Client struct {
	pb.MachineClient
	pb.ClusterClient
	// Docker is a namespaced client for the Docker service to distinguish Uncloud-specific service container operations
	// from generic Docker operations.
	Docker *docker.Client
	// contains filtered or unexported fields
}

Client is a client for the machine API.

func New

func New(ctx context.Context, connector Connector) (*Client, error)

New creates a new client for the machine API. The connector is used to establish the connection either locally or remotely. The client is responsible for closing the connector.

func (*Client) Close

func (cli *Client) Close() error

func (*Client) CreateContainer

func (cli *Client) CreateContainer(
	ctx context.Context, serviceID string, spec api.ServiceSpec, machineID string,
) (container.CreateResponse, error)

CreateContainer creates a new container for the given service on the specified machine.

func (*Client) CreateIngressRecords

func (cli *Client) CreateIngressRecords(ctx context.Context, serviceID string) ([]*pb.DNSRecord, error)

CreateIngressRecords verifies which machines running the specified service (typically Caddy) are reachable from the internet, then creates DNS records for the cluster domain pointing to those machines. It tests each machine by sending HTTP requests to their public IPs. Only machines that respond correctly with their machine ID are included in the resulting DNS configuration. Returns the created DNS records or an error.

func (*Client) CreateVolume added in v0.6.0

func (cli *Client) CreateVolume(
	ctx context.Context, machineNameOrID string, opts volume.CreateOptions,
) (api.MachineVolume, error)

CreateVolume creates a new volume on the specified machine.

func (*Client) GetDomain

func (cli *Client) GetDomain(ctx context.Context) (string, error)

GetDomain returns the cluster domain name or ErrNotFound if it hasn't been reserved yet.

func (*Client) InspectContainer

func (cli *Client) InspectContainer(
	ctx context.Context, serviceNameOrID, containerNameOrID string,
) (api.MachineServiceContainer, error)

InspectContainer returns the information about the specified container within the service.

func (*Client) InspectImage

func (cli *Client) InspectImage(ctx context.Context, id string) ([]api.MachineImage, error)

func (*Client) InspectMachine

func (cli *Client) InspectMachine(ctx context.Context, nameOrID string) (*pb.MachineMember, error)

func (*Client) InspectRemoteImage

func (cli *Client) InspectRemoteImage(ctx context.Context, id string) ([]api.MachineRemoteImage, error)

func (*Client) InspectService

func (cli *Client) InspectService(ctx context.Context, nameOrID string) (api.Service, error)

InspectService returns detailed information about a service and its containers. The nameOrID parameter can be either a service name or ID.

func (*Client) InspectServiceFromStore

func (cli *Client) InspectServiceFromStore(ctx context.Context, id string) (api.Service, error)

InspectServiceFromStore returns detailed information about a service and its containers from the distributed store. Due to eventual consistency of the store, the returned information may not reflect the most recent changes. The id parameter can be either a service ID or name.

func (*Client) ListMachines

func (cli *Client) ListMachines(ctx context.Context, filter *api.MachineFilter) (api.MachineMembersList, error)

ListMachines returns a list of all machines registered in the cluster that match the filter.

func (*Client) ListServices

func (cli *Client) ListServices(ctx context.Context) ([]api.Service, error)

ListServices returns a list of all services and their containers.

func (*Client) ListVolumes added in v0.6.0

func (cli *Client) ListVolumes(ctx context.Context, filter *api.VolumeFilter) ([]api.MachineVolume, error)

ListVolumes returns a list of all volumes on the cluster machines that match the filter.

func (*Client) NewCaddyDeployment

func (cli *Client) NewCaddyDeployment(image string, placement api.Placement) (*deploy.Deployment, error)

NewCaddyDeployment creates a new deployment for a Caddy reverse proxy service. The service is deployed in global mode to all machines in the cluster. If the image is not provided, the latest version of the official Caddy Docker image is used.

func (*Client) NewDeployment

func (cli *Client) NewDeployment(spec api.ServiceSpec, strategy deploy.Strategy) *deploy.Deployment

NewDeployment creates a new deployment for the given service specification. If strategy is nil, a default deploy.RollingStrategy will be used.

func (*Client) RemoveContainer

func (cli *Client) RemoveContainer(
	ctx context.Context, serviceNameOrID, containerNameOrID string, opts container.RemoveOptions,
) error

RemoveContainer removes the specified container within the service.

func (*Client) RemoveService

func (cli *Client) RemoveService(ctx context.Context, id string) error

RemoveService removes all containers on all machines that belong to the specified service. The id parameter can be either a service ID or name.

func (*Client) RemoveVolume added in v0.6.0

func (cli *Client) RemoveVolume(ctx context.Context, machineNameOrID, volumeName string, force bool) error

RemoveVolume removes a volume from the specified machine.

func (*Client) RunService

func (cli *Client) RunService(ctx context.Context, spec api.ServiceSpec) (api.RunServiceResponse, error)

func (*Client) ServiceOperationNameResolver

func (cli *Client) ServiceOperationNameResolver(ctx context.Context, svc api.Service) (*MapNameResolver, error)

ServiceOperationNameResolver returns a machine and container name resolver for a service that can be used to format deployment operations.

func (*Client) StartContainer

func (cli *Client) StartContainer(ctx context.Context, serviceNameOrID, containerNameOrID string) error

StartContainer starts the specified container within the service.

func (*Client) StopContainer

func (cli *Client) StopContainer(
	ctx context.Context, serviceNameOrID, containerNameOrID string, opts container.StopOptions,
) error

StopContainer stops the specified container within the service.

type Connector

type Connector interface {
	Connect(ctx context.Context) (*grpc.ClientConn, error)
	Close() error
}

Connector is an interface for establishing a connection to the machine API.

type MapNameResolver

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

MapNameResolver resolves machine and container IDs to their names using a static map.

func NewNameResolver

func NewNameResolver(machines, containers map[string]string) *MapNameResolver

func (*MapNameResolver) ContainerName

func (r *MapNameResolver) ContainerName(containerID string) string

func (*MapNameResolver) MachineName

func (r *MapNameResolver) MachineName(machineID string) string

type User

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

func NewUser

func NewUser(privateKey secret.Secret) (*User, error)

func (*User) ManagementIP

func (u *User) ManagementIP() netip.Addr

func (*User) PrivateKey

func (u *User) PrivateKey() secret.Secret

func (*User) PublicKey

func (u *User) PublicKey() secret.Secret

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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