Skip to content

feat(cli): onboard iaas volume backup api #773

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

Open
wants to merge 33 commits into
base: main
Choose a base branch
from

Conversation

Benjosh95
Copy link
Contributor

@Benjosh95 Benjosh95 commented Jun 1, 2025

Description

Onboarding the volume backup API https://docs.api.stackit.cloud/documentation/iaas/version/v1#tag/Backups to manage the backup resources via the cli.

Checklist

  • Issue was linked above
  • Code format was applied: make fmt
  • Examples were added / adjusted (see e.g. here)
  • Docs are up-to-date: make generate-docs (will be checked by CI)
  • Unit tests got implemented or updated
  • Unit tests are passing: make test (will be checked by CI)
  • No linter issues: make lint (will be checked by CI)

Testing-Instructions

  1. Create a test volume to have something to backup
    stackit volume create --name backup-test-vol --size 10 --performance-class storage_premium_perf0 --availability-zone eu01-1 --labels initial=true,purpose=backup-testing

  2. Create backup of the volume with name and labels
    stackit volume backup create --source-id <VOLUME_ID> --source-type volume --name first-backup --labels state=original,test=true

  3. List backups with limit and label selector
    stackit volume backup list --limit 5 --label-selector state=original

  4. Update backup with new name and labels
    stackit volume backup update <BACKUP_ID> --name updated-backup --labels state=modified,test=true

  5. Describe backup to verify changes
    stackit volume backup describe <BACKUP_ID>

  6. Restore backup
    stackit volume backup restore <BACKUP_ID>

  7. Clean up by deleting backup
    stackit volume backup delete <BACKUP_ID>

  8. Clean up by deleting volume
    stackit volume delete <VOLUME_ID>

@rubenhoenle
Copy link
Member

@Benjosh95 please check the failing CI pipeline

@Benjosh95 Benjosh95 marked this pull request as ready for review June 2, 2025 17:14
@Benjosh95 Benjosh95 requested review from marceljk and Fyusel as code owners June 2, 2025 17:14
@Benjosh95
Copy link
Contributor Author

@Benjosh95 please check the failing CI pipeline

CI pipeline fails due to missing/undefined waiters that will be merged with this PR: stackitcloud/stackit-sdk-go#2669

func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreateBackupRequest {
req := apiClient.CreateBackup(ctx, model.ProjectId)

// Convert map[string]string to map[string]interface{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is duplicated already 20 times across the codebase: https://github.com/search?q=repo%3Astackitcloud%2Fstackit-cli%20%2F%2F%20Convert%20map%5Bstring%5Dstring%20to%20map%5Bstring%5Dinterface%7B%7D&type=code

Please create a util function for it.

You can also create a Jira ticket in the backlog instead if you prefer. But we shouldn't continue to work like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created a seperate ticket: https://jira.schwarz/browse/STACKITCLI-203

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the new util func here after merge of the refactoring PR

if err != nil {
return err
}

Copy link
Contributor

@marceljk marceljk Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here can a prompt be added, to ask the user to confirm this action. Something similar like this:

if !model.AssumeYes {
prompt := fmt.Sprintf("Are you sure you want to restore %q with backup %q? (This cannot be undone)", sourceLabel, backupLabel)
err = params.Printer.PromptForConfirmation(prompt)
if err != nil {
return err
}
}

Comment on lines +54 to +61
backup, err := apiClient.GetBackup(ctx, model.ProjectId, model.BackupId).Execute()
if err != nil {
params.Printer.Debug(print.ErrorLevel, "get backup name: %v", err)
}
backupLabel := model.BackupId
if backup != nil && backup.Name != nil {
backupLabel = *backup.Name
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be move to a GetBackupName() function to iaas utils as well. Because this part of code is used duplicated in the restore command and would be need for https://github.com/stackitcloud/stackit-cli/pull/773/files#r2142564651

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants