Add validation of setup key duration (#199)

This adds more validation to the setup key duration to make sure the
unit and format is correct.
This commit is contained in:
Philip Laine
2026-04-23 11:47:17 +02:00
committed by GitHub
parent 38f2a8cb99
commit 20a3ddd4ed
3 changed files with 6 additions and 2 deletions
+3 -1
View File
@@ -15,8 +15,10 @@ type SetupKeySpec struct {
Ephemeral bool `json:"ephemeral"` Ephemeral bool `json:"ephemeral"`
// Duration sets how long the setup key is valid for. // Duration sets how long the setup key is valid for.
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="duration is immutable"
// +optional // +optional
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(m|h))+$"
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="duration is immutable"
Duration *metav1.Duration `json:"duration,omitempty"` Duration *metav1.Duration `json:"duration,omitempty"`
// AutoGroups are groups that will be automatically assigned to peers using setup key. // AutoGroups are groups that will be automatically assigned to peers using setup key.
+2 -1
View File
@@ -2,6 +2,7 @@ apiVersion: netbird.io/v1alpha1
kind: SetupKey kind: SetupKey
metadata: metadata:
name: test name: test
namespace: netbird namespace: default
spec: spec:
name: test name: test
ephemeral: true
@@ -77,6 +77,7 @@ spec:
type: array type: array
duration: duration:
description: Duration sets how long the setup key is valid for. description: Duration sets how long the setup key is valid for.
pattern: ^([0-9]+(\.[0-9]+)?(m|h))+$
type: string type: string
x-kubernetes-validations: x-kubernetes-validations:
- message: duration is immutable - message: duration is immutable