Documentation
¶
Index ¶
- Constants
- func ToDockerMounts(volumes []api.VolumeSpec, mounts []api.VolumeMount) ([]mount.Mount, error)
- type Client
- func (c *Client) Close() error
- func (c *Client) CreateContainer(ctx context.Context, config *container.Config, ...) (container.CreateResponse, error)
- func (c *Client) CreateServiceContainer(ctx context.Context, serviceID string, spec api.ServiceSpec, ...) (container.CreateResponse, error)
- func (c *Client) CreateVolume(ctx context.Context, opts volume.CreateOptions) (volume.Volume, error)
- func (c *Client) InspectContainer(ctx context.Context, id string) (types.ContainerJSON, error)
- func (c *Client) InspectImage(ctx context.Context, id string) ([]api.MachineImage, error)
- func (c *Client) InspectRemoteImage(ctx context.Context, id string) ([]api.MachineRemoteImage, error)
- func (c *Client) InspectServiceContainer(ctx context.Context, id string) (api.ServiceContainer, error)
- func (c *Client) ListContainers(ctx context.Context, opts container.ListOptions) ([]MachineContainers, error)
- func (c *Client) ListServiceContainers(ctx context.Context, serviceNameOrID string, opts container.ListOptions) ([]MachineServiceContainers, error)
- func (c *Client) ListVolumes(ctx context.Context, opts volume.ListOptions) ([]MachineVolumes, error)
- func (c *Client) PullImage(ctx context.Context, image string, opts PullOptions) (<-chan PullImageMessage, error)
- func (c *Client) RemoveContainer(ctx context.Context, id string, opts container.RemoveOptions) error
- func (c *Client) RemoveServiceContainer(ctx context.Context, id string, opts container.RemoveOptions) error
- func (c *Client) RemoveVolume(ctx context.Context, id string, force bool) error
- func (c *Client) StartContainer(ctx context.Context, id string, opts container.StartOptions) error
- func (c *Client) StopContainer(ctx context.Context, id string, opts container.StopOptions) error
- type Controller
- type MachineContainers
- type MachineServiceContainers
- type MachineVolumes
- type PullImageMessage
- type PullOptions
- type Server
- func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerRequest) (*pb.CreateContainerResponse, error)
- func (s *Server) CreateServiceContainer(ctx context.Context, req *pb.CreateServiceContainerRequest) (*pb.CreateContainerResponse, error)
- func (s *Server) CreateVolume(ctx context.Context, req *pb.CreateVolumeRequest) (*pb.CreateVolumeResponse, error)
- func (s *Server) InspectContainer(ctx context.Context, req *pb.InspectContainerRequest) (*pb.InspectContainerResponse, error)
- func (s *Server) InspectImage(ctx context.Context, req *pb.InspectImageRequest) (*pb.InspectImageResponse, error)
- func (s *Server) InspectRemoteImage(_ context.Context, req *pb.InspectRemoteImageRequest) (*pb.InspectRemoteImageResponse, error)
- func (s *Server) InspectServiceContainer(ctx context.Context, req *pb.InspectContainerRequest) (*pb.ServiceContainer, error)
- func (s *Server) ListContainers(ctx context.Context, req *pb.ListContainersRequest) (*pb.ListContainersResponse, error)
- func (s *Server) ListServiceContainers(ctx context.Context, req *pb.ListServiceContainersRequest) (*pb.ListServiceContainersResponse, error)
- func (s *Server) ListVolumes(ctx context.Context, req *pb.ListVolumesRequest) (*pb.ListVolumesResponse, error)
- func (s *Server) PullImage(req *pb.PullImageRequest, stream grpc.ServerStreamingServer[pb.JSONMessage]) error
- func (s *Server) RemoveContainer(ctx context.Context, req *pb.RemoveContainerRequest) (*emptypb.Empty, error)
- func (s *Server) RemoveServiceContainer(ctx context.Context, req *pb.RemoveContainerRequest) (*emptypb.Empty, error)
- func (s *Server) RemoveVolume(ctx context.Context, req *pb.RemoveVolumeRequest) (*emptypb.Empty, error)
- func (s *Server) StartContainer(ctx context.Context, req *pb.StartContainerRequest) (*emptypb.Empty, error)
- func (s *Server) StopContainer(ctx context.Context, req *pb.StopContainerRequest) (*emptypb.Empty, error)
- type ServerOption
- type Service
Constants ¶
const ( NetworkName = "uncloud" // EventsDebounceInterval defines how long to wait before processing the next Docker event. Multiple events // occurring within this window will be processed together as a single event to prevent system overload. EventsDebounceInterval = 100 * time.Millisecond // SyncInterval defines a regular interval to sync containers to the cluster store. SyncInterval = 30 * time.Second )
Variables ¶
This section is empty.
Functions ¶
func ToDockerMounts ¶ added in v0.6.0
func ToDockerMounts(volumes []api.VolumeSpec, mounts []api.VolumeMount) ([]mount.Mount, error)
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a gRPC client for the Docker service that provides a similar interface to the Docker HTTP client.
func NewClient ¶
func NewClient(conn *grpc.ClientConn) *Client
NewClient creates a new Docker gRPC client with the provided gRPC connection.
func (*Client) CreateContainer ¶
func (c *Client) CreateContainer( ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *ocispec.Platform, name string, ) (container.CreateResponse, error)
CreateContainer creates a new container based on the given configuration.
func (*Client) CreateServiceContainer ¶
func (c *Client) CreateServiceContainer( ctx context.Context, serviceID string, spec api.ServiceSpec, containerName string, ) (container.CreateResponse, error)
CreateServiceContainer creates a new container for the service with the given specifications.
func (*Client) CreateVolume ¶ added in v0.6.0
func (c *Client) CreateVolume(ctx context.Context, opts volume.CreateOptions) (volume.Volume, error)
CreateVolume creates a new volume with the given options.
func (*Client) InspectContainer ¶
InspectContainer returns the container information for the given container ID.
func (*Client) InspectImage ¶
InspectImage returns the image information for the given image ID. The request may be sent to multiple machines.
func (*Client) InspectRemoteImage ¶
func (c *Client) InspectRemoteImage(ctx context.Context, id string) ([]api.MachineRemoteImage, error)
InspectRemoteImage returns the image metadata for an image in a remote registry using the machine's Docker auth credentials if necessary. If the response from a machine doesn't contain an error, the api.RemoteImage will either contain an IndexManifest or an ImageManifest.
func (*Client) InspectServiceContainer ¶
func (c *Client) InspectServiceContainer(ctx context.Context, id string) (api.ServiceContainer, error)
InspectServiceContainer returns the container information and service specification that was used to create the container with the given ID.
func (*Client) ListContainers ¶
func (c *Client) ListContainers(ctx context.Context, opts container.ListOptions) ([]MachineContainers, error)
func (*Client) ListServiceContainers ¶
func (c *Client) ListServiceContainers( ctx context.Context, serviceNameOrID string, opts container.ListOptions, ) ([]MachineServiceContainers, error)
ListServiceContainers returns all containers on requested machines that belong to the service with the given name or ID. If serviceNameOrID is empty, all service containers are returned.
func (*Client) ListVolumes ¶ added in v0.6.0
func (c *Client) ListVolumes(ctx context.Context, opts volume.ListOptions) ([]MachineVolumes, error)
ListVolumes returns a list of all volumes matching the filter.
func (*Client) PullImage ¶
func (c *Client) PullImage(ctx context.Context, image string, opts PullOptions) (<-chan PullImageMessage, error)
func (*Client) RemoveContainer ¶
func (c *Client) RemoveContainer(ctx context.Context, id string, opts container.RemoveOptions) error
RemoveContainer stops (kills after grace period) and removes a container with the given ID.
func (*Client) RemoveServiceContainer ¶
func (c *Client) RemoveServiceContainer(ctx context.Context, id string, opts container.RemoveOptions) error
RemoveServiceContainer stops (kills after grace period) and removes a service container with the given ID. A service container is a container that has been created with CreateServiceContainer.
func (*Client) RemoveVolume ¶ added in v0.6.0
RemoveVolume removes a volume with the given ID.
func (*Client) StartContainer ¶
StartContainer starts a container with the given ID and options.
func (*Client) StopContainer ¶
StopContainer stops a container with the given ID and options.
type Controller ¶ added in v0.11.1
type Controller struct {
// contains filtered or unexported fields
}
Controller monitors Docker events and synchronises service containers with the cluster store.
func NewController ¶ added in v0.11.1
func NewController(machineID string, service *Service, store *store.Store) *Controller
func (*Controller) Cleanup ¶ added in v0.11.1
func (c *Controller) Cleanup() error
Cleanup removes all uncloud-managed containers and the uncloud Docker network.
func (*Controller) EnsureUncloudNetwork ¶ added in v0.11.1
func (c *Controller) EnsureUncloudNetwork(ctx context.Context, subnet netip.Prefix, dnsServer netip.Addr) error
EnsureUncloudNetwork creates the Docker bridge network NetworkName with the provided machine subnet if it doesn't exist. If the network exists but has a different subnet, it removes and recreates the network. It also configures iptables to allow container access from the WireGuard network.
func (*Controller) WaitDaemonReady ¶ added in v0.11.1
func (c *Controller) WaitDaemonReady(ctx context.Context) error
WaitDaemonReady waits for the Docker daemon to start and be ready to serve requests.
func (*Controller) WatchAndSyncContainers ¶ added in v0.11.1
func (c *Controller) WatchAndSyncContainers(ctx context.Context) error
type MachineContainers ¶
type MachineContainers struct {
Metadata *pb.Metadata
Containers []types.ContainerJSON
}
type MachineServiceContainers ¶
type MachineServiceContainers struct {
Metadata *pb.Metadata
Containers []api.ServiceContainer
}
type MachineVolumes ¶ added in v0.6.0
type MachineVolumes struct {
Metadata *pb.Metadata
Response volume.ListResponse
}
MachineVolumes represents a volume list response from a machine.
type PullImageMessage ¶
type PullImageMessage struct {
Message jsonmessage.JSONMessage
Err error
}
type PullOptions ¶ added in v0.11.1
type PullOptions struct {
All bool
// RegistryAuth is the base64 encoded credentials for the registry.
RegistryAuth string
Platform string
}
PullOptions defines the options for pulling an image from a remote registry. This is a copy of image.PullOptions from the Docker API without the PrivilegeFunc field that is non-serialisable.
type Server ¶
type Server struct {
pb.UnimplementedDockerServer
// contains filtered or unexported fields
}
Server implements the gRPC Docker service that proxies requests to the Docker daemon.
func NewServer ¶
func NewServer(service *Service, db *sqlx.DB, internalDNSIP func() netip.Addr, opts ...ServerOption) *Server
NewServer creates a new Docker gRPC server with the provided Docker service.
func (*Server) CreateContainer ¶
func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerRequest) (*pb.CreateContainerResponse, error)
CreateContainer creates a new container based on the given configuration.
func (*Server) CreateServiceContainer ¶
func (s *Server) CreateServiceContainer( ctx context.Context, req *pb.CreateServiceContainerRequest, ) (*pb.CreateContainerResponse, error)
CreateServiceContainer creates a new container for the service with the given specifications. TODO: move the main logic to the Docker service and remove db dependency from the server.
func (*Server) CreateVolume ¶ added in v0.6.0
func (s *Server) CreateVolume(ctx context.Context, req *pb.CreateVolumeRequest) (*pb.CreateVolumeResponse, error)
CreateVolume creates a new volume with the given options.
func (*Server) InspectContainer ¶
func (s *Server) InspectContainer(ctx context.Context, req *pb.InspectContainerRequest) (*pb.InspectContainerResponse, error)
InspectContainer returns the container information for the given container ID.
func (*Server) InspectImage ¶
func (s *Server) InspectImage(ctx context.Context, req *pb.InspectImageRequest) (*pb.InspectImageResponse, error)
InspectImage returns the image information for the given image ID.
func (*Server) InspectRemoteImage ¶
func (s *Server) InspectRemoteImage( _ context.Context, req *pb.InspectRemoteImageRequest, ) (*pb.InspectRemoteImageResponse, error)
InspectRemoteImage returns the image metadata for an image in a remote registry using the machine's Docker auth credentials if necessary.
func (*Server) InspectServiceContainer ¶
func (s *Server) InspectServiceContainer( ctx context.Context, req *pb.InspectContainerRequest, ) (*pb.ServiceContainer, error)
InspectServiceContainer returns the container information and service specification that was used to create the container with the given ID.
func (*Server) ListContainers ¶
func (s *Server) ListContainers(ctx context.Context, req *pb.ListContainersRequest) (*pb.ListContainersResponse, error)
func (*Server) ListServiceContainers ¶
func (s *Server) ListServiceContainers( ctx context.Context, req *pb.ListServiceContainersRequest, ) (*pb.ListServiceContainersResponse, error)
ListServiceContainers returns all containers that belong to the service with the given name or ID. If req.ServiceId is empty, all service containers are returned.
func (*Server) ListVolumes ¶ added in v0.6.0
func (s *Server) ListVolumes(ctx context.Context, req *pb.ListVolumesRequest) (*pb.ListVolumesResponse, error)
ListVolumes returns a list of all volumes matching the filter.
func (*Server) PullImage ¶
func (s *Server) PullImage(req *pb.PullImageRequest, stream grpc.ServerStreamingServer[pb.JSONMessage]) error
func (*Server) RemoveContainer ¶
func (s *Server) RemoveContainer(ctx context.Context, req *pb.RemoveContainerRequest) (*emptypb.Empty, error)
RemoveContainer stops (kills after grace period) and removes a container with the given ID.
func (*Server) RemoveServiceContainer ¶
func (s *Server) RemoveServiceContainer(ctx context.Context, req *pb.RemoveContainerRequest) (*emptypb.Empty, error)
RemoveServiceContainer stops (kills after grace period) and removes a service container with the given ID. The difference between this method and RemoveContainer is that it also removes the container from the machine database.
func (*Server) RemoveVolume ¶ added in v0.6.0
func (s *Server) RemoveVolume(ctx context.Context, req *pb.RemoveVolumeRequest) (*emptypb.Empty, error)
RemoveVolume removes a volume with the given ID.
func (*Server) StartContainer ¶
func (s *Server) StartContainer(ctx context.Context, req *pb.StartContainerRequest) (*emptypb.Empty, error)
StartContainer starts a container with the given ID and options.
func (*Server) StopContainer ¶
func (s *Server) StopContainer(ctx context.Context, req *pb.StopContainerRequest) (*emptypb.Empty, error)
StopContainer stops a container with the given ID and options.
type ServerOption ¶ added in v0.10.0
type ServerOption func(*Server)
ServerOption configures the Docker server.
func WithNetworkReady ¶ added in v0.10.0
func WithNetworkReady(networkReady func() bool) ServerOption
WithNetworkReady sets the network readiness check function.
func WithWaitForNetworkReady ¶ added in v0.10.0
func WithWaitForNetworkReady(waitForNetworkReady func(ctx context.Context) error) ServerOption
WithWaitForNetworkReady sets the network readiness wait function.
type Service ¶ added in v0.11.1
Service provides higher-level Docker operations that extends Docker API with Uncloud-specific data from the machine database.
func NewService ¶ added in v0.11.1
NewService creates a new Docker service instance.
func (*Service) InspectServiceContainer ¶ added in v0.11.1
func (s *Service) InspectServiceContainer(ctx context.Context, nameOrID string) (api.ServiceContainer, error)
InspectServiceContainer inspects a Docker container and retrieves its associated ServiceSpec from the machine database, returning a complete ServiceContainer.
func (*Service) ListServiceContainers ¶ added in v0.11.1
func (s *Service) ListServiceContainers( ctx context.Context, serviceNameOrID string, opts container.ListOptions, ) ([]api.ServiceContainer, error)
ListServiceContainers lists Docker containers that belong to the service with the given name or ID. If serviceIDOrName is empty, all service containers are returned. The opts parameter allows additional filtering.