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

Fix default BSL setting not work #6771

Merged
merged 1 commit into from
Dec 5, 2023

Conversation

qiuming-best
Copy link
Contributor

@qiuming-best qiuming-best commented Sep 6, 2023

Thank you for contributing to Velero!

Please add a summary of your change

Velero could set the default backup storage location as below:

  • First way: Set a default backup storage location by passing a --default flag when running velero backup-location create.

    velero backup-location create backups-primary \
      --provider aws \
      --bucket velero-backups \
      --config region=us-east-1 \
      --default
    
  • Second way: Set a default backup storage location by passing a --default flag when running velero backup-location set.

    velero backup-location set backups-primary --default

    We also could remove the default backup storage location by this command, below is one example

    velero backup-location set backups-primary --default=false
  • Third way: Set a default backup storage location by passing --default-backup-storage-location flag on the velero server command.

    velero server --default-backup-storage-location backups-primary

Note: Only could have one default backup storage location, which means it's not allowed to set two default backup storage locations at the same time, the priorities among these three are as follows:

  • if velero server side has specified one default backup storage location, suppose it's A
    • if A backup storage location exists, it's not allowed to set a new default backup storage location
    • if A does not exist
      • if using velero backup-location set or velero backup-location create --default command
        • it could be successful if no default backup storage location exists.
        • it would fail if already exist one default backup storage location. (So it need to remove other default backup storage location at first)
  • if velero server side has not specified one default backup storage location
    • if using velero backup-location set or velero backup-location create --default command
      • it could be successful if no default backup storage location exists.
      • it would fail if already exist one default backup storage location. (So it need to remove other default backup storage location at first)

Does your change fix a particular issue?

Fixes #(issue)
#6572

Please indicate you've done the following:

  • Accepted the DCO. Commits without the DCO will delay acceptance.
  • Created a changelog file or added /kind changelog-not-required as a comment on this pull request.
  • Updated the corresponding documentation in site/content/docs/main.

for i, location := range locations.Items {
if location.Spec.Default {
location.Spec.Default = false
if err := kbClient.Update(context.Background(), &locations.Items[i], &kbclient.UpdateOptions{}); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

bug with using &locations.Items[i], which could not set the specific location to Default false

if err := kbClient.Update(context.Background(), &locations.Items[i], &kbclient.UpdateOptions{}); err != nil {
return errors.WithStack(err)
}
break
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we could not break here, per the comment above // There is one and only one default backup storage location. // Disable any existing default backup storage location., If break here only one BSL could be unset

break
}
location.Spec.Default = false
if err := kbClient.Update(context.Background(), &locations.Items[i], &kbclient.UpdateOptions{}); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

bug with using &locations.Items[i], which could not set the specific location to Default false

if err := kbClient.Update(context.Background(), &locations.Items[i], &kbclient.UpdateOptions{}); err != nil {
return errors.WithStack(err)
}
break
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we could not break here, per the comment above // There is one and only one default backup storage location. // Disable any existing default backup storage location., If break here only one BSL could be unset

@qiuming-best
Copy link
Contributor Author

qiuming-best commented Sep 6, 2023

After going through the original codes, it wants to always keep one default BSL, but it does not work to unset the default BSL for the bug mentioned.

The difference between the original codes is that Velero does not unset the default BSL actively but fails, which means the user should unset the default BSL at first. and new codes still keep the three ways of setting priority as original.

@codecov
Copy link

codecov bot commented Sep 6, 2023

Codecov Report

Attention: 39 lines in your changes are missing coverage. Please review.

Comparison is base (b9b2c88) 60.35% compared to head (c6cba30) 61.78%.
Report is 264 commits behind head on main.

Files Patch % Lines
pkg/cmd/cli/backuplocation/set.go 12.50% 14 Missing ⚠️
internal/storage/storagelocation.go 0.00% 11 Missing ⚠️
...g/controller/backup_storage_location_controller.go 79.62% 8 Missing and 3 partials ⚠️
pkg/cmd/cli/backuplocation/create.go 40.00% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6771      +/-   ##
==========================================
+ Coverage   60.35%   61.78%   +1.42%     
==========================================
  Files         242      259      +17     
  Lines       25994    27940    +1946     
==========================================
+ Hits        15689    17262    +1573     
- Misses       9200     9468     +268     
- Partials     1105     1210     +105     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

locations := new(velerov1api.BackupStorageLocationList)
if err := kbClient.List(context.Background(), locations, &kbclient.ListOptions{Namespace: f.Namespace()}); err != nil {
return errors.WithStack(err)
if !o.DefaultBackupStorageLocation { // unset default backup storage location
Copy link
Contributor

Choose a reason for hiding this comment

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

If the velero backup-location set command doesn't set the --default parameter, it can also hit this logic.
I think it can confuse the user because the user could meet the default BSL validation error when the user doesn't have the intention to set the default BSL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are right, I've modified it, please help me to check it again

if err := kbClient.List(context.Background(), locations, &kbclient.ListOptions{Namespace: f.Namespace()}); err != nil {
return errors.WithStack(err)
if !o.DefaultBackupStorageLocation { // unset default backup storage location
if len(defalutBSLs.Items) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems the set command only targets one specific BSL, why do you need to check others?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this checking logic is for when the user uses the command velero backup-location set $BSL --default=false
to unset the default for one specific BSL

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed the unset logic check, we allow the user unset one specific BSL repeatedly

@qiuming-best qiuming-best force-pushed the bsl-fix branch 4 times, most recently from b3365c4 to 73d520a Compare November 29, 2023 06:37
@blackpiglet blackpiglet removed the request for review from reasonerjt November 29, 2023 08:18
@qiuming-best qiuming-best force-pushed the bsl-fix branch 5 times, most recently from 32dbfd7 to 831a011 Compare November 30, 2023 03:26
@@ -104,6 +107,11 @@ func (o *SetOptions) Run(c *cobra.Command, f client.Factory) error {
}
}

defalutBSLs, err := storage.GetDefaultBackupStorageLocations(context.Background(), kbClient, f.Namespace())
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this logic inside the if block in line 126 to avoid unnecessary BSL listing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@qiuming-best qiuming-best merged commit ea04a86 into vmware-tanzu:main Dec 5, 2023
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants