feat(k8s): k8s priority class name config (#5391)

This commit is contained in:
Lilly 2025-08-09 16:33:47 +02:00 committed by GitHub
parent 0eb10d1e04
commit 147256e3a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 0 deletions

View file

@ -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.

View file

@ -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: "",
},
}

View file

@ -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

View file

@ -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),