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

roachprod: minor fixes for snapshots #104573

Merged
merged 1 commit into from
Jun 9, 2023
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
13 changes: 10 additions & 3 deletions pkg/roachprod/roachprod.go
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,13 @@ func CreateSnapshot(
crdbVersion = "unknown"
}
crdbVersion = strings.TrimPrefix(crdbVersion, "cockroach-")
// N.B. snapshot name cannot exceed 63 characters, so we use short sha for dev version.
if index := strings.Index(crdbVersion, "dev-"); index != -1 {
sha := crdbVersion[index+4:]
if len(sha) > 7 {
crdbVersion = crdbVersion[:index+4] + sha[:7]
}
}

labels := map[string]string{
"roachprod-node-src-spec": cVM.MachineType,
Expand Down Expand Up @@ -1655,6 +1662,9 @@ func CreateSnapshot(
snapshotFingerprintInfix := strings.ReplaceAll(
fmt.Sprintf("%s-n%d", crdbVersion, len(nodes)), ".", "-")
snapshotName := fmt.Sprintf("%s-%s-%04d", vsco.Name, snapshotFingerprintInfix, node)
if len(snapshotName) > 63 {
return fmt.Errorf("snapshot name %q exceeds 63 characters; shorten name prefix and use description arg. for more context", snapshotName)
}
volumeSnapshot, err := provider.CreateVolumeSnapshot(l, volume,
vm.VolumeSnapshotCreateOpts{
Name: snapshotName,
Expand All @@ -1673,7 +1683,6 @@ func CreateSnapshot(
return nil
}); err != nil {
res.Err = err
return res, res.Err
}
return res, nil
}); err != nil {
Expand Down Expand Up @@ -1746,7 +1755,6 @@ func ApplySnapshots(
return nil
}); err != nil {
res.Err = err
return res, res.Err
}
return res, nil
}); err != nil {
Expand Down Expand Up @@ -1817,7 +1825,6 @@ func ApplySnapshots(
return nil
}); err != nil {
res.Err = err
return res, res.Err
}
return res, nil
})
Expand Down
10 changes: 10 additions & 0 deletions pkg/roachprod/vm/gce/gcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ func (p *Provider) CreateVolumeSnapshot(
) (vm.VolumeSnapshot, error) {
args := []string{
"compute",
"--project", p.GetProject(),
"snapshots",
"create", vsco.Name,
"--source-disk", volume.ProviderResourceID,
Expand All @@ -336,6 +337,7 @@ func (p *Provider) CreateVolumeSnapshot(

args = []string{
"compute",
"--project", p.GetProject(),
"snapshots",
"add-labels", vsco.Name,
"--labels", s[:len(s)-1],
Expand All @@ -355,6 +357,7 @@ func (p *Provider) ListVolumeSnapshots(
) ([]vm.VolumeSnapshot, error) {
args := []string{
"compute",
"--project", p.GetProject(),
"snapshots",
"list",
"--format", "json(name,id)",
Expand Down Expand Up @@ -398,6 +401,7 @@ func (p *Provider) DeleteVolumeSnapshots(l *logger.Logger, snapshots ...vm.Volum
}
args := []string{
"compute",
"--project", p.GetProject(),
"snapshots",
"delete",
}
Expand Down Expand Up @@ -438,6 +442,7 @@ func (p *Provider) CreateVolume(
}
args := []string{
"compute",
"--project", p.GetProject(),
"disks",
"create", vco.Name,
"--size", strconv.Itoa(vco.Size),
Expand Down Expand Up @@ -496,6 +501,7 @@ func (p *Provider) CreateVolume(
s := sb.String()
args = []string{
"compute",
"--project", p.GetProject(),
"disks",
"add-labels", vco.Name,
"--labels", s[:len(s)-1],
Expand All @@ -522,6 +528,7 @@ func (p *Provider) DeleteVolume(l *logger.Logger, volume vm.Volume, vm *vm.VM) e
{ // Detach disks.
args := []string{
"compute",
"--project", p.GetProject(),
"instances",
"detach-disk", vm.Name,
"--disk", volume.ProviderResourceID,
Expand All @@ -535,6 +542,7 @@ func (p *Provider) DeleteVolume(l *logger.Logger, volume vm.Volume, vm *vm.VM) e
{ // Delete disks.
args := []string{
"compute",
"--project", p.GetProject(),
"disks",
"delete",
volume.ProviderResourceID,
Expand Down Expand Up @@ -646,6 +654,7 @@ func (p *Provider) AttachVolume(l *logger.Logger, volume vm.Volume, vm *vm.VM) (
// Volume attach.
args := []string{
"compute",
"--project", p.GetProject(),
"instances",
"attach-disk",
vm.ProviderID,
Expand Down Expand Up @@ -675,6 +684,7 @@ func (p *Provider) AttachVolume(l *logger.Logger, volume vm.Volume, vm *vm.VM) (
// Volume auto delete.
args = []string{
"compute",
"--project", p.GetProject(),
"instances",
"set-disk-auto-delete", vm.ProviderID,
"--auto-delete",
Expand Down