chore(volumes): add client methods for volume management, e2e test

This commit is contained in:
Pavel Sviderski
2025-04-10 13:50:08 +10:00
parent c6205d4f57
commit df4ab40e12
11 changed files with 286 additions and 89 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ type ImageClient interface {
type MachineClient interface {
InspectMachine(ctx context.Context, id string) (*pb.MachineMember, error)
ListMachines(ctx context.Context) ([]*pb.MachineMember, error)
ListMachines(ctx context.Context) (MachineMembersList, error)
}
type ServiceClient interface {
-5
View File
@@ -110,11 +110,6 @@ type ServiceContainer struct {
ServiceSpec ServiceSpec
}
type MachineContainer struct {
MachineID string
Container Container
}
// ServiceID returns the ID of the service this container belongs to.
func (c *ServiceContainer) ServiceID() string {
return c.Config.Labels[LabelServiceID]
+20
View File
@@ -0,0 +1,20 @@
package api
import "github.com/psviderski/uncloud/internal/machine/api/pb"
type MachineMembersList []*pb.MachineMember
func (m MachineMembersList) FindByManagementIP(ip string) *pb.MachineMember {
for _, machine := range m {
addr, err := machine.Machine.Network.ManagementIp.ToAddr()
if err != nil {
continue
}
if addr.String() == ip {
return machine
}
}
return nil
}
+13
View File
@@ -7,6 +7,7 @@ import (
"strings"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/volume"
)
const (
@@ -43,6 +44,8 @@ type BindOptions struct {
// VolumeOptions represents options for a managed volume.
type VolumeOptions struct {
// Driver specifies the volume driver and its options for volume creation.
// TODO: It seems we don't really need Driver and Labels if we only support externally managed volumes.
// However we may need them in the future if we add support for isolated container-scoped volumes.
Driver *mount.Driver `json:",omitempty"`
// Labels are key-value metadata to apply to the volume if creating a new volume.
Labels map[string]string `json:",omitempty"`
@@ -182,3 +185,13 @@ func sortVolumeMounts(mounts []VolumeMount) {
return false
})
}
// MachineVolume represents a volume on a specific machine.
type MachineVolume struct {
// MachineID is the ID of the machine where the volume exists.
MachineID string
// MachineName is the name of the machine where the volume exists.
MachineName string
// Volume is the Docker volume model.
Volume volume.Volume
}