Skip to content

Commit 2f8caf0

Browse files
committed
feat: allow setting node registration expiration via config
1 parent 757defa commit 2f8caf0

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ This will also affect the way you [reference users in policies](https://github.c
9595
- Fixed missing `stable-debug` container tag [#2232](https://github.com/juanfont/headscale/pr/2232)
9696
- Loosened up `server_url` and `base_domain` check. It was overly strict in some cases. [#2248](https://github.com/juanfont/headscale/pull/2248)
9797
- CLI for managing users now accepts `--identifier` in addition to `--name`, usage of `--identifier` is recommended [#2261](https://github.com/juanfont/headscale/pull/2261)
98+
- Added option to set Node registration expiration/cleanup options via config
9899

99100
## 0.23.0 (2024-09-18)
100101

hscontrol/app.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ const (
7272
updateInterval = 5 * time.Second
7373
privateKeyFileMode = 0o600
7474
headscaleDirPerm = 0o700
75-
76-
registerCacheExpiration = time.Minute * 15
77-
registerCacheCleanup = time.Minute * 20
7875
)
7976

8077
// Headscale represents the base app of the service.
@@ -122,8 +119,8 @@ func NewHeadscale(cfg *types.Config) (*Headscale, error) {
122119
}
123120

124121
registrationCache := zcache.New[string, types.Node](
125-
registerCacheExpiration,
126-
registerCacheCleanup,
122+
cfg.Tuning.NodeRegistrationCacheExpiration,
123+
cfg.Tuning.NodeRegistrationCacheCleanup,
127124
)
128125

129126
app := Headscale{

hscontrol/types/config.go

+8
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ type Tuning struct {
212212
NotifierSendTimeout time.Duration
213213
BatchChangeDelay time.Duration
214214
NodeMapSessionBufferedChanSize int
215+
216+
// Node registration cache expiration
217+
NodeRegistrationCacheExpiration time.Duration
218+
NodeRegistrationCacheCleanup time.Duration
215219
}
216220

217221
// LoadConfig prepares and loads the Headscale configuration into Viper.
@@ -291,6 +295,8 @@ func LoadConfig(path string, isFile bool) error {
291295
viper.SetDefault("tuning.notifier_send_timeout", "800ms")
292296
viper.SetDefault("tuning.batch_change_delay", "800ms")
293297
viper.SetDefault("tuning.node_mapsession_buffered_chan_size", 30)
298+
viper.SetDefault("tuning.node_registration_cache_expiration", "15m")
299+
viper.SetDefault("tuning.node_registration_cache_cleanup", "20m")
294300

295301
viper.SetDefault("prefixes.allocation", string(IPAllocationStrategySequential))
296302

@@ -935,6 +941,8 @@ func LoadServerConfig() (*Config, error) {
935941
NodeMapSessionBufferedChanSize: viper.GetInt(
936942
"tuning.node_mapsession_buffered_chan_size",
937943
),
944+
NodeRegistrationCacheExpiration: viper.GetDuration("tuning.node_registration_cache_expiration"),
945+
NodeRegistrationCacheCleanup: viper.GetDuration("tuning.node_registration_cache_cleanup"),
938946
},
939947
}, nil
940948
}

0 commit comments

Comments
 (0)