Skip to content
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 refactoring #2907

Merged
merged 4 commits into from
Dec 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .revive.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ warningCode = 0
[rule.increment-decrement]
[rule.var-naming]
[rule.var-declaration]
[rule.package-comments]
#[rule.package-comments]
[rule.range]
[rule.receiver-naming]
[rule.time-naming]
Expand Down
6 changes: 6 additions & 0 deletions pkg/pillar/cas/cas.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"strings"

"github.com/lf-edge/edge-containers/pkg/resolver"
"github.com/lf-edge/eve/pkg/pillar/types"
Expand Down Expand Up @@ -147,6 +148,11 @@ var knownCASHandlers = map[string]casDesc{
"containerd": {constructor: newContainerdCAS},
}

// CheckAndCorrectBlobHash checks if the blobHash has hash algo sha256 as prefix. If not then it'll prepend it.
func CheckAndCorrectBlobHash(blobHash string) string {
return fmt.Sprintf("sha256:%s", strings.TrimPrefix(blobHash, "sha256:"))
}

// NewCAS returns new CAS object with a new client of underlying implementor(selectedCAS).
// It's the caller/user's responsibility to close the respective client after use by calling CAS.CloseClient().
func NewCAS(selectedCAS string) (CAS, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/pillar/cmd/domainmgr/domainmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -1455,8 +1455,8 @@ func doActivate(ctx *domainContext, config types.DomainConfig,
}
default:
// assume everything else to be disk formats
_, _, format, _, err := utils.GetVolumeSize(log, ctx.casClient, ds.FileLocation)
if err == nil && format != strings.ToLower(ds.Format.String()) {
format, err := utils.GetVolumeFormat(log, ds.FileLocation)
if err == nil && format != ds.Format {
err = fmt.Errorf("Disk format mismatch, format in config %v and output of qemu-img/zfs get %v\n"+
"Note: Format mismatch may be because of disk corruption also.",
ds.Format, format)
Expand Down
3 changes: 1 addition & 2 deletions pkg/pillar/cmd/volumemgr/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ func getManifestsForBareBlob(ctx *volumemgrContext, image, rootHash string, size
}

//Adding config blob to blobStatuses list
configBlobStatus := lookupBlobStatus(ctx,
strings.Replace(desc[0].Digest.String(), "sha256:", "", 1))
configBlobStatus := ctx.LookupBlobStatus(strings.Replace(desc[0].Digest.String(), "sha256:", "", 1))
if configBlobStatus != nil {
blobStatuses = append(blobStatuses, configBlobStatus)
}
Expand Down
18 changes: 6 additions & 12 deletions pkg/pillar/cmd/volumemgr/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,13 @@ func resolveManifestSize(ctx *volumemgrContext, blob types.BlobStatus) int64 {
return size
}

// lookupBlobStatus look for a BlobStatus. Does not attempt to recreate one
// LookupBlobStatus look for a BlobStatus. Does not attempt to recreate one
// from VerifyImageStatus
func lookupBlobStatus(ctx *volumemgrContext, blobSha string) *types.BlobStatus {

func (ctxPtr *volumemgrContext) LookupBlobStatus(blobSha string) *types.BlobStatus {
if blobSha == "" {
return nil
}
pub := ctx.pubBlobStatus
pub := ctxPtr.pubBlobStatus
s, _ := pub.Get(blobSha)
if s == nil {
log.Tracef("lookupBlobStatus(%s) not found", blobSha)
Expand All @@ -407,7 +406,7 @@ func lookupOrCreateBlobStatus(ctx *volumemgrContext, blobSha string) *types.Blob
return nil
}
// Does it already exist?
blob := lookupBlobStatus(ctx, blobSha)
blob := ctx.LookupBlobStatus(blobSha)
if blob != nil {
return blob
}
Expand Down Expand Up @@ -494,7 +493,7 @@ func unpublishBlobStatus(ctx *volumemgrContext, blobs ...*types.BlobStatus) {
}
//If blob is loaded, then remove it from CAS
if blob.State == types.LOADED {
if err := ctx.casClient.RemoveBlob(checkAndCorrectBlobHash(blob.Sha256)); err != nil {
if err := ctx.casClient.RemoveBlob(cas.CheckAndCorrectBlobHash(blob.Sha256)); err != nil {
err := fmt.Errorf("unpublishBlobStatus: Exception while removing loaded blob %s: %s",
blob.Sha256, err.Error())
log.Errorf(err.Error())
Expand Down Expand Up @@ -537,7 +536,7 @@ func populateInitBlobStatus(ctx *volumemgrContext) {
log.Functionf("populateInitBlobStatus: blob %s in CAS could not get mediaType", blobInfo.Digest)
continue
}
if lookupBlobStatus(ctx, blobInfo.Digest) == nil {
if ctx.LookupBlobStatus(blobInfo.Digest) == nil {
log.Functionf("populateInitBlobStatus: Found blob %s in CAS", blobInfo.Digest)
blobStatus := &types.BlobStatus{
Sha256: strings.TrimPrefix(blobInfo.Digest, "sha256:"),
Expand Down Expand Up @@ -608,11 +607,6 @@ func gcImagesFromCAS(ctx *volumemgrContext) {
}
}

// checkAndCorrectBlobHash checks if the blobHash has hash algo sha256 as prefix. If not then it'll prepend it.
func checkAndCorrectBlobHash(blobHash string) string {
return fmt.Sprintf("sha256:%s", strings.TrimPrefix(blobHash, "sha256:"))
}

// lookupImageCAS check if an image reference exists
func lookupImageCAS(reference string, client cas.CAS) bool {
hash, err := client.GetImageHash(reference)
Expand Down
Loading