2024-02-08 17:39:32 +00:00
|
|
|
package kubernetes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mitchellh/mapstructure"
|
|
|
|
|
|
|
|
backend "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types"
|
|
|
|
)
|
|
|
|
|
2024-05-13 20:58:21 +00:00
|
|
|
// BackendOptions defines all the advanced options for the kubernetes backend.
|
2024-02-08 17:39:32 +00:00
|
|
|
type BackendOptions struct {
|
|
|
|
Resources Resources `mapstructure:"resources"`
|
2024-03-29 09:29:07 +00:00
|
|
|
RuntimeClassName *string `mapstructure:"runtimeClassName"`
|
2024-02-08 17:39:32 +00:00
|
|
|
ServiceAccountName string `mapstructure:"serviceAccountName"`
|
2024-05-11 09:45:29 +00:00
|
|
|
Labels map[string]string `mapstructure:"labels"`
|
|
|
|
Annotations map[string]string `mapstructure:"annotations"`
|
2024-02-08 17:39:32 +00:00
|
|
|
NodeSelector map[string]string `mapstructure:"nodeSelector"`
|
|
|
|
Tolerations []Toleration `mapstructure:"tolerations"`
|
|
|
|
SecurityContext *SecurityContext `mapstructure:"securityContext"`
|
2024-06-23 16:20:21 +00:00
|
|
|
Secrets []SecretRef `mapstructure:"secrets"`
|
2024-02-08 17:39:32 +00:00
|
|
|
}
|
|
|
|
|
2024-05-13 20:58:21 +00:00
|
|
|
// Resources defines two maps for kubernetes resource definitions.
|
2024-02-08 17:39:32 +00:00
|
|
|
type Resources struct {
|
|
|
|
Requests map[string]string `mapstructure:"requests"`
|
|
|
|
Limits map[string]string `mapstructure:"limits"`
|
|
|
|
}
|
|
|
|
|
2024-05-13 20:58:21 +00:00
|
|
|
// Toleration defines Kubernetes toleration.
|
2024-02-08 17:39:32 +00:00
|
|
|
type Toleration struct {
|
|
|
|
Key string `mapstructure:"key"`
|
|
|
|
Operator TolerationOperator `mapstructure:"operator"`
|
|
|
|
Value string `mapstructure:"value"`
|
|
|
|
Effect TaintEffect `mapstructure:"effect"`
|
|
|
|
TolerationSeconds *int64 `mapstructure:"tolerationSeconds"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type TaintEffect string
|
|
|
|
|
|
|
|
const (
|
|
|
|
TaintEffectNoSchedule TaintEffect = "NoSchedule"
|
|
|
|
TaintEffectPreferNoSchedule TaintEffect = "PreferNoSchedule"
|
|
|
|
TaintEffectNoExecute TaintEffect = "NoExecute"
|
|
|
|
)
|
|
|
|
|
|
|
|
type TolerationOperator string
|
|
|
|
|
|
|
|
const (
|
|
|
|
TolerationOpExists TolerationOperator = "Exists"
|
|
|
|
TolerationOpEqual TolerationOperator = "Equal"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SecurityContext struct {
|
|
|
|
Privileged *bool `mapstructure:"privileged"`
|
|
|
|
RunAsNonRoot *bool `mapstructure:"runAsNonRoot"`
|
|
|
|
RunAsUser *int64 `mapstructure:"runAsUser"`
|
|
|
|
RunAsGroup *int64 `mapstructure:"runAsGroup"`
|
|
|
|
FSGroup *int64 `mapstructure:"fsGroup"`
|
|
|
|
SeccompProfile *SecProfile `mapstructure:"seccompProfile"`
|
|
|
|
ApparmorProfile *SecProfile `mapstructure:"apparmorProfile"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type SecProfile struct {
|
|
|
|
Type SecProfileType `mapstructure:"type"`
|
|
|
|
LocalhostProfile string `mapstructure:"localhostProfile"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type SecProfileType string
|
|
|
|
|
2024-06-23 16:20:21 +00:00
|
|
|
// SecretRef defines Kubernetes secret reference.
|
|
|
|
type SecretRef struct {
|
|
|
|
Name string `mapstructure:"name"`
|
|
|
|
Key string `mapstructure:"key"`
|
|
|
|
Target SecretTarget `mapstructure:"target"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// SecretTarget defines secret mount target.
|
|
|
|
type SecretTarget struct {
|
|
|
|
Env string `mapstructure:"env"`
|
|
|
|
File string `mapstructure:"file"`
|
|
|
|
}
|
|
|
|
|
2024-02-08 17:39:32 +00:00
|
|
|
const (
|
|
|
|
SecProfileTypeRuntimeDefault SecProfileType = "RuntimeDefault"
|
|
|
|
SecProfileTypeLocalhost SecProfileType = "Localhost"
|
|
|
|
)
|
|
|
|
|
|
|
|
func parseBackendOptions(step *backend.Step) (BackendOptions, error) {
|
|
|
|
var result BackendOptions
|
|
|
|
if step.BackendOptions == nil {
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
err := mapstructure.Decode(step.BackendOptions[EngineName], &result)
|
|
|
|
return result, err
|
|
|
|
}
|