Skip to content

Commit f2fd7a0

Browse files
jaxxstormtomhjp
andauthored
cmd/k8s-operator,k8s-operator: allow setting a priorityClassName (tailscale#16685)
* cmd/k8s-operator,k8s-operator: allow setting a `priorityClassName` Fixes tailscale#16682 Signed-off-by: Lee Briggs <[email protected]> * Update k8s-operator/apis/v1alpha1/types_proxyclass.go Co-authored-by: Tom Proctor <[email protected]> Signed-off-by: Lee Briggs <[email protected]> * run make kube-generate-all Change-Id: I5f8f16694fdc181b048217b9f05ec2ee2aa04def Signed-off-by: Tom Proctor <[email protected]> --------- Signed-off-by: Lee Briggs <[email protected]> Signed-off-by: Lee Briggs <[email protected]> Signed-off-by: Tom Proctor <[email protected]> Co-authored-by: Tom Proctor <[email protected]>
1 parent 23a0398 commit f2fd7a0

File tree

6 files changed

+22
-0
lines changed

6 files changed

+22
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,12 @@ spec:
10931093
type: object
10941094
additionalProperties:
10951095
type: string
1096+
priorityClassName:
1097+
description: |-
1098+
PriorityClassName for the proxy Pod.
1099+
By default Tailscale Kubernetes operator does not apply any priority class.
1100+
https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#scheduling
1101+
type: string
10961102
securityContext:
10971103
description: |-
10981104
Proxy Pod's security context.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,12 @@ spec:
15741574
selector.
15751575
https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#scheduling
15761576
type: object
1577+
priorityClassName:
1578+
description: |-
1579+
PriorityClassName for the proxy Pod.
1580+
By default Tailscale Kubernetes operator does not apply any priority class.
1581+
https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#scheduling
1582+
type: string
15771583
securityContext:
15781584
description: |-
15791585
Proxy Pod's security context.

cmd/k8s-operator/sts.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ func applyProxyClassToStatefulSet(pc *tsapi.ProxyClass, ss *appsv1.StatefulSet,
809809
ss.Spec.Template.Spec.NodeSelector = wantsPod.NodeSelector
810810
ss.Spec.Template.Spec.Affinity = wantsPod.Affinity
811811
ss.Spec.Template.Spec.Tolerations = wantsPod.Tolerations
812+
ss.Spec.Template.Spec.PriorityClassName = wantsPod.PriorityClassName
812813
ss.Spec.Template.Spec.TopologySpreadConstraints = wantsPod.TopologySpreadConstraints
813814

814815
// Update containers.

cmd/k8s-operator/sts_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func Test_applyProxyClassToStatefulSet(t *testing.T) {
7676
NodeSelector: map[string]string{"beta.kubernetes.io/os": "linux"},
7777
Affinity: &corev1.Affinity{NodeAffinity: &corev1.NodeAffinity{RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{}}},
7878
Tolerations: []corev1.Toleration{{Key: "", Operator: "Exists"}},
79+
PriorityClassName: "high-priority",
7980
TopologySpreadConstraints: []corev1.TopologySpreadConstraint{
8081
{
8182
WhenUnsatisfiable: "DoNotSchedule",
@@ -198,6 +199,7 @@ func Test_applyProxyClassToStatefulSet(t *testing.T) {
198199
wantSS.Spec.Template.Spec.Containers[0].ImagePullPolicy = "IfNotPresent"
199200
wantSS.Spec.Template.Spec.InitContainers[0].Image = "ghcr.io/my-repo/tailscale:v0.01testsomething"
200201
wantSS.Spec.Template.Spec.InitContainers[0].ImagePullPolicy = "IfNotPresent"
202+
wantSS.Spec.Template.Spec.PriorityClassName = proxyClassAllOpts.Spec.StatefulSet.Pod.PriorityClassName
201203

202204
gotSS := applyProxyClassToStatefulSet(proxyClassAllOpts, nonUserspaceProxySS.DeepCopy(), new(tailscaleSTSConfig), zl.Sugar())
203205
if diff := cmp.Diff(gotSS, wantSS); diff != "" {
@@ -236,6 +238,7 @@ func Test_applyProxyClassToStatefulSet(t *testing.T) {
236238
wantSS.Spec.Template.Spec.Containers[0].Env = append(wantSS.Spec.Template.Spec.Containers[0].Env, []corev1.EnvVar{{Name: "foo", Value: "bar"}, {Name: "TS_USERSPACE", Value: "true"}, {Name: "bar"}}...)
237239
wantSS.Spec.Template.Spec.Containers[0].ImagePullPolicy = "IfNotPresent"
238240
wantSS.Spec.Template.Spec.Containers[0].Image = "ghcr.io/my-repo/tailscale:v0.01testsomething"
241+
wantSS.Spec.Template.Spec.PriorityClassName = proxyClassAllOpts.Spec.StatefulSet.Pod.PriorityClassName
239242
gotSS = applyProxyClassToStatefulSet(proxyClassAllOpts, userspaceProxySS.DeepCopy(), new(tailscaleSTSConfig), zl.Sugar())
240243
if diff := cmp.Diff(gotSS, wantSS); diff != "" {
241244
t.Errorf("Unexpected result applying ProxyClass with all options to a StatefulSet for a userspace proxy (-got +want):\n%s", diff)

k8s-operator/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ _Appears in:_
515515
| `nodeSelector` _object (keys:string, values:string)_ | Proxy Pod's node selector.<br />By default Tailscale Kubernetes operator does not apply any node<br />selector.<br />https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#scheduling | | |
516516
| `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 | | |
517517
| `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/ | | |
518+
| `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 | | |
518519

519520

520521
#### PortRange

k8s-operator/apis/v1alpha1/types_proxyclass.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ type Pod struct {
298298
// https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/
299299
// +optional
300300
TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
301+
// PriorityClassName for the proxy Pod.
302+
// By default Tailscale Kubernetes operator does not apply any priority class.
303+
// https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#scheduling
304+
// +optional
305+
PriorityClassName string `json:"priorityClassName,omitempty"`
301306
}
302307

303308
// +kubebuilder:validation:XValidation:rule="!(has(self.serviceMonitor) && self.serviceMonitor.enable && !self.enable)",message="ServiceMonitor can only be enabled if metrics are enabled"

0 commit comments

Comments
 (0)