Project: Longhorn (Runtime / Cloud Native Storage)
File: 20231204-default-priority-class.md

Pods can have priority which indicates the importance of a pod relative to other pods. Longhorn pods will face unexpected eviction due to insufficient cluster resources or being preempted by higher-priority pods A PriorityClass defines a mapping from a priority class name to the integer value of the priority, where a higher value signifies greater priority.. Reduce the opportunity of the unexpected eviction of Longhorn pods. `None` Have a default priority class with the highest value to all Longhorn pods. After a fresh installation or an upgrade, users will have Longhorn pods with the field `priorityClassName: longhorn-critical` in `spec` to prevent Longhorn pods from unexpected eviction. For install, the priority class will not be set using the default value if the value has been provided by users. For upgrade, the priority class will not be set using the default value if the settings already exists. For a fresh install, the default priority class will be set if there is no priority class set by users. The setting of the priority class will be updated. For an upgrade, if all volumes are detached and the setting of the priority class is empty, the setting should be applied including user-managed components. The setting of the priority class will be updated because the source of truth of settings is the config map (longhorn-default-setting). For an upgrade, no matter weather all volumes are detached or not, if the setting of the priority class has been set, the setting should not be updated with the default priority class. For an upgrade, if volumes are attached, the setting should be applied to the user-managed components only if they haven't been set. The setting of the priority class will not be updated. NOTE: Before modifying the setting `priority-class`, all Longhorn volumes must be detached. `None` Adding a new template YAML file in the Longhorn chart/templates to create a default priority class. ```yaml apiVersion: scheduling.k8s.io/v1 kind: PriorityClass metadata: name: longhorn-critical value: 1000000000 description: "Ensure Longhorn pods have the highest priority to prevent any unexpected eviction by the Kubernetes scheduler under node pressure" globalDefault: false preemptionPolicy: PreemptLowerPriority ``` Set the `defaultSettings.priorityClass` to `longhorn-critical` and `priorityClass` of Longhorn components in the value.yaml of Longhorn chart. ```yaml ... defaultSettings: ... priorityClass: &defaultPriorityClassNameRef "longhorn-critical" ... longhornManager: log: format: plain priorityClass: *defaultPriorityClassNameRef longhornDriver: priorityClass: *defaultPriorityClassNameRef longhornUI: priorityClass: *defaultPriorityClassNameRef ``` Modify the test case `testsettingpriority_class` to check if there is a default priority class `longhorn-critical` existing. Add a test case where the `defaultSettings.priorityClass` has been modified by users and the setting `priority-class` should be the same to the value provided by users after a fresh install. Add a test case where the setting `priority-class` will be updated if all volumes are detached and the setting of the priority class is not set for an upgrade. Add a test case where the setting `priority-class` will not be updated after the upgrade if any volume is attached. Add a test case where the setting `priority-class` will not be updated if the setting of the priority class has been set for an upgrade. When adding a priority class, all Longhorn volumes must be detached. Therefore we will not change the setting `priority-class` if there is any volume attached to the node or the setting `priority-class` is set to a priority class. `None`