Skip to content

Commit

Permalink
Cleanup volumemgr code
Browse files Browse the repository at this point in the history
Set docker.io prefix for containers in ReferenceID() call.
Delete from all other places where docker.io prefix is set.
Update volrefstatus with ReferenceName from volumestatus.
Rebase to master and fixed Makefile conflict
Updated pkg/pillar/Makefile to add -tags kubevirt
Tested regression suite to make sure nothing is broken

Signed-off-by: Pramodh Pallapothu <pramodh@zededa.com>
  • Loading branch information
Pramodh Pallapothu committed Mar 15, 2024
1 parent dcac663 commit 4cf603b
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 42 deletions.
2 changes: 1 addition & 1 deletion pkg/pillar/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ test: build-docker-test
--entrypoint /final/opt/gotestsum $(DOCKER_TAG) \
--jsonfile /pillar/results.json \
--junitfile /pillar/results.xml \
--raw-command -- go test -coverprofile=coverage.txt -covermode=atomic -race -json \
--raw-command -- go test -tags kubevirt -coverprofile=coverage.txt -covermode=atomic -race -json \
./...
docker run --platform linux/$(ZARCH) -w /pillar \
--entrypoint /bin/sh $(DOCKER_TAG) \
Expand Down
4 changes: 0 additions & 4 deletions pkg/pillar/cmd/volumemgr/handlecontent.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,6 @@ func doDeleteContentTree(ctx *volumemgrContext, status *types.ContentTreeStatus)
RemoveAllBlobsFromContentTreeStatus(ctx, status, status.Blobs...)
//We create a reference when we load the blobs. We should remove that reference when we delete the contentTree.
refName := status.ReferenceID()
if ctx.hvTypeKube && status.IsContainer() {
refName = types.KubeContainerImagePrefix + refName
log.Functionf("doDeleteContentTree: oci image %v", refName)
}
if err := ctx.casClient.RemoveImage(refName); err != nil {
log.Errorf("doDeleteContentTree: exception while deleting image %s: %s",
status.RelativeURL, err.Error())
Expand Down
21 changes: 0 additions & 21 deletions pkg/pillar/cmd/volumemgr/handlevolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package volumemgr

import (
"fmt"
"strings"
"time"

"github.com/lf-edge/eve/pkg/pillar/types"
Expand Down Expand Up @@ -193,26 +192,6 @@ func publishVolumeStatus(ctx *volumemgrContext,
status *types.VolumeStatus) {

key := status.Key()
if ctx.hvTypeKube {
vrStatus := lookupVolumeRefStatus(ctx, key)
sub := ctx.pubContentTreeStatus
items := sub.GetAll()
reference := ""
for _, item := range items {
cts := item.(types.ContentTreeStatus)
if status.ContentID.String() == cts.ContentID.String() && cts.IsContainer() {
reference = cts.ReferenceID()
break
}
}
if vrStatus != nil && reference != "" {
if !strings.HasPrefix(vrStatus.ReferenceName, types.KubeContainerImagePrefix) && vrStatus.IsContainer() {
vrStatus.ReferenceName = types.KubeContainerImagePrefix + reference
log.Functionf("publishVolumeStatus: sync reference name %s", vrStatus.ReferenceName)
publishVolumeRefStatus(ctx, vrStatus)
}
}
}
log.Tracef("publishVolumeStatus(%s)", key)
pub := ctx.pubVolumeStatus
pub.Publish(key, *status)
Expand Down
3 changes: 3 additions & 0 deletions pkg/pillar/cmd/volumemgr/handlevolumeref.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func handleVolumeRefCreate(ctxArg interface{}, key string,
VerifyOnly: config.VerifyOnly,
Target: vs.Target,
CustomMeta: vs.CustomMeta,
ReferenceName: vs.ReferenceName,
}
if vs.HasError() {
description := vs.ErrorDescription
Expand Down Expand Up @@ -187,6 +188,7 @@ func updateVolumeRefStatus(ctx *volumemgrContext, vs *types.VolumeStatus) {
status.Target = vs.Target
status.CustomMeta = vs.CustomMeta
status.WWN = vs.WWN
status.ReferenceName = vs.ReferenceName
if vs.HasError() {
description := vs.ErrorDescription
description.ErrorEntities = []*types.ErrorEntity{{
Expand Down Expand Up @@ -215,6 +217,7 @@ func updateVolumeRefStatus(ctx *volumemgrContext, vs *types.VolumeStatus) {
WWN: vs.WWN,
VerifyOnly: config.VerifyOnly,
Target: vs.Target,
ReferenceName: vs.ReferenceName,
}
if vs.HasError() {
description := vs.ErrorDescription
Expand Down
3 changes: 0 additions & 3 deletions pkg/pillar/cmd/volumemgr/handlework.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,6 @@ func casIngestWorker(ctxPtr interface{}, w worker.Work) worker.WorkResult {
}

appImgName := status.ReferenceID()
if ctx.hvTypeKube && status.IsContainer() {
appImgName = types.KubeContainerImagePrefix + appImgName
}

// load the blobs
loadedBlobs, err := ctx.casClient.IngestBlobsAndCreateImage(appImgName, *root, loadBlobs...)
Expand Down
10 changes: 0 additions & 10 deletions pkg/pillar/cmd/volumemgr/updatestatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,6 @@ func doUpdateContentTree(ctx *volumemgrContext, status *types.ContentTreeStatus)

// check if the image was created
imgName := status.ReferenceID()
if ctx.hvTypeKube && status.IsContainer() {
imgName = types.KubeContainerImagePrefix + imgName
}
if !lookupImageCAS(imgName, ctx.casClient) {
log.Functionf("doUpdateContentTree(%s): image does not yet exist in CAS", status.Key())
return changed, false
Expand Down Expand Up @@ -604,13 +601,6 @@ func doUpdateVol(ctx *volumemgrContext, status *types.VolumeStatus) (bool, bool)
status.SubState == types.VolumeSubStateInitial {

imgName := ctStatus.ReferenceID()
if ctx.hvTypeKube {
cfg := lookupContentTreeConfig(ctx, status.ContentID.String())
if cfg != nil && ctStatus.IsContainer() {
imgName = types.KubeContainerImagePrefix + imgName
log.Functionf("doUpdateVol:reference name %v", imgName)
}
}
_, err := ctx.casClient.GetImageHash(imgName)
if err != nil {
log.Functionf("doUpdateVol(%s): waiting for image create: %s", status.Key(), err.Error())
Expand Down
7 changes: 7 additions & 0 deletions pkg/pillar/types/contenttreetypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (
uuid "github.com/satori/go.uuid"
)

// Container Image prefix adding to kubevirt container image name

Check failure on line 17 in pkg/pillar/types/contenttreetypes.go

View workflow job for this annotation

GitHub Actions / yetus

revive: comment on exported const KubeContainerImagePrefix should be of the form "KubeContainerImagePrefix ..." https://revive.run/r#exported
const KubeContainerImagePrefix = "docker.io/"

// ContentTreeConfig specifies the needed information for content tree
// which might need to be downloaded and verified
type ContentTreeConfig struct {
Expand Down Expand Up @@ -157,6 +160,10 @@ func (status ContentTreeStatus) IsContainer() bool {

// ReferenceID get the image reference ID
func (status ContentTreeStatus) ReferenceID() string {

if base.IsHVTypeKube() && status.IsContainer() {
return fmt.Sprintf("%s%s-%s", KubeContainerImagePrefix, status.ContentID.String(), status.RelativeURL)
}
return fmt.Sprintf("%s-%s", status.ContentID.String(), status.RelativeURL)
}

Expand Down
3 changes: 0 additions & 3 deletions pkg/pillar/types/locationconsts.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ const (

// ContainerdContentDir - path to containerd`s content store
ContainerdContentDir = SealedDirName + "/containerd/io.containerd.content.v1.content"

// KubeContainerImagePrefix - Container Image prefix adding to kubevirt container image name
KubeContainerImagePrefix = "docker.io/"
)

var (
Expand Down
2 changes: 2 additions & 0 deletions pkg/pillar/types/volumetypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ func (status VolumeStatus) PathName() string {
}

// PVCName returns the volume name for kubernetes(longhorn)

Check failure on line 171 in pkg/pillar/types/volumetypes.go

View workflow job for this annotation

GitHub Actions / yetus

revive: comment on exported method VolumeStatus.GetPVCName should be of the form "GetPVCName ..." https://revive.run/r#exported
// Kubernetes does not allow special characters like '#' in the object names.
// so we need to generate a PVC name.
func (status VolumeStatus) GetPVCName() string {
return fmt.Sprintf("%s-pvc-%d", status.VolumeID.String(),
status.GenerationCounter+status.LocalGenerationCounter)
Expand Down

0 comments on commit 4cf603b

Please sign in to comment.