Skip to content

Commit 57a7b4d

Browse files
committed
feat: ssh key secret namespace
1 parent e22f2b3 commit 57a7b4d

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

main.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func main() {
5252
shootTokenSecret string
5353
shootTokenPath string
5454
sshKeySecret string
55+
sshKeySecretNamespace string
5556
namespace string
5657
gracefulShutdownTimeout time.Duration
5758
reconcileInterval time.Duration
@@ -72,7 +73,7 @@ func main() {
7273
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
7374
"Enable leader election for controller manager. "+
7475
"Enabling this will ensure there is only one active controller manager")
75-
flag.StringVar(&namespace, "namespace", "default", "the namespace this controller is running")
76+
flag.StringVar(&namespace, "namespace", "", "the namespace this controller is running")
7677
flag.DurationVar(&reconcileInterval, "reconcile-interval", 10*time.Minute, "duration after which a resource is getting reconciled at minimum")
7778
flag.DurationVar(&firewallHealthTimeout, "firewall-health-timeout", 20*time.Minute, "duration after a created firewall not getting ready is considered dead")
7879
flag.DurationVar(&createTimeout, "create-timeout", 10*time.Minute, "duration after which a firewall in the creation phase will be recreated")
@@ -88,10 +89,15 @@ func main() {
8889
flag.StringVar(&shootKubeconfigSecret, "shoot-kubeconfig-secret-name", "", "the secret name of the generic kubeconfig for shoot access")
8990
flag.StringVar(&shootTokenSecret, "shoot-token-secret-name", "", "the secret name of the token for shoot access")
9091
flag.StringVar(&sshKeySecret, "ssh-key-secret-name", "", "the secret name of the ssh key for machine access")
92+
flag.StringVar(&sshKeySecretNamespace, "ssh-key-secret-namespace", "", "the secret name of the ssh key for machine access")
9193
flag.StringVar(&shootTokenPath, "shoot-token-path", "", "the path where to store the token file for shoot access")
9294

9395
flag.Parse()
9496

97+
if sshKeySecretNamespace == "" {
98+
sshKeySecretNamespace = namespace
99+
}
100+
95101
slogHandler, err := controllers.NewLogger(logLevel)
96102
if err != nil {
97103
ctrl.Log.WithName("setup").Error(err, "unable to parse log level")
@@ -110,7 +116,7 @@ func main() {
110116
log.Fatalf("unable to create metal client %v", err)
111117
}
112118

113-
seedMgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
119+
mgrConfig := ctrl.Options{
114120
Scheme: scheme,
115121
Metrics: server.Options{
116122
BindAddress: metricsAddr,
@@ -129,7 +135,16 @@ func main() {
129135
LeaderElection: enableLeaderElection,
130136
LeaderElectionID: "firewall-controller-manager-leader-election",
131137
GracefulShutdownTimeout: &gracefulShutdownTimeout,
132-
})
138+
}
139+
140+
if namespace != "" {
141+
l.Info("running in dedicated namespace only", "namespace", namespace)
142+
mgrConfig.Cache.DefaultNamespaces = map[string]cache.Config{
143+
namespace: {},
144+
}
145+
}
146+
147+
seedMgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), mgrConfig)
133148
if err != nil {
134149
log.Fatalf("unable to setup firewall-controller-manager %v", err)
135150
}
@@ -196,7 +211,7 @@ func main() {
196211
// secret for this controller and expose the access secrets through the firewall
197212
// status resource, which can be read by the firewall-controller
198213
// - the firewall-controller can then create a client from these secrets but
199-
// it has to contiuously update the token file because the token will expire
214+
// it has to continuously update the token file because the token will expire
200215
// - we can re-use the same approach for this controller as well and do not have
201216
// to do any additional mounts for the deployment of the controller
202217
//
@@ -247,7 +262,7 @@ func main() {
247262
ShootAPIServerURL: shootApiURL,
248263
ShootAccess: externalShootAccess,
249264
SSHKeySecretName: sshKeySecret,
250-
SSHKeySecretNamespace: namespace,
265+
SSHKeySecretNamespace: sshKeySecretNamespace,
251266
ShootAccessHelper: internalShootAccessHelper,
252267
Metal: mclient,
253268
ClusterTag: fmt.Sprintf("%s=%s", tag.ClusterID, clusterID),

0 commit comments

Comments
 (0)