/
options.go
93 lines (82 loc) · 2.99 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package app
import (
"os"
controllercmd "github.com/gardener/gardener/extensions/pkg/controller/cmd"
heartbeatcmd "github.com/gardener/gardener/extensions/pkg/controller/heartbeat/cmd"
webhookcmd "github.com/gardener/gardener/extensions/pkg/webhook/cmd"
"k8s.io/client-go/tools/leaderelection/resourcelock"
authncmd "github.com/fi-ts/gardener-extension-authn/pkg/cmd"
)
// ExtensionName is the name of the extension.
const ExtensionName = "extension-fits-authn"
// Options holds configuration passed to the registry service controller.
type Options struct {
generalOptions *controllercmd.GeneralOptions
authnOptions *authncmd.AuthOptions
restOptions *controllercmd.RESTOptions
managerOptions *controllercmd.ManagerOptions
controllerOptions *controllercmd.ControllerOptions
heartbeatOptions *heartbeatcmd.Options
healthOptions *controllercmd.ControllerOptions
controllerSwitches *controllercmd.SwitchOptions
webhookOptions *webhookcmd.AddToManagerOptions
reconcileOptions *controllercmd.ReconcilerOptions
optionAggregator controllercmd.OptionAggregator
}
// NewOptions creates a new Options instance.
func NewOptions() *Options {
// options for the webhook server
webhookServerOptions := &webhookcmd.ServerOptions{
Namespace: os.Getenv("WEBHOOK_CONFIG_NAMESPACE"),
}
webhookSwitches := authncmd.WebhookSwitchOptions()
webhookOptions := webhookcmd.NewAddToManagerOptions(
"fits-authn",
"",
nil,
webhookServerOptions,
webhookSwitches,
)
options := &Options{
generalOptions: &controllercmd.GeneralOptions{},
authnOptions: &authncmd.AuthOptions{},
restOptions: &controllercmd.RESTOptions{},
managerOptions: &controllercmd.ManagerOptions{
// These are default values.
LeaderElection: true,
LeaderElectionID: controllercmd.LeaderElectionNameID(ExtensionName),
LeaderElectionResourceLock: resourcelock.LeasesResourceLock,
LeaderElectionNamespace: os.Getenv("LEADER_ELECTION_NAMESPACE"),
},
controllerOptions: &controllercmd.ControllerOptions{
// This is a default value.
MaxConcurrentReconciles: 5,
},
heartbeatOptions: &heartbeatcmd.Options{
// This is a default value.
ExtensionName: ExtensionName,
RenewIntervalSeconds: 30,
Namespace: os.Getenv("LEADER_ELECTION_NAMESPACE"),
},
healthOptions: &controllercmd.ControllerOptions{
// This is a default value.
MaxConcurrentReconciles: 5,
},
controllerSwitches: authncmd.ControllerSwitchOptions(),
reconcileOptions: &controllercmd.ReconcilerOptions{},
webhookOptions: webhookOptions,
}
options.optionAggregator = controllercmd.NewOptionAggregator(
options.generalOptions,
options.restOptions,
options.managerOptions,
options.controllerOptions,
options.authnOptions,
controllercmd.PrefixOption("heartbeat-", options.heartbeatOptions),
controllercmd.PrefixOption("healthcheck-", options.healthOptions),
options.controllerSwitches,
options.reconcileOptions,
options.webhookOptions,
)
return options
}