Add support for defining kubernetes tolerations

Signed-off-by: Zsolt <zsolt.szeberenyi@figured.com>
pull/1045/head
Zsolt 3 years ago
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.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` - `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` - `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. - `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" - `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. - `qemu.install=(true|false)` - Install QEMU emulation for multi platforms support.

@ -5,6 +5,8 @@ import (
"strconv" "strconv"
"strings" "strings"
corev1 "k8s.io/api/core/v1"
"github.com/docker/buildx/driver" "github.com/docker/buildx/driver"
"github.com/docker/buildx/driver/bkimage" "github.com/docker/buildx/driver/bkimage"
"github.com/docker/buildx/driver/kubernetes/manifest" "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 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": case "loadbalance":
switch v { switch v {
case LoadbalanceSticky: case LoadbalanceSticky:

@ -32,6 +32,7 @@ type DeploymentOpt struct {
Rootless bool Rootless bool
NodeSelector map[string]string NodeSelector map[string]string
Tolerations []corev1.Toleration
RequestsCPU string RequestsCPU string
RequestsMemory string RequestsMemory string
LimitsCPU string LimitsCPU string
@ -159,6 +160,10 @@ func NewDeployment(opt *DeploymentOpt) (d *appsv1.Deployment, c []*corev1.Config
d.Spec.Template.Spec.NodeSelector = opt.NodeSelector d.Spec.Template.Spec.NodeSelector = opt.NodeSelector
} }
if len(opt.Tolerations) > 0 {
d.Spec.Template.Spec.Tolerations = opt.Tolerations
}
if opt.RequestsCPU != "" { if opt.RequestsCPU != "" {
reqCPU, err := resource.ParseQuantity(opt.RequestsCPU) reqCPU, err := resource.ParseQuantity(opt.RequestsCPU)
if err != nil { if err != nil {

Loading…
Cancel
Save