Commit 884673c8 authored by Brad Davidson's avatar Brad Davidson Committed by Brad Davidson

Add support for svclb pod PriorityClassName

Signed-off-by: 's avatarBrad Davidson <brad.davidson@rancher.com> (cherry picked from commit 37f97b33) Signed-off-by: 's avatarBrad Davidson <brad.davidson@rancher.com>
parent 064c9cfc
...@@ -28,6 +28,7 @@ import ( ...@@ -28,6 +28,7 @@ import (
// Config describes externally-configurable cloud provider configuration. // Config describes externally-configurable cloud provider configuration.
// This is normally unmarshalled from a JSON config file. // This is normally unmarshalled from a JSON config file.
type Config struct { type Config struct {
LBDefaultPriorityClassName string `json:"lbDefaultPriorityClassName"`
LBEnabled bool `json:"lbEnabled"` LBEnabled bool `json:"lbEnabled"`
LBImage string `json:"lbImage"` LBImage string `json:"lbImage"`
LBNamespace string `json:"lbNamespace"` LBNamespace string `json:"lbNamespace"`
...@@ -56,6 +57,7 @@ func init() { ...@@ -56,6 +57,7 @@ func init() {
var err error var err error
k := k3s{ k := k3s{
Config: Config{ Config: Config{
LBDefaultPriorityClassName: DefaultLBPriorityClassName,
LBEnabled: true, LBEnabled: true,
LBImage: DefaultLBImage, LBImage: DefaultLBImage,
LBNamespace: DefaultLBNS, LBNamespace: DefaultLBNS,
......
...@@ -39,12 +39,14 @@ var ( ...@@ -39,12 +39,14 @@ var (
daemonsetNodeLabel = "svccontroller." + version.Program + ".cattle.io/enablelb" daemonsetNodeLabel = "svccontroller." + version.Program + ".cattle.io/enablelb"
daemonsetNodePoolLabel = "svccontroller." + version.Program + ".cattle.io/lbpool" daemonsetNodePoolLabel = "svccontroller." + version.Program + ".cattle.io/lbpool"
nodeSelectorLabel = "svccontroller." + version.Program + ".cattle.io/nodeselector" nodeSelectorLabel = "svccontroller." + version.Program + ".cattle.io/nodeselector"
priorityAnnotation = "svccontroller." + version.Program + ".cattle.io/priorityclassname"
controllerName = ccmapp.DefaultInitFuncConstructors["service"].InitContext.ClientName controllerName = ccmapp.DefaultInitFuncConstructors["service"].InitContext.ClientName
) )
const ( const (
Ready = condition.Cond("Ready") Ready = condition.Cond("Ready")
DefaultLBNS = meta.NamespaceSystem DefaultLBNS = meta.NamespaceSystem
DefaultLBPriorityClassName = "system-node-critical"
) )
var ( var (
...@@ -426,6 +428,7 @@ func (k *k3s) deleteDaemonSet(ctx context.Context, svc *core.Service) error { ...@@ -426,6 +428,7 @@ func (k *k3s) deleteDaemonSet(ctx context.Context, svc *core.Service) error {
func (k *k3s) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) { func (k *k3s) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) {
name := generateName(svc) name := generateName(svc)
oneInt := intstr.FromInt(1) oneInt := intstr.FromInt(1)
priorityClassName := k.getPriorityClassName(svc)
localTraffic := servicehelper.RequestsOnlyLocalTraffic(svc) localTraffic := servicehelper.RequestsOnlyLocalTraffic(svc)
sourceRangesSet, err := servicehelper.GetLoadBalancerSourceRanges(svc) sourceRangesSet, err := servicehelper.GetLoadBalancerSourceRanges(svc)
if err != nil { if err != nil {
...@@ -470,6 +473,7 @@ func (k *k3s) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) { ...@@ -470,6 +473,7 @@ func (k *k3s) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) {
}, },
}, },
Spec: core.PodSpec{ Spec: core.PodSpec{
PriorityClassName: priorityClassName,
ServiceAccountName: "svclb", ServiceAccountName: "svclb",
AutomountServiceAccountToken: utilsptr.To(false), AutomountServiceAccountToken: utilsptr.To(false),
SecurityContext: &core.PodSecurityContext{ SecurityContext: &core.PodSecurityContext{
...@@ -680,6 +684,17 @@ func (k *k3s) removeFinalizer(ctx context.Context, svc *core.Service) (*core.Ser ...@@ -680,6 +684,17 @@ func (k *k3s) removeFinalizer(ctx context.Context, svc *core.Service) (*core.Ser
return svc, nil return svc, nil
} }
// getPriorityClassName returns the value of the priority class name annotation on the service,
// or the system default priority class name.
func (k *k3s) getPriorityClassName(svc *core.Service) string {
if svc != nil {
if v, ok := svc.Annotations[priorityAnnotation]; ok {
return v
}
}
return k.LBDefaultPriorityClassName
}
// generateName generates a distinct name for the DaemonSet based on the service name and UID // generateName generates a distinct name for the DaemonSet based on the service name and UID
func generateName(svc *core.Service) string { func generateName(svc *core.Service) string {
return fmt.Sprintf("svclb-%s-%s", svc.Name, svc.UID[:8]) return fmt.Sprintf("svclb-%s-%s", svc.Name, svc.UID[:8])
......
...@@ -829,6 +829,7 @@ func genEgressSelectorConfig(controlConfig *config.Control) error { ...@@ -829,6 +829,7 @@ func genEgressSelectorConfig(controlConfig *config.Control) error {
func genCloudConfig(controlConfig *config.Control) error { func genCloudConfig(controlConfig *config.Control) error {
cloudConfig := cloudprovider.Config{ cloudConfig := cloudprovider.Config{
LBDefaultPriorityClassName: cloudprovider.DefaultLBPriorityClassName,
LBEnabled: !controlConfig.DisableServiceLB, LBEnabled: !controlConfig.DisableServiceLB,
LBNamespace: controlConfig.ServiceLBNamespace, LBNamespace: controlConfig.ServiceLBNamespace,
LBImage: cloudprovider.DefaultLBImage, LBImage: cloudprovider.DefaultLBImage,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment