Skip to content

Commit

Permalink
fix(controller): provision zfs volume if zfs volume already exists
Browse files Browse the repository at this point in the history
Signed-off-by: AChangFeng <1048243380@qq.com>
  • Loading branch information
AChangFeng committed Aug 8, 2024
1 parent 3854ec2 commit b5abeb5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/zfs/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,9 @@ func GetUserFinalizers(finalizers []string) []string {

// IsVolumeReady returns true if volume is Ready
func IsVolumeReady(vol *apis.ZFSVolume) bool {

if vol.Status.State == ZFSStatusReady {
return true
if vol.Status.State != "" {
// For newer volumes, we only check the Status
return vol.Status.State == ZFSStatusReady
}

// For older volumes, there was no Status field
Expand All @@ -429,5 +429,6 @@ func IsVolumeReady(vol *apis.ZFSVolume) bool {
return true
}
}

return false
}
40 changes: 40 additions & 0 deletions pkg/zfs/volume_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package zfs

import (
"testing"

apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/zfs/v1"
)

func TestIsVolumeReady(t *testing.T) {
volGen := func(finalizer string, state string) *apis.ZFSVolume {
vol := &apis.ZFSVolume{}
if finalizer != "" {
vol.Finalizers = append(vol.Finalizers, finalizer)
}
if state != "" {
vol.Status.State = state
}
return vol
}
tests := []struct {
name string
volFinalizer string
volState string
want bool
}{
{"Older volume is ready", ZFSFinalizer, "", true},
{"Older volume is not ready", "", "", false},
{"Newer volume is pending", "", ZFSStatusPending, false},
{"Newer volume is pending with finalizer", ZFSFinalizer, ZFSStatusPending, false},
{"Newer volume is ready with finalizer", ZFSFinalizer, ZFSStatusReady, true},
{"Newer volume is failed", "", ZFSStatusFailed, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsVolumeReady(volGen(tt.volFinalizer, tt.volState)); got != tt.want {
t.Errorf("IsVolumeReady() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit b5abeb5

Please sign in to comment.