Add runtimeClassName in Kubernetes backend options (#3474)

Resolves #3473

---------

Co-authored-by: Thomas Anderson <127358482+zc-devs@users.noreply.github.com>
This commit is contained in:
YR Chen 2024-03-29 17:29:07 +08:00 committed by GitHub
parent 2029813fc2
commit e1b574a4bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 14 additions and 0 deletions

View file

@ -40,6 +40,11 @@ steps:
You can use [Limit Ranges](https://kubernetes.io/docs/concepts/policy/limit-range/) if you want to set the limits by per-namespace basis. You can use [Limit Ranges](https://kubernetes.io/docs/concepts/policy/limit-range/) if you want to set the limits by per-namespace basis.
### Runtime class
`runtimeClassName` specifies the name of the RuntimeClass which will be used to run this pod. If no `runtimeClassName` is specified, the default RuntimeHandler will be used.
See the [kubernetes documentation](https://kubernetes.io/docs/concepts/containers/runtime-class/) for more information on specifying runtime classes.
### Service account ### Service account
`serviceAccountName` specifies the name of the ServiceAccount which the pod will mount. This service account must be created externally. `serviceAccountName` specifies the name of the ServiceAccount which the pod will mount. This service account must be created externally.

View file

@ -9,6 +9,7 @@ import (
// BackendOptions defines all the advanced options for the kubernetes backend // BackendOptions defines all the advanced options for the kubernetes backend
type BackendOptions struct { type BackendOptions struct {
Resources Resources `mapstructure:"resources"` Resources Resources `mapstructure:"resources"`
RuntimeClassName *string `mapstructure:"runtimeClassName"`
ServiceAccountName string `mapstructure:"serviceAccountName"` ServiceAccountName string `mapstructure:"serviceAccountName"`
NodeSelector map[string]string `mapstructure:"nodeSelector"` NodeSelector map[string]string `mapstructure:"nodeSelector"`
Tolerations []Toleration `mapstructure:"tolerations"` Tolerations []Toleration `mapstructure:"tolerations"`

View file

@ -117,6 +117,7 @@ func podSpec(step *types.Step, config *config, options BackendOptions) (v1.PodSp
var err error var err error
spec := v1.PodSpec{ spec := v1.PodSpec{
RestartPolicy: v1.RestartPolicyNever, RestartPolicy: v1.RestartPolicyNever,
RuntimeClassName: options.RuntimeClassName,
ServiceAccountName: options.ServiceAccountName, ServiceAccountName: options.ServiceAccountName,
ImagePullSecrets: imagePullSecretsReferences(config.ImagePullSecretNames), ImagePullSecrets: imagePullSecretsReferences(config.ImagePullSecretNames),
HostAliases: hostAliases(step.ExtraHosts), HostAliases: hostAliases(step.ExtraHosts),

View file

@ -245,6 +245,7 @@ func TestFullPod(t *testing.T) {
"nodeSelector": { "nodeSelector": {
"storage": "ssd" "storage": "ssd"
}, },
"runtimeClassName": "runc",
"serviceAccountName": "wp-svc-acc", "serviceAccountName": "wp-svc-acc",
"securityContext": { "securityContext": {
"runAsUser": 101, "runAsUser": 101,
@ -289,6 +290,7 @@ func TestFullPod(t *testing.T) {
"status": {} "status": {}
}` }`
runtimeClass := "runc"
hostAliases := []types.HostAlias{ hostAliases := []types.HostAlias{
{Name: "cloudflare", IP: "1.1.1.1"}, {Name: "cloudflare", IP: "1.1.1.1"},
{Name: "cf.v6", IP: "2606:4700:4700::64"}, {Name: "cf.v6", IP: "2606:4700:4700::64"},
@ -333,6 +335,7 @@ func TestFullPod(t *testing.T) {
SecurityContext: SecurityContextConfig{RunAsNonRoot: false}, SecurityContext: SecurityContextConfig{RunAsNonRoot: false},
}, "wp-01he8bebctabr3kgk0qj36d2me-0", "linux/amd64", BackendOptions{ }, "wp-01he8bebctabr3kgk0qj36d2me-0", "linux/amd64", BackendOptions{
NodeSelector: map[string]string{"storage": "ssd"}, NodeSelector: map[string]string{"storage": "ssd"},
RuntimeClassName: &runtimeClass,
ServiceAccountName: "wp-svc-acc", ServiceAccountName: "wp-svc-acc",
Tolerations: []Toleration{{Key: "net-port", Value: "100Mbit", Effect: TaintEffectNoSchedule}}, Tolerations: []Toleration{{Key: "net-port", Value: "100Mbit", Effect: TaintEffectNoSchedule}},
Resources: Resources{ Resources: Resources{

View file

@ -696,6 +696,10 @@
}, },
"securityContext": { "securityContext": {
"$ref": "#/definitions/step_backend_kubernetes_security_context" "$ref": "#/definitions/step_backend_kubernetes_security_context"
},
"runtimeClassName": {
"description": "Read more: https://woodpecker-ci.org/docs/administration/backends/kubernetes#runtimeclassname",
"type": "string"
} }
} }
}, },