From 93aa99ca5c874e4116bd0ff57569294501b30ee0 Mon Sep 17 00:00:00 2001 From: Tim Serong Date: Thu, 10 Oct 2024 16:34:14 +1100 Subject: [PATCH] fix: set LHv2 DiskDriver to "auto" if unset We need to force DiskDriver to "auto" if it's not explicitly set, because Longhorn also does that internally. If we don't do this, the subsequent reflect.DeepEqual() in LonghornV2Provisioner.Update() will always fail because we have an empty string, but the LHN CR will have it set to "auto" which results in a weird resync loop. Related issue: https://github.com/harvester/harvester/issues/6709 Signed-off-by: Tim Serong (cherry picked from commit 09e26bc26c561a6a0e06198f7087f768188bb231) --- pkg/provisioner/longhornv2.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/provisioner/longhornv2.go b/pkg/provisioner/longhornv2.go index c842fb24..2b7dee9d 100644 --- a/pkg/provisioner/longhornv2.go +++ b/pkg/provisioner/longhornv2.go @@ -30,6 +30,14 @@ func NewLHV2Provisioner( if !cacheDiskTags.Initialized() { return nil, errors.New(ErrorCacheDiskTagsNotInitialized) } + if device.Spec.Provisioner.Longhorn.DiskDriver == longhornv1.DiskDriverNone { + // We need to force DiskDriver to "auto" if it's not explicitly set, + // because Longhorn also does that internally. If we don't do it + // here, the subsequent reflect.DeepEqual() in our Update() function + // will always fail because we have an empty string, but the LHN CR + // has it set to "auto" which results in a weird resync loop. + device.Spec.Provisioner.Longhorn.DiskDriver = longhornv1.DiskDriverAuto + } baseProvisioner := &provisioner{ name: TypeLonghornV2, blockInfo: block, @@ -85,9 +93,6 @@ func (p *LonghornV2Provisioner) Provision() (isRequeueNeeded bool, err error) { return false, err } - // If diskDriver is an empty string, longhorn will map that to "auto" internally - diskDriver := p.device.Spec.Provisioner.Longhorn.DiskDriver - diskSpec := longhornv1.DiskSpec{ Type: longhornv1.DiskTypeBlock, Path: devPath, @@ -95,7 +100,7 @@ func (p *LonghornV2Provisioner) Provision() (isRequeueNeeded bool, err error) { EvictionRequested: false, StorageReserved: 0, Tags: tags, - DiskDriver: diskDriver, + DiskDriver: p.device.Spec.Provisioner.Longhorn.DiskDriver, } // We're intentionally not trying to sync disk tags from longhorn if the