diff --git a/dist/images/install.sh b/dist/images/install.sh index fb1a30eba7f..b8b4c16dc7a 100755 --- a/dist/images/install.sh +++ b/dist/images/install.sh @@ -469,6 +469,21 @@ spec: type: array items: type: string + tolerations: + type: array + items: + type: object + properties: + key: + type: string + operator: + type: string + value: + type: string + effect: + type: string + tolerationSeconds: + type: integer --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/pkg/apis/kubeovn/v1/types.go b/pkg/apis/kubeovn/v1/types.go index 3ed58d252b0..60baf21d239 100644 --- a/pkg/apis/kubeovn/v1/types.go +++ b/pkg/apis/kubeovn/v1/types.go @@ -447,10 +447,19 @@ type VpcNatGateway struct { } type VpcNatSpec struct { - Vpc string `json:"vpc"` - Subnet string `json:"subnet"` - LanIp string `json:"lanIp"` - Selector []string `json:"selector"` + Vpc string `json:"vpc"` + Subnet string `json:"subnet"` + LanIp string `json:"lanIp"` + Selector []string `json:"selector"` + Tolerations []VpcNatToleration `json:"tolerations"` +} + +type VpcNatToleration struct { + Key string `json:"key"` + Operator string `json:"operator"` + Value string `json:"value"` + Effect string `json:"effect"` + TolerationSeconds int64 `json:"tolerationSeconds"` } // +genclient diff --git a/pkg/apis/kubeovn/v1/zz_generated.deepcopy.go b/pkg/apis/kubeovn/v1/zz_generated.deepcopy.go index e466fe6fb88..21d8ba8365c 100644 --- a/pkg/apis/kubeovn/v1/zz_generated.deepcopy.go +++ b/pkg/apis/kubeovn/v1/zz_generated.deepcopy.go @@ -1802,6 +1802,11 @@ func (in *VpcNatSpec) DeepCopyInto(out *VpcNatSpec) { *out = make([]string, len(*in)) copy(*out, *in) } + if in.Tolerations != nil { + in, out := &in.Tolerations, &out.Tolerations + *out = make([]VpcNatToleration, len(*in)) + copy(*out, *in) + } return } @@ -1815,6 +1820,22 @@ func (in *VpcNatSpec) DeepCopy() *VpcNatSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *VpcNatToleration) DeepCopyInto(out *VpcNatToleration) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VpcNatToleration. +func (in *VpcNatToleration) DeepCopy() *VpcNatToleration { + if in == nil { + return nil + } + out := new(VpcNatToleration) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *VpcPeering) DeepCopyInto(out *VpcPeering) { *out = *in diff --git a/pkg/controller/vpc_nat_gateway.go b/pkg/controller/vpc_nat_gateway.go index dd7257c2beb..e8f9b92387f 100644 --- a/pkg/controller/vpc_nat_gateway.go +++ b/pkg/controller/vpc_nat_gateway.go @@ -673,6 +673,21 @@ func (c *Controller) genNatGwStatefulSet(gw *kubeovnv1.VpcNatGateway, oldSts *v1 } klog.V(3).Infof("prepare for vpc nat gateway pod, node selector: %v", selectors) + var tolerations []corev1.Toleration + for _, t := range gw.Spec.Tolerations { + toleration := corev1.Toleration{ + Key: t.Key, + Value: t.Value, + Effect: corev1.TaintEffect(t.Effect), + Operator: corev1.TolerationOperator(t.Operator), + } + + if t.TolerationSeconds != 0 { + toleration.TolerationSeconds = &t.TolerationSeconds + } + tolerations = append(tolerations, toleration) + } + newSts = &v1.StatefulSet{ ObjectMeta: metav1.ObjectMeta{ Name: name, @@ -703,6 +718,7 @@ func (c *Controller) genNatGwStatefulSet(gw *kubeovnv1.VpcNatGateway, oldSts *v1 }, }, NodeSelector: selectors, + Tolerations: tolerations, }, }, UpdateStrategy: v1.StatefulSetUpdateStrategy{