-
Notifications
You must be signed in to change notification settings - Fork 472
/
options.go
73 lines (62 loc) · 2.69 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package backupoptions
import (
"github.com/spf13/pflag"
"sigs.k8s.io/controller-runtime/pkg/controller"
)
const (
// DefaultBackupPath is the default path to the directory where the backup bucket is created.
DefaultBackupPath = "dev/local-backupbuckets"
// DefaultContainerMountPath is the default path to the directory where the backup bucket is mounted on the container.
DefaultContainerMountPath = "/etc/gardener/local-backupbuckets"
)
// ControllerOptions are command line options that can be set for controller.Options.
type ControllerOptions struct {
// BackupBucketPath is the path to the backupbucket.
BackupBucketPath string
// ContainerMountPath is the path to the directory where the backup bucket is mounted on the container.
ContainerMountPath string
config *ControllerConfig
}
// AddOptions are options to apply when adding the backupbucket controller to the manager.
type AddOptions struct {
// BackupBucketPath is the path to the backupbucket.
BackupBucketPath string
// ContainerMountPath is the path to the directory where the backup bucket is mounted on the container.
ContainerMountPath string
// Controller are the controller.Options.
Controller controller.Options
// IgnoreOperationAnnotation specifies whether to ignore the operation annotation or not.
IgnoreOperationAnnotation bool
}
// AddFlags implements Flagger.AddFlags.
func (c *ControllerOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&c.BackupBucketPath, "local-dir", c.BackupBucketPath, "Path to the directory where the bucket will be created.")
fs.StringVar(&c.ContainerMountPath, "container-mount-path", c.ContainerMountPath, "Path to the directory where the backup bucket is mounted on the container.")
}
// Complete implements Completer.Complete.
func (c *ControllerOptions) Complete() error {
c.config = &ControllerConfig{
c.BackupBucketPath,
c.ContainerMountPath,
}
return nil
}
// Completed returns the completed ControllerConfig. Only call this if `Complete` was successful.
func (c *ControllerOptions) Completed() *ControllerConfig {
return c.config
}
// ControllerConfig is a completed controller configuration.
type ControllerConfig struct {
// BackupBucketPath is the path to the backupbucket.
BackupBucketPath string
// ContainerMountPath is the path to the directory where the backup bucket is mounted on the container.
ContainerMountPath string
}
// Apply sets the values of this ControllerConfig in the given AddOptions.
func (c *ControllerConfig) Apply(opts *AddOptions) {
opts.BackupBucketPath = c.BackupBucketPath
opts.ContainerMountPath = c.ContainerMountPath
}