Add functional options for the Ark config install library

Signed-off-by: Mike Arpaia <mike@arpaia.co>
This commit is contained in:
Mike Arpaia
2018-05-18 15:04:05 -06:00
parent aeb5f6d832
commit cb7bcea5c3
2 changed files with 44 additions and 8 deletions

View File

@@ -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,
}
}

View File

@@ -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",
}