mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-30 21:42:48 -08:00
k8s-operator: allow setting runtimeClassName via ProxyClass (#22686)
* k8s-operator: allow setting runtimeClassName via ProxyClass Add a runtimeClassName field to the ProxyClass CRD's pod spec, next to priorityClassName, and propagate it to the proxy StatefulSet pod spec. This lets users run proxy pods under a non-default RuntimeClass, for example one provided by a confidential-computing or sandboxed runtime. Updates tailscale/tailscale#21843 Signed-off-by: Abdelrahman Rabie <[email protected]> * k8s-operator: regenerate manifests and API reference Signed-off-by: Abdelrahman Rabie <[email protected]> * k8s-operator: use omitzero for ProxyClass runtimeClassName The vet check requires omitzero on pointer fields that are optional. Updates #21843 Assisted-by: AI tool Signed-off-by: Abdelrahman Rabie <[email protected]> --------- Signed-off-by: Abdelrahman Rabie <[email protected]>
This commit is contained in:
1 parent
2bebbebc9b
commit
03aa2c47f0
9 files changed
+57
No files matched your search
@@ -1147,6 +1147,12 @@ spec:
|
||||
By default Tailscale Kubernetes operator does not apply any priority class.
|
||||
https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#scheduling
|
||||
type: string
|
||||
runtimeClassName:
|
||||
description: |-
|
||||
RuntimeClassName for the proxy Pod.
|
||||
By default Tailscale Kubernetes operator does not apply any runtime class.
|
||||
https://kubernetes.io/docs/concepts/containers/runtime-class/
|
||||
type: string
|
||||
securityContext:
|
||||
description: |-
|
||||
Proxy Pod's security context.
|
||||
|
||||
@@ -2951,6 +2951,12 @@ spec:
|
||||
By default Tailscale Kubernetes operator does not apply any priority class.
|
||||
https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#scheduling
|
||||
type: string
|
||||
runtimeClassName:
|
||||
description: |-
|
||||
RuntimeClassName for the proxy Pod.
|
||||
By default Tailscale Kubernetes operator does not apply any runtime class.
|
||||
https://kubernetes.io/docs/concepts/containers/runtime-class/
|
||||
type: string
|
||||
securityContext:
|
||||
description: |-
|
||||
Proxy Pod's security context.
|
||||
|
||||
@@ -1141,6 +1141,7 @@ func applyProxyClassToStatefulSet(pc *tsapi.ProxyClass, ss *appsv1.StatefulSet,
|
||||
ss.Spec.Template.Spec.Affinity = wantsPod.Affinity
|
||||
ss.Spec.Template.Spec.Tolerations = wantsPod.Tolerations
|
||||
ss.Spec.Template.Spec.PriorityClassName = wantsPod.PriorityClassName
|
||||
ss.Spec.Template.Spec.RuntimeClassName = wantsPod.RuntimeClassName
|
||||
ss.Spec.Template.Spec.TopologySpreadConstraints = wantsPod.TopologySpreadConstraints
|
||||
if wantsPod.DNSPolicy != nil {
|
||||
ss.Spec.Template.Spec.DNSPolicy = *wantsPod.DNSPolicy
|
||||
|
||||
@@ -78,6 +78,7 @@ func Test_applyProxyClassToStatefulSet(t *testing.T) {
|
||||
Affinity: &corev1.Affinity{NodeAffinity: &corev1.NodeAffinity{RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{}}},
|
||||
Tolerations: []corev1.Toleration{{Key: "", Operator: "Exists"}},
|
||||
PriorityClassName: "high-priority",
|
||||
RuntimeClassName: new("some-runtime"),
|
||||
TopologySpreadConstraints: []corev1.TopologySpreadConstraint{
|
||||
{
|
||||
WhenUnsatisfiable: "DoNotSchedule",
|
||||
@@ -210,6 +211,7 @@ func Test_applyProxyClassToStatefulSet(t *testing.T) {
|
||||
wantSS.Spec.Template.Spec.InitContainers[0].Image = "ghcr.io/my-repo/tailscale:v0.01testsomething"
|
||||
wantSS.Spec.Template.Spec.InitContainers[0].ImagePullPolicy = "IfNotPresent"
|
||||
wantSS.Spec.Template.Spec.PriorityClassName = proxyClassAllOpts.Spec.StatefulSet.Pod.PriorityClassName
|
||||
wantSS.Spec.Template.Spec.RuntimeClassName = proxyClassAllOpts.Spec.StatefulSet.Pod.RuntimeClassName
|
||||
wantSS.Spec.Template.Spec.DNSPolicy = corev1.DNSClusterFirstWithHostNet
|
||||
wantSS.Spec.Template.Spec.DNSConfig = proxyClassAllOpts.Spec.StatefulSet.Pod.DNSConfig
|
||||
|
||||
@@ -251,6 +253,7 @@ func Test_applyProxyClassToStatefulSet(t *testing.T) {
|
||||
wantSS.Spec.Template.Spec.Containers[0].ImagePullPolicy = "IfNotPresent"
|
||||
wantSS.Spec.Template.Spec.Containers[0].Image = "ghcr.io/my-repo/tailscale:v0.01testsomething"
|
||||
wantSS.Spec.Template.Spec.PriorityClassName = proxyClassAllOpts.Spec.StatefulSet.Pod.PriorityClassName
|
||||
wantSS.Spec.Template.Spec.RuntimeClassName = proxyClassAllOpts.Spec.StatefulSet.Pod.RuntimeClassName
|
||||
wantSS.Spec.Template.Spec.DNSPolicy = corev1.DNSClusterFirstWithHostNet
|
||||
wantSS.Spec.Template.Spec.DNSConfig = proxyClassAllOpts.Spec.StatefulSet.Pod.DNSConfig
|
||||
gotSS = applyProxyClassToStatefulSet(proxyClassAllOpts, userspaceProxySS.DeepCopy(), new(tailscaleSTSConfig), zl.Sugar())
|
||||
|
||||
@@ -730,6 +730,7 @@ _Appears in:_
|
||||
| `tolerations` _[Toleration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.3/#toleration-v1-core) array_ | Proxy Pod's tolerations.<br />By default Tailscale Kubernetes operator does not apply any<br />tolerations.<br />https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#scheduling | | Optional: \{\} <br /> |
|
||||
| `topologySpreadConstraints` _[TopologySpreadConstraint](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.3/#topologyspreadconstraint-v1-core) array_ | Proxy Pod's topology spread constraints.<br />By default Tailscale Kubernetes operator does not apply any topology spread constraints.<br />https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/ | | Optional: \{\} <br /> |
|
||||
| `priorityClassName` _string_ | PriorityClassName for the proxy Pod.<br />By default Tailscale Kubernetes operator does not apply any priority class.<br />https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#scheduling | | Optional: \{\} <br /> |
|
||||
| `runtimeClassName` _string_ | RuntimeClassName for the proxy Pod.<br />By default Tailscale Kubernetes operator does not apply any runtime class.<br />https://kubernetes.io/docs/concepts/containers/runtime-class/ | | Optional: \{\} <br /> |
|
||||
| `dnsPolicy` _[DNSPolicy](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.3/#dnspolicy-v1-core)_ | DNSPolicy defines how DNS will be configured for the proxy Pod.<br />By default the Tailscale Kubernetes Operator does not set a DNS policy (uses cluster default).<br />https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-dns-policy | | Enum: [ClusterFirstWithHostNet ClusterFirst Default None] <br />Optional: \{\} <br /> |
|
||||
| `dnsConfig` _[PodDNSConfig](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.3/#poddnsconfig-v1-core)_ | DNSConfig defines DNS parameters for the proxy Pod in addition to those generated from DNSPolicy.<br />When DNSPolicy is set to "None", DNSConfig must be specified.<br />https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-dns-config | | Optional: \{\} <br /> |
|
||||
|
||||
|
||||
@@ -303,6 +303,11 @@ type Pod struct {
|
||||
// https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#scheduling
|
||||
// +optional
|
||||
PriorityClassName string `json:"priorityClassName,omitempty"`
|
||||
// RuntimeClassName for the proxy Pod.
|
||||
// By default Tailscale Kubernetes operator does not apply any runtime class.
|
||||
// https://kubernetes.io/docs/concepts/containers/runtime-class/
|
||||
// +optional
|
||||
RuntimeClassName *string `json:"runtimeClassName,omitzero"`
|
||||
// DNSPolicy defines how DNS will be configured for the proxy Pod.
|
||||
// By default the Tailscale Kubernetes Operator does not set a DNS policy (uses cluster default).
|
||||
// https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-dns-policy
|
||||
|
||||
@@ -846,6 +846,11 @@ func (in *Pod) DeepCopyInto(out *Pod) {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
if in.RuntimeClassName != nil {
|
||||
in, out := &in.RuntimeClassName, &out.RuntimeClassName
|
||||
*out = new(string)
|
||||
**out = **in
|
||||
}
|
||||
if in.DNSPolicy != nil {
|
||||
in, out := &in.DNSPolicy, &out.DNSPolicy
|
||||
*out = new(corev1.DNSPolicy)
|
||||
|
||||
@@ -57,6 +57,7 @@ func ApplyProxyClass(ss *appsv1.StatefulSet, pc *tsapi.ProxyClass, managedLabels
|
||||
ss.Spec.Template.Spec.Affinity = wantsPod.Affinity
|
||||
ss.Spec.Template.Spec.Tolerations = wantsPod.Tolerations
|
||||
ss.Spec.Template.Spec.PriorityClassName = wantsPod.PriorityClassName
|
||||
ss.Spec.Template.Spec.RuntimeClassName = wantsPod.RuntimeClassName
|
||||
ss.Spec.Template.Spec.TopologySpreadConstraints = wantsPod.TopologySpreadConstraints
|
||||
|
||||
if wantsPod.DNSPolicy != nil {
|
||||
|
||||
@@ -58,3 +58,32 @@ func TestApplyProxyClass_Env(t *testing.T) {
|
||||
t.Errorf("container env mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyProxyClass_RuntimeClassName(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Unset: no runtime class is applied.
|
||||
ss := &appsv1.StatefulSet{}
|
||||
pc := &tsapi.ProxyClass{
|
||||
Spec: tsapi.ProxyClassSpec{
|
||||
StatefulSet: &tsapi.StatefulSet{Pod: &tsapi.Pod{}},
|
||||
},
|
||||
}
|
||||
if got := tailscaled.ApplyProxyClass(ss, pc, nil, nil).Spec.Template.Spec.RuntimeClassName; got != nil {
|
||||
t.Errorf("RuntimeClassName = %v, want nil", *got)
|
||||
}
|
||||
|
||||
// Set: the runtime class from ProxyClass is applied to the proxy Pod.
|
||||
ss = &appsv1.StatefulSet{}
|
||||
pc = &tsapi.ProxyClass{
|
||||
Spec: tsapi.ProxyClassSpec{
|
||||
StatefulSet: &tsapi.StatefulSet{
|
||||
Pod: &tsapi.Pod{RuntimeClassName: new("some-runtime")},
|
||||
},
|
||||
},
|
||||
}
|
||||
got := tailscaled.ApplyProxyClass(ss, pc, nil, nil).Spec.Template.Spec.RuntimeClassName
|
||||
if got == nil || *got != "some-runtime" {
|
||||
t.Errorf("RuntimeClassName = %v, want %q", got, "some-runtime")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user