Skip to content

Commit

Permalink
Merge pull request #497 from deepakkinni/xport-2
Browse files Browse the repository at this point in the history
[Cherry-pick]Remove health annotation from PVC (#495)
  • Loading branch information
Deepak Kinni authored Nov 17, 2022
2 parents fe50791 + c6cff9e commit 795eaec
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,3 +414,11 @@ const (
DefaultSecretName = "velero-vsphere-config-secret"
DefaultSecretNamespace = "velero"
)

const (
// AnnVolumeHealth is the key for HealthStatus annotation on volume claim
// for vSphere CSI Driver.
AnnVolumeHealth = "volumehealth.storage.kubernetes.io/health"
// key for expressing timestamp for volume health annotation
AnnVolumeHealthTS = "volumehealth.storage.kubernetes.io/health-timestamp"
)
7 changes: 7 additions & 0 deletions pkg/plugin/backup_pvc_action_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ func (p *NewPVCBackupItemAction) Execute(item runtime.Unstructured, backup *vele
}

p.Log.Infof("Persisting snapshot with snapshotID :%s under label: %s Snapshot: %v", updatedSnapshot.Status.SnapshotID, constants.ItemSnapshotLabel, updatedSnapshot)

// Remove the volume health annotations before the backup
// because vSphere CSI driver has a webhook that prevents this annotation
// from being created/updated by a non-CSI driver system service account
healthAnnotations := []string{constants.AnnVolumeHealth, constants.AnnVolumeHealthTS}
pluginUtil.RemoveAnnotations(&pvc.ObjectMeta, healthAnnotations)

// Persist the snapshot blob as an annotation of PVC
snapshotAnnotation, err := pluginUtil.GetAnnotationFromSnapshot(updatedSnapshot)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions pkg/plugin/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ func GetAnnotationFromSnapshot(itemSnapshot interface{}) (string, error) {
return base64.StdEncoding.EncodeToString(itemSnapshotByteArray), nil
}

// RemoveAnnotations removes the supplied keys from the annotations on the object
func RemoveAnnotations(o *metav1.ObjectMeta, keys []string) {
if o.Annotations != nil {
for _, k := range keys {
delete(o.Annotations, k)
}
}
}

// AddAnnotations adds the supplied key-values to the annotations on the object
func AddAnnotations(o *metav1.ObjectMeta, vals map[string]string) {
if o.Annotations == nil {
Expand Down

0 comments on commit 795eaec

Please sign in to comment.