Skip to content

Commit 4c8fbfc

Browse files
Fix RBD connection handling in Volume resize (#444)
Co-authored-by: [email protected] <[email protected]>
1 parent db33d91 commit 4c8fbfc

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

internal/controllers/machine_controller.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,13 @@ func (r *MachineReconciler) Start(ctx context.Context) error {
221221
}
222222

223223
func (r *MachineReconciler) startCheckAndEnqueueVolumeResize(ctx context.Context, log logr.Logger) {
224+
if r.resyncIntervalVolumeSize == 0 {
225+
log.V(1).Info("volume resize trigger loop is disabled")
226+
return
227+
}
228+
224229
wait.UntilWithContext(ctx, func(ctx context.Context) {
230+
log.V(1).Info("starting volume resize trigger loop")
225231
machines, err := r.machines.List(ctx)
226232
if err != nil {
227233
log.Error(err, "failed to list machines")
@@ -306,6 +312,7 @@ func (r *MachineReconciler) startEnqueueMachineByLibvirtEvent(ctx context.Contex
306312

307313
func (r *MachineReconciler) startGarbageCollector(ctx context.Context, log logr.Logger) {
308314
wait.UntilWithContext(ctx, func(ctx context.Context) {
315+
log.V(1).Info("starting garbage-collector loop")
309316
machines, err := r.machines.List(ctx)
310317
if err != nil {
311318
log.Error(err, "failed to list machines")

internal/plugins/volume/ceph/size.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func connectToRados(ctx context.Context, monitors, user, keyfile string) (*rados
4141
if err != nil {
4242
return nil, fmt.Errorf("creating a new connection failed: %w", err)
4343
}
44+
4445
err = conn.ParseCmdLineArgs(args)
4546
if err != nil {
4647
return nil, fmt.Errorf("parsing cmdline args (%v) failed: %w", args, err)
@@ -108,13 +109,15 @@ func (p *plugin) GetSize(ctx context.Context, spec *api.VolumeSpec) (int64, erro
108109
if err != nil {
109110
return 0, fmt.Errorf("failed to open connection: %w", err)
110111
}
112+
defer conn.Shutdown()
111113

112114
ioCtx, err := conn.OpenIOContext(poolName)
113115
if err != nil {
114116
return 0, fmt.Errorf("failed to open io context: %w", err)
115117
}
118+
defer ioCtx.Destroy()
116119

117-
image, err := rbd.OpenImage(ioCtx, imageName, rbd.NoSnapshot)
120+
image, err := rbd.OpenImageReadOnly(ioCtx, imageName, rbd.NoSnapshot)
118121
if err != nil {
119122
return 0, fmt.Errorf("failed to open image: %w", err)
120123
}

0 commit comments

Comments
 (0)