Documentation
¶
Index ¶
- Constants
- Variables
- func PortsEqual(a, b []PortSpec) bool
- func ProxyMachinesContext(ctx context.Context, cli MachineClient, namesOrIDs []string) (context.Context, error)
- func ValidateServiceID(id string) bool
- type Client
- type Container
- type ContainerClient
- type ContainerSpec
- type DNSClient
- type ImageClient
- type MachineClient
- type MachineContainer
- type MachineImage
- type MachineRemoteImage
- type MachineServiceContainer
- type PortSpec
- type RemoteImage
- type Service
- type ServiceClient
- type ServiceContainer
- type ServiceSpec
Constants ¶
const ( LabelManaged = "uncloud.managed" LabelServiceID = "uncloud.service.id" LabelServiceName = "uncloud.service.name" LabelServiceMode = "uncloud.service.mode" LabelServicePorts = "uncloud.service.ports" )
const ( PortModeIngress = "ingress" PortModeHost = "host" ProtocolHTTP = "http" ProtocolHTTPS = "https" ProtocolTCP = "tcp" ProtocolUDP = "udp" )
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 ¶
var ErrNotFound = errors.New("not found")
Functions ¶
func PortsEqual ¶
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 ¶
Types ¶
type Client ¶
type Client interface {
ContainerClient
DNSClient
ImageClient
MachineClient
ServiceClient
}
type Container ¶
type Container struct {
types.ContainerJSON
}
func (*Container) Healthy ¶
Healthy determines if the container is running and healthy. A running container with no health check configured is considered healthy.
func (*Container) HumanState ¶
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 ¶
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 ImageClient ¶
type ImageClient interface {
InspectImage(ctx context.Context, id string) ([]MachineImage, error)
InspectRemoteImage(ctx context.Context, id string) ([]MachineRemoteImage, error)
}
type MachineClient ¶
type MachineContainer ¶
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 ¶
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
}
type ServiceClient ¶
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