mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-07 05:46:37 +00:00
Merge pull request #7451 from qiuming-best/maintenance-job
Add repository maintenance job
This commit is contained in:
@@ -27,6 +27,7 @@ import (
|
||||
|
||||
"github.com/vmware-tanzu/velero/internal/velero"
|
||||
"github.com/vmware-tanzu/velero/pkg/builder"
|
||||
"github.com/vmware-tanzu/velero/pkg/repository"
|
||||
)
|
||||
|
||||
type podTemplateOption func(*podTemplateConfig)
|
||||
@@ -51,6 +52,7 @@ type podTemplateConfig struct {
|
||||
privilegedNodeAgent bool
|
||||
disableInformerCache bool
|
||||
scheduleSkipImmediately bool
|
||||
maintenanceConfig repository.MaintenanceConfig
|
||||
}
|
||||
|
||||
func WithImage(image string) podTemplateOption {
|
||||
@@ -177,6 +179,12 @@ func WithScheduleSkipImmediately(b bool) podTemplateOption {
|
||||
}
|
||||
}
|
||||
|
||||
func WithMaintenanceConfig(config repository.MaintenanceConfig) podTemplateOption {
|
||||
return func(c *podTemplateConfig) {
|
||||
c.maintenanceConfig = config
|
||||
}
|
||||
}
|
||||
|
||||
func Deployment(namespace string, opts ...podTemplateOption) *appsv1.Deployment {
|
||||
// TODO: Add support for server args
|
||||
c := &podTemplateConfig{
|
||||
@@ -234,6 +242,26 @@ func Deployment(namespace string, opts ...podTemplateOption) *appsv1.Deployment
|
||||
args = append(args, fmt.Sprintf("--fs-backup-timeout=%v", c.podVolumeOperationTimeout))
|
||||
}
|
||||
|
||||
if c.maintenanceConfig.KeepLatestMaitenanceJobs > 0 {
|
||||
args = append(args, fmt.Sprintf("--keep-latest-maintenance-jobs=%d", c.maintenanceConfig.KeepLatestMaitenanceJobs))
|
||||
}
|
||||
|
||||
if c.maintenanceConfig.CPULimit != "" {
|
||||
args = append(args, fmt.Sprintf("--maintenance-job-cpu-limit=%s", c.maintenanceConfig.CPULimit))
|
||||
}
|
||||
|
||||
if c.maintenanceConfig.CPURequest != "" {
|
||||
args = append(args, fmt.Sprintf("--maintenance-job-cpu-request=%s", c.maintenanceConfig.CPURequest))
|
||||
}
|
||||
|
||||
if c.maintenanceConfig.MemLimit != "" {
|
||||
args = append(args, fmt.Sprintf("--maintenance-job-mem-limit=%s", c.maintenanceConfig.MemLimit))
|
||||
}
|
||||
|
||||
if c.maintenanceConfig.MemRequest != "" {
|
||||
args = append(args, fmt.Sprintf("--maintenance-job-mem-request=%s", c.maintenanceConfig.MemRequest))
|
||||
}
|
||||
|
||||
deployment := &appsv1.Deployment{
|
||||
ObjectMeta: objectMeta(namespace, "velero"),
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
|
||||
@@ -22,6 +22,8 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
|
||||
"github.com/vmware-tanzu/velero/pkg/repository"
|
||||
)
|
||||
|
||||
func TestDeployment(t *testing.T) {
|
||||
@@ -68,4 +70,18 @@ func TestDeployment(t *testing.T) {
|
||||
deploy = Deployment("velero", WithDisableInformerCache())
|
||||
assert.Len(t, deploy.Spec.Template.Spec.Containers[0].Args, 2)
|
||||
assert.Equal(t, "--disable-informer-cache=true", deploy.Spec.Template.Spec.Containers[0].Args[1])
|
||||
|
||||
deploy = Deployment("velero", WithMaintenanceConfig(repository.MaintenanceConfig{
|
||||
KeepLatestMaitenanceJobs: 3,
|
||||
CPURequest: "100m",
|
||||
MemRequest: "256Mi",
|
||||
CPULimit: "200m",
|
||||
MemLimit: "512Mi",
|
||||
}))
|
||||
assert.Len(t, deploy.Spec.Template.Spec.Containers[0].Args, 6)
|
||||
assert.Equal(t, "--keep-latest-maintenance-jobs=3", deploy.Spec.Template.Spec.Containers[0].Args[1])
|
||||
assert.Equal(t, "--maintenance-job-cpu-limit=200m", deploy.Spec.Template.Spec.Containers[0].Args[2])
|
||||
assert.Equal(t, "--maintenance-job-cpu-request=100m", deploy.Spec.Template.Spec.Containers[0].Args[3])
|
||||
assert.Equal(t, "--maintenance-job-mem-limit=512Mi", deploy.Spec.Template.Spec.Containers[0].Args[4])
|
||||
assert.Equal(t, "--maintenance-job-mem-request=256Mi", deploy.Spec.Template.Spec.Containers[0].Args[5])
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ import (
|
||||
v1crds "github.com/vmware-tanzu/velero/config/crd/v1/crds"
|
||||
v2alpha1crds "github.com/vmware-tanzu/velero/config/crd/v2alpha1/crds"
|
||||
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
||||
"github.com/vmware-tanzu/velero/pkg/repository"
|
||||
"github.com/vmware-tanzu/velero/pkg/util/logging"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -261,6 +263,9 @@ type VeleroOptions struct {
|
||||
DefaultSnapshotMoveData bool
|
||||
DisableInformerCache bool
|
||||
ScheduleSkipImmediately bool
|
||||
FormatFlag *logging.FormatFlag
|
||||
LogLevelFlag *logging.LevelFlag
|
||||
MaintenanceCfg repository.MaintenanceConfig
|
||||
}
|
||||
|
||||
func AllCRDs() *unstructured.UnstructuredList {
|
||||
@@ -345,6 +350,7 @@ func AllResources(o *VeleroOptions) *unstructured.UnstructuredList {
|
||||
WithPodVolumeOperationTimeout(o.PodVolumeOperationTimeout),
|
||||
WithUploaderType(o.UploaderType),
|
||||
WithScheduleSkipImmediately(o.ScheduleSkipImmediately),
|
||||
WithMaintenanceConfig(o.MaintenanceCfg),
|
||||
}
|
||||
|
||||
if len(o.Features) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user