mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-07 13:55:20 +00:00
Add functional options for the Ark config install library
Signed-off-by: Mike Arpaia <mike@arpaia.co>
This commit is contained in:
@@ -8,6 +8,32 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
type arkConfigOption func(*arkConfig)
|
||||
|
||||
type arkConfig struct {
|
||||
backupSyncPeriod time.Duration
|
||||
gcSyncPeriod time.Duration
|
||||
restoreOnly bool
|
||||
}
|
||||
|
||||
func WithBackupSyncPeriod(t time.Duration) arkConfigOption {
|
||||
return func(c *arkConfig) {
|
||||
c.backupSyncPeriod = t
|
||||
}
|
||||
}
|
||||
|
||||
func WithGCSyncPeriod(t time.Duration) arkConfigOption {
|
||||
return func(c *arkConfig) {
|
||||
c.gcSyncPeriod = t
|
||||
}
|
||||
}
|
||||
|
||||
func WithRestoreOnly() arkConfigOption {
|
||||
return func(c *arkConfig) {
|
||||
c.restoreOnly = true
|
||||
}
|
||||
}
|
||||
|
||||
func Config(
|
||||
namespace string,
|
||||
pvCloudProviderName string,
|
||||
@@ -15,7 +41,17 @@ func Config(
|
||||
backupCloudProviderName string,
|
||||
backupCloudProviderConfig map[string]string,
|
||||
bucket string,
|
||||
opts ...arkConfigOption,
|
||||
) *arkv1.Config {
|
||||
c := &arkConfig{
|
||||
backupSyncPeriod: 30 * time.Minute,
|
||||
gcSyncPeriod: 30 * time.Minute,
|
||||
}
|
||||
|
||||
for _, opt := range opts {
|
||||
opt(c)
|
||||
}
|
||||
|
||||
return &arkv1.Config{
|
||||
ObjectMeta: objectMeta(namespace, "default"),
|
||||
PersistentVolumeProvider: &arkv1.CloudProviderConfig{
|
||||
@@ -30,14 +66,14 @@ func Config(
|
||||
Bucket: bucket,
|
||||
},
|
||||
BackupSyncPeriod: metav1.Duration{
|
||||
Duration: 30 * time.Minute,
|
||||
Duration: c.backupSyncPeriod,
|
||||
},
|
||||
GCSyncPeriod: metav1.Duration{
|
||||
Duration: 30 * time.Minute,
|
||||
Duration: c.gcSyncPeriod,
|
||||
},
|
||||
ScheduleSyncPeriod: metav1.Duration{
|
||||
Duration: time.Minute,
|
||||
},
|
||||
RestoreOnlyMode: false,
|
||||
RestoreOnlyMode: c.restoreOnly,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,27 +8,27 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
type deploymentOption func(*config)
|
||||
type deploymentOption func(*deploymentConfig)
|
||||
|
||||
type config struct {
|
||||
type deploymentConfig struct {
|
||||
image string
|
||||
withoutCredentialsVolume bool
|
||||
}
|
||||
|
||||
func WithImage(image string) deploymentOption {
|
||||
return func(c *config) {
|
||||
return func(c *deploymentConfig) {
|
||||
c.image = image
|
||||
}
|
||||
}
|
||||
|
||||
func WithoutCredentialsVolume() deploymentOption {
|
||||
return func(c *config) {
|
||||
return func(c *deploymentConfig) {
|
||||
c.withoutCredentialsVolume = true
|
||||
}
|
||||
}
|
||||
|
||||
func Deployment(namespace string, opts ...deploymentOption) *appsv1beta1.Deployment {
|
||||
c := &config{
|
||||
c := &deploymentConfig{
|
||||
image: "gcr.io/heptio-images/ark:latest",
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user