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

Allow annotations and/or labels on Backup objects to be added onto the backup object in plugins during a backup #2483

Open
jimbo459 opened this issue Apr 30, 2020 · 7 comments
Labels
Area/Plugins Issues related to plugin infra/internal plugins Icebox We see the value, but it is not slated for the next couple releases. Needs Product Blocked needing input or feedback from Product Reviewed Q2 2021

Comments

@jimbo459
Copy link

Issue
We are writing a custom backup plugin where we wish to amend the backup object which is passed in as the second arg.
When attempting to amend the labels or annotations we are not seeing this change reflected in the final backup object.
To amend the passed in *v1.backup we attempted to use the SetAnnotation() method on the backup.ObjectMeta property.

annotations := make(map[string]string)
annotations["velero.io/foo"] = "bar"
backup.ObjectMeta.SetAnnotations(annotations)

As this failed, we then attempted to set the field directly by accessing the property and setting the value. This change also did not persist.

annotations := &backup.ObjectMeta.Annotations  
content := make(map[string]string) 
content["foo"] = "bar"
*annotations = content

Expectation
We expected the change to reflect in the final backup object, reachable either by velero backup describe <backup_name> or kubectl get backups.velero.io <backup_name>

Replication
An easy way to replicate this issue is by running the following code snippet in a custom plugin:

p.log.Info("backup Object before instantiation")
p.log.Info(backup)
backup = new(v1.Backup)                                                                                                                                   
p.log.Info("backup Object after instantiation")                                                                                                            
p.log.Info(backup)

This instantiates a new backup object when the plugin in called. On the p.log.Info calls you can see this change has reflected, however when the plugin in called on the next item the backup object is the original one, indicating that the change made in the previous call to the plugin has not persisted.

Environment:

  • Velero version: 1.3.1
  • Velero features:
  • Kubernetes version:
    --Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.2", GitCommit:"52c56ce7a8272c798dbc29846288d7cd9fbae032", GitTreeState:"clean", BuildDate:"2020-04-21T01:25:41Z", GoVersion:"go1.13.10", Compiler:"gc", Platform:"linux/amd64"}
    --Server Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.5", GitCommit:"20c265fef0741dd71a66480e35bd69f18351daea", GitTreeState:"clean", BuildDate:"2019-10-15T19:07:57Z", GoVersion:"go1.12.10", Compiler:"gc", Platform:"linux/amd64"}
  • Kubernetes installer & version: TKG-i
  • Cloud provider or hardware configuration: GCP
  • OS: Ubuntu 18.04.4 LTS (Bionic Beaver)"

CC @neil-hickey @aclevername

@ashish-amarnath
Copy link
Member

@jimbo459 It is definitely possible to add annotations or update the object to be backed un in a backupItemAction plugin.
Here is an example of our velero-plugin-for-csi where this is done.
https://github.com/vmware-tanzu/velero-plugin-for-csi/blob/master/internal/backup/pvc_action.go#L147

What you might be missing is the marshaling and un-marshaling steps performed at https://github.com/vmware-tanzu/velero-plugin-for-csi/blob/master/internal/backup/pvc_action.go#L65-L68 and https://github.com/vmware-tanzu/velero-plugin-for-csi/blob/master/internal/backup/pvc_action.go#L163-L166 respectively.

If this doesn't solve your problem, please share a link to your code and we'll be happy to help further.

@ashish-amarnath ashish-amarnath added Needs info Waiting for information Area/Plugins Issues related to plugin infra/internal plugins Question labels May 11, 2020
@neil-hickey
Copy link

Hey @ashish-amarnath Thanks for the update!

We are trying to modify the Backup object of Velero itself (as opposed to the item to be backed-up)

In your examples I think the csi plugin is modifying item runtime.Unstructured, where we want to edit backup *velerov1api.Backup.

From slack: https://kubernetes.slack.com/archives/C6VCGP4MT/p1588064584438000 it seems like this isn't a use-case that is expected to work. So we may try out the workaround suggested in the thread and update here if that works 👍

@ashish-amarnath
Copy link
Member

@neil-hickey Thanks for the update. I am going to close this issue. Feel free to re-open or engage w/ us on slack.

@ashish-amarnath ashish-amarnath changed the title backup object not editable in plugin Allow annotations and/or labels on Backup objects to be added onto the backup object during a backup Jun 15, 2020
@ashish-amarnath
Copy link
Member

Reopening as there are use cases where this may be useful for plugins to add annotations/labels.

@ashish-amarnath ashish-amarnath added Enhancement/User End-User Enhancement to Velero Needs Product Blocked needing input or feedback from Product and removed Needs info Waiting for information Area/Plugins Issues related to plugin infra/internal plugins Question labels Aug 26, 2020
@nrb nrb changed the title Allow annotations and/or labels on Backup objects to be added onto the backup object during a backup Allow annotations and/or labels on Backup objects to be added onto the backup object in plugins during a backup Oct 22, 2020
@nrb nrb added Area/Plugins Issues related to plugin infra/internal plugins and removed Enhancement/User End-User Enhancement to Velero labels Oct 22, 2020
@eleanor-millman eleanor-millman added Reviewed Q2 2021 Icebox We see the value, but it is not slated for the next couple releases. labels May 11, 2021
@dsu-igeek
Copy link
Contributor

Need to figure out how to make this work as we moved the Kubernetes serializer into Astrolabe

@sjoukedv
Copy link

sjoukedv commented Jan 9, 2023

Reopening as there are use cases where this may be useful for plugins to add annotations/labels.

I need this feature with Argo CD, so that I can ignore the backup objects itself, but not the schedule

@timbuchinger
Copy link

Reopening as there are use cases where this may be useful for plugins to add annotations/labels.

I need this feature with Argo CD, so that I can ignore the backup objects itself, but not the schedule

I had this same issue and this is the solution I settled on: https://argo-cd.readthedocs.io/en/stable/operator-manual/declarative-setup/#resource-exclusioninclusion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Plugins Issues related to plugin infra/internal plugins Icebox We see the value, but it is not slated for the next couple releases. Needs Product Blocked needing input or feedback from Product Reviewed Q2 2021
Projects
None yet
Development

No branches or pull requests

8 participants