mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 00:47:48 +08:00
Add support for defining kubernetes tolerations
Signed-off-by: Zsolt <zsolt.szeberenyi@figured.com>
This commit is contained in:
parent
adafbe0e65
commit
3f6517747e
@ -140,6 +140,7 @@ Passes additional driver-specific options. Details for each driver:
|
||||
- `limits.cpu` - Sets the limit CPU value specified in units of Kubernetes CPU. Example `limits.cpu=100m`, `limits.cpu=2`
|
||||
- `limits.memory` - Sets the limit memory value specified in bytes or with a valid suffix. Example `limits.memory=500Mi`, `limits.memory=4G`
|
||||
- `nodeselector="label1=value1,label2=value2"` - Sets the kv of `Pod` nodeSelector. No Defaults. Example `nodeselector=kubernetes.io/arch=arm64`
|
||||
- `tolerations="key=foo,value=bar;key=foo2,operator=exists;key=foo3,effect=NoSchedule"` - Sets the `Pod` tolerations. Accepts the same values as the kube manifest tolerations. Key-value pairs are separated by `,`, tolerations are separated by `;`. No Defaults. Example `tolerations=operator=exists`
|
||||
- `rootless=(true|false)` - Run the container as a non-root user without `securityContext.privileged`. [Using Ubuntu host kernel is recommended](https://github.com/moby/buildkit/blob/master/docs/rootless.md). Defaults to false.
|
||||
- `loadbalance=(sticky|random)` - Load-balancing strategy. If set to "sticky", the pod is chosen using the hash of the context path. Defaults to "sticky"
|
||||
- `qemu.install=(true|false)` - Install QEMU emulation for multi platforms support.
|
||||
|
@ -5,6 +5,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
|
||||
"github.com/docker/buildx/driver"
|
||||
"github.com/docker/buildx/driver/bkimage"
|
||||
"github.com/docker/buildx/driver/kubernetes/manifest"
|
||||
@ -117,6 +119,48 @@ func (f *factory) New(ctx context.Context, cfg driver.InitConfig) (driver.Driver
|
||||
}
|
||||
}
|
||||
deploymentOpt.NodeSelector = s
|
||||
case "tolerations":
|
||||
u, err := strconv.Unquote(v)
|
||||
if nil != err {
|
||||
return nil, err
|
||||
}
|
||||
ts := strings.Split(u, ";")
|
||||
deploymentOpt.Tolerations = []corev1.Toleration{}
|
||||
for i := range ts {
|
||||
kvs := strings.Split(ts[i], ",")
|
||||
if len(kvs) == 0 {
|
||||
return nil, errors.Errorf("invalid tolaration %q", v)
|
||||
}
|
||||
|
||||
t := corev1.Toleration{}
|
||||
|
||||
for j := range kvs {
|
||||
kv := strings.Split(kvs[j], "=")
|
||||
if len(kv) == 2 {
|
||||
switch kv[0] {
|
||||
case "key":
|
||||
t.Key = kv[1]
|
||||
case "operator":
|
||||
t.Operator = corev1.TolerationOperator(kv[1])
|
||||
case "value":
|
||||
t.Value = kv[1]
|
||||
case "effect":
|
||||
t.Effect = corev1.TaintEffect(kv[1])
|
||||
case "tolerationSeconds":
|
||||
c, err := strconv.Atoi(kv[1])
|
||||
if nil != err {
|
||||
return nil, err
|
||||
}
|
||||
c64 := int64(c)
|
||||
t.TolerationSeconds = &c64
|
||||
default:
|
||||
return nil, errors.Errorf("invalid tolaration %q", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deploymentOpt.Tolerations = append(deploymentOpt.Tolerations, t)
|
||||
}
|
||||
case "loadbalance":
|
||||
switch v {
|
||||
case LoadbalanceSticky:
|
||||
|
@ -32,6 +32,7 @@ type DeploymentOpt struct {
|
||||
|
||||
Rootless bool
|
||||
NodeSelector map[string]string
|
||||
Tolerations []corev1.Toleration
|
||||
RequestsCPU string
|
||||
RequestsMemory string
|
||||
LimitsCPU string
|
||||
@ -159,6 +160,10 @@ func NewDeployment(opt *DeploymentOpt) (d *appsv1.Deployment, c []*corev1.Config
|
||||
d.Spec.Template.Spec.NodeSelector = opt.NodeSelector
|
||||
}
|
||||
|
||||
if len(opt.Tolerations) > 0 {
|
||||
d.Spec.Template.Spec.Tolerations = opt.Tolerations
|
||||
}
|
||||
|
||||
if opt.RequestsCPU != "" {
|
||||
reqCPU, err := resource.ParseQuantity(opt.RequestsCPU)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user