mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-08-16 12:16:06 +00:00
Add Labels field to BackupSpec (#3641)
* Add metadata.Labels to schedule.Spec.Template and it's copy logic to Backup Signed-off-by: Arush Salil <me@aru.sh> * document metadata.labels Signed-off-by: Klavs Klavsen <klavs@enableit.dk> * adjust text per suggestion. Signed-off-by: Klavs Klavsen <klavs@enableit.dk> * Rewrite labels copy logic, add comments, and debug log messages Signed-off-by: Arush Salil <me@aru.sh> * Rephrase label copy debug log Signed-off-by: Arush Salil <me@aru.sh> * Add initialized logger to FromSchedule Signed-off-by: Arush Salil <me@aru.sh> * use info log level per request. Signed-off-by: Klavs Klavsen <klavs@enableit.dk> Co-authored-by: Klavs Klavsen <klavs@enableit.dk>
This commit is contained in:
co-authored by
Klavs Klavsen
parent
f727e070cb
commit
ae6e1df9aa
@@ -0,0 +1 @@
|
||||
Add Label to BackupSpec so that labels can explicitly be provided to Schedule.Spec.Template.Metadata.Labels which will be reflected on the backups created.
|
||||
@@ -303,6 +303,13 @@ spec:
|
||||
are ANDed.
|
||||
type: object
|
||||
type: object
|
||||
metadata:
|
||||
properties:
|
||||
labels:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
type: object
|
||||
orderedResources:
|
||||
additionalProperties:
|
||||
type: string
|
||||
|
||||
@@ -318,6 +318,13 @@ spec:
|
||||
are ANDed.
|
||||
type: object
|
||||
type: object
|
||||
metadata:
|
||||
properties:
|
||||
labels:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
type: object
|
||||
orderedResources:
|
||||
additionalProperties:
|
||||
type: string
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -20,8 +20,14 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
type Metadata struct {
|
||||
Labels map[string]string `json:"labels,omitempty"`
|
||||
}
|
||||
|
||||
// BackupSpec defines the specification for a Velero backup.
|
||||
type BackupSpec struct {
|
||||
// +optional
|
||||
Metadata `json:"metadata,omitempty"`
|
||||
// IncludedNamespaces is a slice of namespace names to include objects
|
||||
// from. If empty, all namespaces are included.
|
||||
// +optional
|
||||
|
||||
@@ -205,6 +205,7 @@ func (in *BackupResourceHookSpec) DeepCopy() *BackupResourceHookSpec {
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *BackupSpec) DeepCopyInto(out *BackupSpec) {
|
||||
*out = *in
|
||||
in.Metadata.DeepCopyInto(&out.Metadata)
|
||||
if in.IncludedNamespaces != nil {
|
||||
in, out := &in.IncludedNamespaces, &out.IncludedNamespaces
|
||||
*out = make([]string, len(*in))
|
||||
@@ -715,6 +716,29 @@ func (in *InitRestoreHook) DeepCopy() *InitRestoreHook {
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Metadata) DeepCopyInto(out *Metadata) {
|
||||
*out = *in
|
||||
if in.Labels != nil {
|
||||
in, out := &in.Labels, &out.Labels
|
||||
*out = make(map[string]string, len(*in))
|
||||
for key, val := range *in {
|
||||
(*out)[key] = val
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Metadata.
|
||||
func (in *Metadata) DeepCopy() *Metadata {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(Metadata)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *ObjectStorageLocation) DeepCopyInto(out *ObjectStorageLocation) {
|
||||
*out = *in
|
||||
|
||||
@@ -17,13 +17,17 @@ limitations under the License.
|
||||
package builder
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/vmware-tanzu/velero/pkg/util/boolptr"
|
||||
"github.com/vmware-tanzu/velero/pkg/util/logging"
|
||||
)
|
||||
|
||||
/*
|
||||
@@ -77,7 +81,24 @@ func (b *BackupBuilder) ObjectMeta(opts ...ObjectMetaOpt) *BackupBuilder {
|
||||
|
||||
// FromSchedule sets the Backup's spec and labels from the Schedule template
|
||||
func (b *BackupBuilder) FromSchedule(schedule *velerov1api.Schedule) *BackupBuilder {
|
||||
labels := schedule.Labels
|
||||
var labels = make(map[string]string)
|
||||
|
||||
// Check if there's explicit Labels defined in the Schedule object template
|
||||
// and if present then copy it to the backup object.
|
||||
if schedule.Spec.Template.Metadata.Labels != nil {
|
||||
logger := logging.DefaultLogger(logging.LogLevelFlag(logrus.InfoLevel).Parse(), logging.NewFormatFlag().Parse())
|
||||
labels = schedule.Spec.Template.Metadata.Labels
|
||||
logger.WithFields(logrus.Fields{
|
||||
"backup": fmt.Sprintf("%s/%s", b.object.GetNamespace(), b.object.GetName()),
|
||||
"labels": schedule.Spec.Template.Metadata.Labels,
|
||||
}).Info("Schedule.template.metadata.labels set - using those labels instead of schedule.labels for backup object")
|
||||
} else {
|
||||
labels = schedule.Labels
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"backup": fmt.Sprintf("%s/%s", b.object.GetNamespace(), b.object.GetName()),
|
||||
"labels": schedule.Labels,
|
||||
}).Info("No Schedule.template.metadata.labels set - using Schedule.labels for backup object")
|
||||
}
|
||||
if labels == nil {
|
||||
labels = make(map[string]string)
|
||||
}
|
||||
|
||||
@@ -78,6 +78,11 @@ spec:
|
||||
# a default value of 30 days will be used. The default can be configured on the velero server
|
||||
# by passing the flag --default-backup-ttl.
|
||||
ttl: 24h0m0s
|
||||
# The labels you want on backup objects, created from this schedule (instead of copying the labels you have on schedule object itself).
|
||||
# When this field is set, the labels from the Schedule resource are not copied to the Backup resource.
|
||||
metadata:
|
||||
labels:
|
||||
labelname: somelabelvalue
|
||||
# Actions to perform at different times during a backup. The only hook supported is
|
||||
# executing a command in a container in a pod using the pod exec API. Optional.
|
||||
hooks:
|
||||
|
||||
Reference in New Issue
Block a user