diff --git a/docs/docs/30-administration/10-configuration/11-backends/20-kubernetes.md b/docs/docs/30-administration/10-configuration/11-backends/20-kubernetes.md index f7afbc406..cc7d3f430 100644 --- a/docs/docs/30-administration/10-configuration/11-backends/20-kubernetes.md +++ b/docs/docs/30-administration/10-configuration/11-backends/20-kubernetes.md @@ -404,3 +404,12 @@ Determines if containers must be required to run as non-root users. - Default: none Secret names to pull images from private repositories. See, how to [Pull an Image from a Private Registry](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/). + +--- + +### BACKEND_K8S_PRIORITY_CLASS + +- Name: `WOODPECKER_BACKEND_K8S_PRIORITY_CLASS` +- Default: none, which will use the default priority class configured in Kubernetes + +Which [Kubernetes PriorityClass](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/priority-class-v1/) to assign to created job pods. diff --git a/pipeline/backend/kubernetes/flags.go b/pipeline/backend/kubernetes/flags.go index d866347a1..f71f8c368 100644 --- a/pipeline/backend/kubernetes/flags.go +++ b/pipeline/backend/kubernetes/flags.go @@ -95,4 +95,10 @@ var Flags = []cli.Flag{ Usage: "whether to allow existing Kubernetes secrets to be referenced from steps", Value: false, }, + &cli.StringFlag{ + Sources: cli.EnvVars("WOODPECKER_BACKEND_K8S_PRIORITY_CLASS"), + Name: "backend-k8s-priority-class", + Usage: "which kubernetes priority class to assign to created job pods", + Value: "", + }, } diff --git a/pipeline/backend/kubernetes/kubernetes.go b/pipeline/backend/kubernetes/kubernetes.go index a5919f898..90318175c 100644 --- a/pipeline/backend/kubernetes/kubernetes.go +++ b/pipeline/backend/kubernetes/kubernetes.go @@ -70,6 +70,7 @@ type config struct { ImagePullSecretNames []string SecurityContext SecurityContextConfig NativeSecretsAllowFromStep bool + PriorityClassName string } func (c *config) GetNamespace(orgID int64) string { @@ -103,6 +104,7 @@ func configFromCliContext(ctx context.Context) (*config, error) { StorageClass: c.String("backend-k8s-storage-class"), VolumeSize: c.String("backend-k8s-volume-size"), StorageRwx: c.Bool("backend-k8s-storage-rwx"), + PriorityClassName: c.String("backend-k8s-priority-class"), PodLabels: make(map[string]string), // just init empty map to prevent nil panic PodLabelsAllowFromStep: c.Bool("backend-k8s-pod-labels-allow-from-step"), PodAnnotations: make(map[string]string), // just init empty map to prevent nil panic diff --git a/pipeline/backend/kubernetes/pod.go b/pipeline/backend/kubernetes/pod.go index d595e722b..f591d50d9 100644 --- a/pipeline/backend/kubernetes/pod.go +++ b/pipeline/backend/kubernetes/pod.go @@ -173,6 +173,7 @@ func podSpec(step *types.Step, config *config, options BackendOptions, nsp nativ RestartPolicy: v1.RestartPolicyNever, RuntimeClassName: options.RuntimeClassName, ServiceAccountName: options.ServiceAccountName, + PriorityClassName: config.PriorityClassName, HostAliases: hostAliases(step.ExtraHosts), NodeSelector: nodeSelector(options.NodeSelector, config.PodNodeSelector, step.Environment["CI_SYSTEM_PLATFORM"]), Tolerations: tolerations(options.Tolerations),