Skip to content

Commit 42a5262

Browse files
authored
cmd/k8s-operator: add multi replica support for recorders (tailscale#17864)
This commit adds the `spec.replicas` field to the `Recorder` custom resource that allows for a highly available deployment of `tsrecorder` within a kubernetes cluster. Many changes were required here as the code hard-coded the assumption of a single replica. This has required a few loops, similar to what we do for the `Connector` resource to create auth and state secrets. It was also required to add a check to remove dangling state and auth secrets should the recorder be scaled down. Updates: tailscale#17965 Signed-off-by: David Bond <[email protected]>
1 parent 682172c commit 42a5262

File tree

10 files changed

+381
-152
lines changed

10 files changed

+381
-152
lines changed

cmd/k8s-operator/deploy/crds/tailscale.com_recorders.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ spec:
6868
Corresponds to --ui tsrecorder flag https://tailscale.com/kb/1246/tailscale-ssh-session-recording#deploy-a-recorder-node.
6969
Required if S3 storage is not set up, to ensure that recordings are accessible.
7070
type: boolean
71+
replicas:
72+
description: Replicas specifies how many instances of tsrecorder to run. Defaults to 1.
73+
type: integer
74+
format: int32
75+
minimum: 0
7176
statefulSet:
7277
description: |-
7378
Configuration parameters for the Recorder's StatefulSet. The operator
@@ -1683,6 +1688,9 @@ spec:
16831688
items:
16841689
type: string
16851690
pattern: ^tag:[a-zA-Z][a-zA-Z0-9-]*$
1691+
x-kubernetes-validations:
1692+
- rule: '!(self.replicas > 1 && (!has(self.storage) || !has(self.storage.s3)))'
1693+
message: S3 storage must be used when deploying multiple Recorder replicas
16861694
status:
16871695
description: |-
16881696
RecorderStatus describes the status of the recorder. This is set

cmd/k8s-operator/deploy/manifests/operator.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3348,6 +3348,11 @@ spec:
33483348
Corresponds to --ui tsrecorder flag https://tailscale.com/kb/1246/tailscale-ssh-session-recording#deploy-a-recorder-node.
33493349
Required if S3 storage is not set up, to ensure that recordings are accessible.
33503350
type: boolean
3351+
replicas:
3352+
description: Replicas specifies how many instances of tsrecorder to run. Defaults to 1.
3353+
format: int32
3354+
minimum: 0
3355+
type: integer
33513356
statefulSet:
33523357
description: |-
33533358
Configuration parameters for the Recorder's StatefulSet. The operator
@@ -4964,6 +4969,9 @@ spec:
49644969
type: string
49654970
type: array
49664971
type: object
4972+
x-kubernetes-validations:
4973+
- message: S3 storage must be used when deploying multiple Recorder replicas
4974+
rule: '!(self.replicas > 1 && (!has(self.storage) || !has(self.storage.s3)))'
49674975
status:
49684976
description: |-
49694977
RecorderStatus describes the status of the recorder. This is set

cmd/k8s-operator/operator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ import (
4444
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
4545
"sigs.k8s.io/controller-runtime/pkg/predicate"
4646
"sigs.k8s.io/controller-runtime/pkg/reconcile"
47-
"tailscale.com/envknob"
4847

4948
"tailscale.com/client/local"
5049
"tailscale.com/client/tailscale"
50+
"tailscale.com/envknob"
5151
"tailscale.com/hostinfo"
5252
"tailscale.com/ipn"
5353
"tailscale.com/ipn/store/kubestore"

0 commit comments

Comments
 (0)