Skip to content
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
14 changes: 12 additions & 2 deletions provider/cocoon/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cocoon

import (
"context"
"crypto/sha256"
"fmt"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -540,10 +541,19 @@ func isHTTPURL(ref string) bool {

// localSnapshotName omits the default tag for backward compatibility.
func localSnapshotName(repo, tag string) string {
name := repo
if tag == "" || tag == meta.DefaultSnapshotTag {
return repo
name = repo
} else {
name = repo + ":" + tag
}
return repo + ":" + tag
const maxSnapshotNameLength = 63
if len(name) <= maxSnapshotNameLength {
return name
}
sum := sha256.Sum256([]byte(name))
suffix := fmt.Sprintf("-%x", sum[:6])
return name[:maxSnapshotNameLength-len(suffix)] + suffix
}

func forkSnapshotName(sourceVMName string) string {
Expand Down
19 changes: 19 additions & 0 deletions provider/cocoon/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,25 @@ func TestLocalSnapshotName(t *testing.T) {
}
}

func TestLocalSnapshotNameBoundsLongRegistryRefs(t *testing.T) {
repo := "simular/ubuntu2404-base-snapshot"
tag := "ubuntu2404-20260716-29479663055-1"

got := localSnapshotName(repo, tag)
if len(got) > 63 {
t.Fatalf("local snapshot name length = %d, want <= 63: %q", len(got), got)
}
if got != localSnapshotName(repo, tag) {
t.Fatal("local snapshot name is not deterministic")
}
if got == localSnapshotName(repo, tag+"-different") {
t.Fatal("different registry refs produced the same local snapshot name")
}
if !strings.HasPrefix(got, "simular/ubuntu2404-base-snapshot:") {
t.Fatalf("local snapshot name lost its recognizable prefix: %q", got)
}
}

func TestAssertSnapshotBackend(t *testing.T) {
t.Parallel()

Expand Down