-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
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 { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
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. |
c4df504
to
3fd7aec
Compare
Codecov ReportAttention:
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. |
28afd82
to
f4a1de4
Compare
pkg/cmd/cli/backuplocation/set.go
Outdated
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
pkg/cmd/cli/backuplocation/set.go
Outdated
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
b3365c4
to
73d520a
Compare
32dbfd7
to
831a011
Compare
pkg/cmd/cli/backuplocation/set.go
Outdated
@@ -104,6 +107,11 @@ func (o *SetOptions) Run(c *cobra.Command, f client.Factory) error { | |||
} | |||
} | |||
|
|||
defalutBSLs, err := storage.GetDefaultBackupStorageLocations(context.Background(), kbClient, f.Namespace()) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
Signed-off-by: Ming Qiu <[email protected]>
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 runningvelero backup-location create
.Second way: Set a default backup storage location by passing a
--default
flag when runningvelero 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 thevelero server
command.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:
A
A
backup storage location exists, it's not allowed to set a new default backup storage locationA
does not existvelero backup-location set
orvelero backup-location create --default
commandvelero backup-location set
orvelero backup-location create --default
commandDoes your change fix a particular issue?
Fixes #(issue)
#6572
Please indicate you've done the following:
/kind changelog-not-required
as a comment on this pull request.site/content/docs/main
.