From d08029ab050c6242386ba67ad2cdf9faf138b964 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 --- 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