-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Volumemgr support for kubevirt eve #3768
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package cas | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is missing Copyright and license lines. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestWriteKubevirtMountpointsFile(t *testing.T) { | ||
cas := containerdCAS{} | ||
mountPoints := map[string]struct{}{ | ||
"/media/floppy": {}, | ||
"/media/cdrom": {}, | ||
} | ||
|
||
dname, err := os.MkdirTemp("", "prefix") | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = cas.writeKubevirtMountpointsFile(mountPoints, dname) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
contentBytes, err := os.ReadFile(filepath.Join(dname, "mountPoints")) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
content := string(contentBytes) | ||
|
||
for mountPoint := range mountPoints { | ||
if !strings.Contains(content, mountPoint) { | ||
t.Fatalf("mountPoint %s is missing", mountPoint) | ||
} | ||
} | ||
|
||
os.RemoveAll(filepath.Join(dname, "mountPoints")) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import ( | |
"strings" | ||
|
||
zconfig "github.com/lf-edge/eve-api/go/config" | ||
"github.com/lf-edge/eve/pkg/pillar/kubeapi" | ||
"github.com/lf-edge/eve/pkg/pillar/types" | ||
"github.com/lf-edge/eve/pkg/pillar/volumehandlers" | ||
"github.com/lf-edge/eve/pkg/pillar/zfs" | ||
|
@@ -66,6 +67,28 @@ func populateExistingVolumesFormatDatasets(_ *volumemgrContext, dataset string) | |
log.Functionf("populateExistingVolumesFormatDatasets(%s) Done", dataset) | ||
} | ||
|
||
// populateExistingVolumesFormatPVC iterates over the namespace and takes format | ||
// from the name of the volume/PVC and prepares map of it | ||
func populateExistingVolumesFormatPVC(_ *volumemgrContext) { | ||
|
||
log.Functionf("populateExistingVolumesFormatPVC") | ||
pvlist, err := kubeapi.GetPVCList(log) | ||
if err != nil { | ||
log.Errorf("populateExistingVolumesFormatPVC: GetPVCList failed: %v", err) | ||
return | ||
} | ||
for _, pvcName := range pvlist { | ||
tempStatus, err := getVolumeStatusByPVC(pvcName) | ||
if err != nil { | ||
log.Error(err) | ||
continue | ||
} | ||
volumeFormat[tempStatus.Key()] = tempStatus.ContentFormat | ||
} | ||
log.Functionf("populateExistingVolumesFormatPVC Done") | ||
|
||
} | ||
|
||
// Periodic garbage collection looking at RefCount=0 files in the unknown | ||
// Others have their delete handler. | ||
func gcObjects(ctx *volumemgrContext, dirName string) { | ||
|
@@ -117,6 +140,38 @@ func gcVolumes(ctx *volumemgrContext, locations []string) { | |
} | ||
} | ||
|
||
func getVolumeStatusByPVC(pvcName string) (*types.VolumeStatus, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about adding a comment that this is the reverse of the PVCName function you added? That would be helpful for a reader. |
||
var encrypted bool | ||
var parsedFormat int32 | ||
var volumeIDAndGeneration string | ||
|
||
volumeIDAndGeneration = pvcName | ||
parsedFormat = int32(zconfig.Format_PVC) | ||
|
||
generation := strings.Split(volumeIDAndGeneration, "-pvc-") | ||
volUUID, err := uuid.FromString(generation[0]) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to parse VolumeID: %s", err) | ||
} | ||
if len(generation) == 1 { | ||
return nil, fmt.Errorf("cannot extract generation from PVC %s", pvcName) | ||
} | ||
// we cannot extract LocalGenerationCounter from the PVC name | ||
// assume it is zero | ||
generationCounter, err := strconv.ParseInt(generation[1], 10, 64) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to parse GenerationCounter: %s", err) | ||
} | ||
vs := types.VolumeStatus{ | ||
VolumeID: volUUID, | ||
Encrypted: encrypted, | ||
GenerationCounter: generationCounter, | ||
ContentFormat: zconfig.Format(parsedFormat), | ||
FileLocation: pvcName, | ||
} | ||
return &vs, nil | ||
} | ||
|
||
func getVolumeStatusByLocation(location string) (*types.VolumeStatus, error) { | ||
var encrypted bool | ||
var parsedFormat int32 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a unit test that failing without the kubevirt tag?
If so, we should put it under
//go:build kubevirt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that I know of. This code is given by @christoph-zededa I just used it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no go test that is failing without the kubevirt tag.
There are two reasons I've put it there:
kubevirt
build flag