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 34dee9f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
14 changes: 14 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.",
)
}

// NewInstallOptions instantiates a new, default InstallOptions struct.
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])
}
2 changes: 2 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

0 comments on commit 34dee9f

Please sign in to comment.