Skip to content

Commit

Permalink
Add backup-repository-config and repo-maintenance-job-config for inst…
Browse files Browse the repository at this point in the history
…all CLI

Signed-off-by: Xun Jiang <[email protected]>
  • Loading branch information
blackpiglet committed Sep 10, 2024
1 parent 46801a0 commit 69301c2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/cmd/cli/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ type Options struct {
ScheduleSkipImmediately bool
PodResources kubeutil.PodResources
KeepLatestMaintenanceJobs int
BackupRepoConfig string
RepoMaintenanceJobConfig string
}

// BindFlags adds command line values to the options struct.
Expand Down Expand Up @@ -161,6 +163,18 @@ func (o *Options) BindFlags(flags *pflag.FlagSet) {
o.PodResources.MemoryLimit,
"Memory limit for maintenance jobs. Default is no limit.",
)
flags.StringVar(
&o.BackupRepoConfig,
"backup-repository-config",
o.BackupRepoConfig,
"The name of configMap containing backup repository configurations.",
)
flags.StringVar(
&o.RepoMaintenanceJobConfig,
"repo-maintenance-job-config",
o.RepoMaintenanceJobConfig,
"The name of ConfigMap containing repository maintenance Job configurations.",
)

Check warning on line 177 in pkg/cmd/cli/install/install.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/cli/install/install.go#L166-L177

Added lines #L166 - L177 were not covered by tests
}

// NewInstallOptions instantiates a new, default InstallOptions struct.
Expand Down Expand Up @@ -259,6 +273,8 @@ func (o *Options) AsVeleroOptions() (*install.VeleroOptions, error) {
ScheduleSkipImmediately: o.ScheduleSkipImmediately,
PodResources: o.PodResources,
KeepLatestMaintenanceJobs: o.KeepLatestMaintenanceJobs,
BackupRepoConfig: o.BackupRepoConfig,
RepoMaintenanceJobConfig: o.RepoMaintenanceJobConfig,

Check warning on line 277 in pkg/cmd/cli/install/install.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/cli/install/install.go#L276-L277

Added lines #L276 - L277 were not covered by tests
}, nil
}

Expand Down
21 changes: 21 additions & 0 deletions pkg/install/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ type podTemplateConfig struct {
scheduleSkipImmediately bool
podResources kube.PodResources
keepLatestMaintenanceJobs int
backupRepoConfig string
repoMaintenanceJobConfig string
}

func WithImage(image string) podTemplateOption {
Expand Down Expand Up @@ -192,6 +194,17 @@ func WithKeepLatestMaintenanceJobs(keepLatestMaintenanceJobs int) podTemplateOpt
}
}

func WithBackupRepoConfig(backupRepoConfig string) podTemplateOption {
return func(c *podTemplateConfig) {
c.backupRepoConfig = backupRepoConfig
}
}
func WithRepoMaintenanceJobConfig(repoMaintenanceJobConfig string) podTemplateOption {
return func(c *podTemplateConfig) {
c.repoMaintenanceJobConfig = repoMaintenanceJobConfig
}
}

func Deployment(namespace string, opts ...podTemplateOption) *appsv1.Deployment {
// TODO: Add support for server args
c := &podTemplateConfig{
Expand Down Expand Up @@ -269,6 +282,14 @@ func Deployment(namespace string, opts ...podTemplateOption) *appsv1.Deployment
args = append(args, fmt.Sprintf("--maintenance-job-mem-request=%s", c.podResources.MemoryRequest))
}

if len(c.backupRepoConfig) > 0 {
args = append(args, fmt.Sprintf("--backup-repository-config=%s", c.backupRepoConfig))
}

if len(c.repoMaintenanceJobConfig) > 0 {
args = append(args, fmt.Sprintf("--repo-maintenance-job-config=%s", c.repoMaintenanceJobConfig))
}

deployment := &appsv1.Deployment{
ObjectMeta: objectMeta(namespace, "velero"),
TypeMeta: metav1.TypeMeta{
Expand Down
8 changes: 8 additions & 0 deletions pkg/install/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,12 @@ func TestDeployment(t *testing.T) {
assert.Equal(t, "--maintenance-job-cpu-request=100m", deploy.Spec.Template.Spec.Containers[0].Args[2])
assert.Equal(t, "--maintenance-job-mem-limit=512Mi", deploy.Spec.Template.Spec.Containers[0].Args[3])
assert.Equal(t, "--maintenance-job-mem-request=256Mi", deploy.Spec.Template.Spec.Containers[0].Args[4])

deploy = Deployment("velero", WithBackupRepoConfig("test-backup-repo-config"))
assert.Len(t, deploy.Spec.Template.Spec.Containers[0].Args, 2)
assert.Equal(t, "--backup-repository-config=test-backup-repo-config", deploy.Spec.Template.Spec.Containers[0].Args[1])

deploy = Deployment("velero", WithRepoMaintenanceJobConfig("test-repo-maintenance-config"))
assert.Len(t, deploy.Spec.Template.Spec.Containers[0].Args, 2)
assert.Equal(t, "--repo-maintenance-job-config=test-repo-maintenance-config", deploy.Spec.Template.Spec.Containers[0].Args[1])
}
4 changes: 4 additions & 0 deletions pkg/install/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ type VeleroOptions struct {
ScheduleSkipImmediately bool
PodResources kube.PodResources
KeepLatestMaintenanceJobs int
BackupRepoConfig string
RepoMaintenanceJobConfig string
}

func AllCRDs() *unstructured.UnstructuredList {
Expand Down Expand Up @@ -350,6 +352,8 @@ func AllResources(o *VeleroOptions) *unstructured.UnstructuredList {
WithScheduleSkipImmediately(o.ScheduleSkipImmediately),
WithPodResources(o.PodResources),
WithKeepLatestMaintenanceJobs(o.KeepLatestMaintenanceJobs),
WithBackupRepoConfig(o.BackupRepoConfig),
WithRepoMaintenanceJobConfig(o.RepoMaintenanceJobConfig),
}

if len(o.Features) > 0 {
Expand Down

0 comments on commit 69301c2

Please sign in to comment.