|
9 | 9 | "net" |
10 | 10 | "os" |
11 | 11 | "strings" |
12 | | - "time" |
13 | 12 |
|
14 | | - "github.com/digitalocean/go-qemu/qmp" |
15 | 13 | "github.com/go-logr/logr" |
16 | 14 | "github.com/ironcore-dev/cloud-hypervisor-provider/api" |
17 | 15 | "github.com/ironcore-dev/cloud-hypervisor-provider/internal/host" |
@@ -44,47 +42,24 @@ type validatedVolume struct { |
44 | 42 | encryptionKey *string |
45 | 43 | } |
46 | 44 |
|
47 | | -type Provider interface { |
| 45 | +type backend interface { |
| 46 | + VolumeType() api.VolumeType |
48 | 47 | Mount(ctx context.Context, machineID string, volume *validatedVolume) (string, error) |
49 | 48 | Unmount(ctx context.Context, machineID string, volumeID string) error |
50 | 49 | } |
51 | 50 |
|
52 | | -func QMPProvider(ctx context.Context, log logr.Logger, paths host.Paths, socket string) (Provider, error) { |
53 | | - monitor, err := qmp.NewSocketMonitor("unix", socket, 2*time.Second) |
54 | | - if err != nil { |
55 | | - return nil, fmt.Errorf("failed to connect to qmp monitor: %w", err) |
56 | | - } |
57 | | - |
58 | | - go func() { |
59 | | - // TODO |
60 | | - _ = monitor.Connect() |
61 | | - defer func() { |
62 | | - // TODO |
63 | | - _ = monitor.Disconnect() |
64 | | - }() |
65 | | - |
66 | | - stream, _ := monitor.Events(ctx) |
67 | | - for e := range stream { |
68 | | - log.V(1).Info(fmt.Sprintf("EVENT: %s", e.Event)) |
69 | | - } |
70 | | - }() |
71 | | - |
72 | | - return &QMP{ |
73 | | - log: log, |
74 | | - paths: paths, |
75 | | - monitor: monitor, |
76 | | - }, nil |
| 51 | +// NewRBDPlugin creates a volume.Plugin backed by host-level rbd map/unmap. |
| 52 | +func NewRBDPlugin(log logr.Logger, paths host.Paths) volume.Plugin { |
| 53 | + return newPlugin(newRBDProvider(log, paths)) |
77 | 54 | } |
78 | 55 |
|
79 | 56 | type plugin struct { |
80 | | - provider Provider |
81 | | - host volume.Host |
| 57 | + be backend |
| 58 | + host volume.Host |
82 | 59 | } |
83 | 60 |
|
84 | | -func NewPlugin(provider Provider) volume.Plugin { |
85 | | - return &plugin{ |
86 | | - provider: provider, |
87 | | - } |
| 61 | +func newPlugin(be backend) volume.Plugin { |
| 62 | + return &plugin{be: be} |
88 | 63 | } |
89 | 64 |
|
90 | 65 | func (p *plugin) Init(host volume.Host) error { |
@@ -181,14 +156,14 @@ func (p *plugin) Apply(ctx context.Context, spec *api.VolumeSpec, machineID stri |
181 | 156 | return nil, fmt.Errorf("failed to get volume data: %w", err) |
182 | 157 | } |
183 | 158 |
|
184 | | - path, err := p.provider.Mount(ctx, machineID, volumeData) |
| 159 | + path, err := p.be.Mount(ctx, machineID, volumeData) |
185 | 160 | if err != nil { |
186 | 161 | return nil, fmt.Errorf("failed to mount volume: %w", err) |
187 | 162 | } |
188 | 163 |
|
189 | 164 | return &api.VolumeStatus{ |
190 | 165 | Name: spec.Name, |
191 | | - Type: api.VolumeSocketType, |
| 166 | + Type: p.be.VolumeType(), |
192 | 167 | Path: path, |
193 | 168 | Handle: volumeData.handle, |
194 | 169 | State: api.VolumeStatePrepared, |
@@ -238,7 +213,7 @@ func (p *plugin) validateVolume(spec *api.VolumeSpec) (vData *validatedVolume, e |
238 | 213 | } |
239 | 214 |
|
240 | 215 | func (p *plugin) Delete(ctx context.Context, computeVolumeName string, machineID string) error { |
241 | | - if err := p.provider.Unmount(ctx, machineID, computeVolumeName); err != nil { |
| 216 | + if err := p.be.Unmount(ctx, machineID, computeVolumeName); err != nil { |
242 | 217 | return fmt.Errorf("failed to unmount volume %q: %w", computeVolumeName, err) |
243 | 218 | } |
244 | 219 |
|
|
0 commit comments