api

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LabelManaged      = "uncloud.managed"
	LabelServiceID    = "uncloud.service.id"
	LabelServiceName  = "uncloud.service.name"
	LabelServiceMode  = "uncloud.service.mode"
	LabelServicePorts = "uncloud.service.ports"
)
View Source
const (
	PortModeIngress = "ingress"
	PortModeHost    = "host"

	ProtocolHTTP  = "http"
	ProtocolHTTPS = "https"
	ProtocolTCP   = "tcp"
	ProtocolUDP   = "udp"
)
View Source
const (
	ServiceModeReplicated = "replicated"
	ServiceModeGlobal     = "global"

	// PullPolicyAlways means the image is always pulled from the registry.
	PullPolicyAlways = "always"
	// PullPolicyMissing means the image is pulled from the registry only if it's not available on the machine where
	// a container is started. This is the default pull policy.
	// TODO: make each machine aware of the images on other machines and it possible to pull from them.
	// 	Pull from the registry only if the image is missing on all machines.
	PullPolicyMissing = "missing"
	// PullPolicyNever means the image is never pulled from the registry. A service with this pull policy can only be
	// deployed to machines where the image is already available.
	// TODO: see the TODO above for PullPolicyMissing. Pull from other machines in the cluster if available.
	PullPolicyNever = "never"
)

Variables

View Source
var ErrNotFound = errors.New("not found")

Functions

func PortsEqual

func PortsEqual(a, b []PortSpec) bool

PortsEqual returns true if the two port sets are equal. The order of the ports is not important.

func ProxyMachinesContext

func ProxyMachinesContext(ctx context.Context, cli MachineClient, namesOrIDs []string) (context.Context, error)

ProxyMachinesContext returns a new context that proxies gRPC requests to the specified machines. If namesOrIDs is nil, all machines are included.

func ValidateServiceID

func ValidateServiceID(id string) bool

Types

type Container

type Container struct {
	types.ContainerJSON
}

func (*Container) Healthy

func (c *Container) Healthy() bool

Healthy determines if the container is running and healthy. A running container with no health check configured is considered healthy.

func (*Container) HumanState

func (c *Container) HumanState() (string, error)

HumanState returns a human-readable description of the container's state. Based on the Docker implementation: https://github.com/moby/moby/blob/b343d235a0a1f30c8f05b1d651238e72158dc25d/container/state.go#L79-L113

func (*Container) UnmarshalJSON

func (c *Container) UnmarshalJSON(data []byte) error

type ContainerClient

type ContainerClient interface {
	CreateContainer(
		ctx context.Context, serviceID string, spec ServiceSpec, machineID string,
	) (container.CreateResponse, error)
	InspectContainer(ctx context.Context, serviceNameOrID, containerNameOrID string) (MachineServiceContainer, error)
	RemoveContainer(ctx context.Context, serviceNameOrID, containerNameOrID string, opts container.RemoveOptions) error
	StartContainer(ctx context.Context, serviceNameOrID, containerNameOrID string) error
	StopContainer(ctx context.Context, serviceNameOrID, containerNameOrID string, opts container.StopOptions) error
}

type ContainerSpec

type ContainerSpec struct {
	// Command overrides the default CMD of the image to be executed when running a container.
	Command []string
	// Entrypoint overrides the default ENTRYPOINT of the image.
	Entrypoint []string
	Image      string
	// Run a custom init inside the container. If nil, use the daemon's configured settings.
	Init *bool
	// PullPolicy determines when to pull the image from the registry or use the image already available in the cluster.
	// Default is PullPolicyMissing if empty.
	PullPolicy string
	// List of volumes to bind mount into the container.
	Volumes []string
}

ContainerSpec defines the desired state of a container in a service. ATTENTION: after changing this struct, verify if deploy.EvalContainerSpecChange needs to be updated.

func (*ContainerSpec) Clone

func (s *ContainerSpec) Clone() ContainerSpec

func (*ContainerSpec) Equals

func (s *ContainerSpec) Equals(spec ContainerSpec) bool

func (*ContainerSpec) SetDefaults

func (s *ContainerSpec) SetDefaults() ContainerSpec

SetDefaults returns a copy of the container spec with default values set.

func (*ContainerSpec) Validate

func (s *ContainerSpec) Validate() error

type DNSClient

type DNSClient interface {
	GetDomain(ctx context.Context) (string, error)
}

type ImageClient

type ImageClient interface {
	InspectImage(ctx context.Context, id string) ([]MachineImage, error)
	InspectRemoteImage(ctx context.Context, id string) ([]MachineRemoteImage, error)
}

type MachineClient

type MachineClient interface {
	InspectMachine(ctx context.Context, id string) (*pb.MachineMember, error)
	ListMachines(ctx context.Context) ([]*pb.MachineMember, error)
}

type MachineContainer

type MachineContainer struct {
	MachineID string
	Container Container
}

type MachineImage

type MachineImage struct {
	Metadata *pb.Metadata
	Image    types.ImageInspect
}

type MachineRemoteImage

type MachineRemoteImage struct {
	Metadata *pb.Metadata
	Image    RemoteImage
}

MachineRemoteImage represents an image in a remote registry fetched by a particular machine.

type MachineServiceContainer

type MachineServiceContainer struct {
	MachineID string
	Container ServiceContainer
}

type PortSpec

type PortSpec struct {
	// Hostname specifies the DNS name that will route to this service. Only valid in ingress mode.
	Hostname string
	// HostIP is the host IP to bind the PublishedPort to. Only valid in host mode.
	HostIP netip.Addr
	// PublishedPort is the port number exposed outside the container.
	// In ingress mode, this is the load balancer port. In host mode, this is the port bound on the host.
	PublishedPort uint16
	// ContainerPort is the port inside the container that the service listens on.
	ContainerPort uint16
	// Protocol specifies the network protocol.
	Protocol string
	// Mode specifies how the port is published.
	Mode string
}

func ParsePortSpec

func ParsePortSpec(port string) (PortSpec, error)

func (*PortSpec) String

func (p *PortSpec) String() (string, error)

String returns the port specification in the -p/--publish flag format. Format: [hostname:][load_balancer_port:]container_port/protocol for ingress mode (default) or [host_ip:]:host_port:container_port/protocol@host for host mode.

func (*PortSpec) Validate

func (p *PortSpec) Validate() error

type RemoteImage

type RemoteImage struct {
	Reference     reference.Canonical
	IndexManifest *v1.Index
	ImageManifest *v1.Manifest
}

RemoteImage represents an image in a remote registry. The canonical reference includes the image digest. Either IndexManifest or ImageManifest must be set depending on whether the reference points to an index (multi-platform image) or a single-platform image.

type Service

type Service struct {
	ID         string
	Name       string
	Mode       string
	Containers []MachineServiceContainer
}

func ServiceFromProto

func ServiceFromProto(s *pb.Service) (Service, error)

func (*Service) Endpoints

func (s *Service) Endpoints() []string

Endpoints returns the exposed HTTP and HTTPS endpoints of the service.

type ServiceClient

type ServiceClient interface {
	InspectService(ctx context.Context, id string) (Service, error)
}

type ServiceContainer

type ServiceContainer struct {
	Container
	ServiceSpec ServiceSpec
}

func (*ServiceContainer) ConflictingServicePorts

func (c *ServiceContainer) ConflictingServicePorts(ports []PortSpec) ([]PortSpec, error)

ConflictingServicePorts returns a list of service ports that conflict with the given ports.

func (*ServiceContainer) ServiceID

func (c *ServiceContainer) ServiceID() string

ServiceID returns the ID of the service this container belongs to.

func (*ServiceContainer) ServiceMode

func (c *ServiceContainer) ServiceMode() string

ServiceMode returns the replication mode of the service this container belongs to.

func (*ServiceContainer) ServiceName

func (c *ServiceContainer) ServiceName() string

ServiceName returns the name of the service this container belongs to.

func (*ServiceContainer) ServicePorts

func (c *ServiceContainer) ServicePorts() ([]PortSpec, error)

ServicePorts returns the ports this container publishes as part of its service.

type ServiceSpec

type ServiceSpec struct {
	Container ContainerSpec
	// Mode is the replication mode of the service. Default is ServiceModeReplicated if empty.
	Mode string
	Name string
	// Ports defines what service ports to publish to make the service accessible outside the cluster.
	Ports []PortSpec
	// Replicas is the number of containers to run for the service. Only valid for a replicated service.
	Replicas uint `json:",omitempty"`
}

ServiceSpec defines the desired state of a service. ATTENTION: after changing this struct, verify if deploy.EvalContainerSpecChange needs to be updated.

func (*ServiceSpec) Clone

func (s *ServiceSpec) Clone() ServiceSpec

func (*ServiceSpec) SetDefaults

func (s *ServiceSpec) SetDefaults() ServiceSpec

func (*ServiceSpec) Validate

func (s *ServiceSpec) Validate() error

Jump to

Keyboard shortcuts

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