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) ExecContainer(ctx context.Context, opts ExecConfig) (exitCode int, err error)
- func (c *Client) InspectContainer(ctx context.Context, id string) (container.InspectResponse, 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 docker.PullPushImageMessage, 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 ContainerLogsOptions
- type Controller
- type ExecConfig
- type Images
- type MachineContainers
- type MachineServiceContainers
- type MachineVolumes
- type PullOptions
- type Server
- func (s *Server) ContainerLogs(req *pb.ContainerLogsRequest, ...) error
- 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) ExecContainer(stream pb.Docker_ExecContainerServer) 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) ListImages(ctx context.Context, req *pb.ListImagesRequest) (*pb.ListImagesResponse, 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 ServerOptions
- type Service
- func (s *Service) ContainerLogs(ctx context.Context, opts ContainerLogsOptions) (<-chan api.ContainerLogEntry, error)
- func (s *Service) InspectServiceContainer(ctx context.Context, nameOrID string) (api.ServiceContainer, error)
- func (s *Service) IsContainerdImageStoreEnabled(ctx context.Context) (bool, error)
- func (s *Service) ListImages(ctx context.Context, opts image.ListOptions) (Images, error)
- func (s *Service) ListServiceContainers(ctx context.Context, serviceNameOrID string, opts container.ListOptions) ([]api.ServiceContainer, error)
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 {
GRPCClient pb.DockerClient
// contains filtered or unexported fields
}
Client is a gRPC client for the Docker service that provides a similar interface to the Docker HTTP client. TODO: it doesn't seem there is much value in having this intermediate Docker client. Consider merging it into the main pkg/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) ExecContainer ¶ added in v0.14.0
ExecContainer executes a command in a running container with bidirectional streaming. TODO: This can be merged with pkg/client as it's an unnecessary logic split.
func (*Client) InspectContainer ¶
func (c *Client) InspectContainer(ctx context.Context, id string) (container.InspectResponse, error)
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)
func (*Client) PullImage ¶
func (c *Client) PullImage(ctx context.Context, image string, opts PullOptions) (<-chan docker.PullPushImageMessage, 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 ContainerLogsOptions ¶ added in v0.15.0
type ContainerLogsOptions struct {
ContainerID string
Follow bool
Tail int
Since string
Until string
}
ContainerLogsOptions specifies parameters for ContainerLogs.
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 ExecConfig ¶ added in v0.14.0
type ExecConfig struct {
// Container ID to execute the command in.
ContainerID string
// Exec configuration.
Options api.ExecOptions
}
ExecConfig contains options for executing a command in a container.
type MachineContainers ¶
type MachineContainers struct {
Metadata *pb.Metadata
Containers []container.InspectResponse
}
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
}
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, machineID func() string, opts ServerOptions) *Server
NewServer creates a new Docker gRPC server with the provided Docker service.
func (*Server) ContainerLogs ¶ added in v0.15.0
func (s *Server) ContainerLogs( req *pb.ContainerLogsRequest, stream grpc.ServerStreamingServer[pb.ContainerLogEntry], ) error
ContainerLogs streams logs from a container.
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) ExecContainer ¶ added in v0.14.0
func (s *Server) ExecContainer(stream pb.Docker_ExecContainerServer) error
ExecContainer executes a command in a running container with bidirectional streaming for stdin/stdout/stderr.
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) ListImages ¶ added in v0.13.0
func (s *Server) ListImages(ctx context.Context, req *pb.ListImagesRequest) (*pb.ListImagesResponse, error)
ListImages returns a list of all images matching the filter and indicates whether Docker is using the containerd image store.
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 ServerOptions ¶ added in v0.13.0
type ServerOptions struct {
// TODO: verify if we still need the network readiness checks as the cluster controller ensures the network
// is ready before starting the network API server. It may still be needed when communicating with the local
// API server but in this case we should probably fail until the cluster is initialised.
NetworkReady func() bool
WaitForNetworkReady func(ctx context.Context) error
}
type Service ¶ added in v0.11.1
type Service struct {
// Client is a Docker client for managing Docker resources.
Client *client.Client
// contains filtered or unexported fields
}
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) ContainerLogs ¶ added in v0.15.0
func (s *Service) ContainerLogs(ctx context.Context, opts ContainerLogsOptions) (<-chan api.ContainerLogEntry, error)
ContainerLogs streams logs from a container and returns demultiplexed entries via a channel. The channel is closed when streaming completes or context is cancelled.
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) IsContainerdImageStoreEnabled ¶ added in v0.13.0
IsContainerdImageStoreEnabled checks if Docker is configured to use the containerd image store: https://docs.docker.com/engine/storage/containerd/
func (*Service) ListImages ¶ added in v0.13.0
ListImages lists Docker images with the given options and indicates whether Docker is using the containerd image store. It always includes image manifests in the response if the store is containerd.
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.