Skip to content

Commit

Permalink
Optimized tolerations code in vpc-nat-gw (#2613)
Browse files Browse the repository at this point in the history
Co-authored-by: yl4811 <yl4811@yealink.com>
  • Loading branch information
ShaPoHun and yl4811 committed Apr 7, 2023
1 parent 1e8e382 commit 42a8686
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 48 deletions.
7 changes: 7 additions & 0 deletions dist/images/install.sh
Expand Up @@ -410,10 +410,17 @@ spec:
type: string
operator:
type: string
enum:
- Equal
- Exists
value:
type: string
effect:
type: string
enum:
- NoExecute
- NoSchedule
- PreferNoSchedule
tolerationSeconds:
type: integer
affinity:
Expand Down
7 changes: 7 additions & 0 deletions kubeovn-helm/templates/kube-ovn-crd.yaml
Expand Up @@ -191,10 +191,17 @@ spec:
type: string
operator:
type: string
enum:
- Equal
- Exists
value:
type: string
effect:
type: string
enum:
- NoExecute
- NoSchedule
- PreferNoSchedule
tolerationSeconds:
type: integer
affinity:
Expand Down
20 changes: 6 additions & 14 deletions pkg/apis/kubeovn/v1/types.go
Expand Up @@ -462,20 +462,12 @@ type VpcNatGateway struct {
}

type VpcNatSpec struct {
Vpc string `json:"vpc"`
Subnet string `json:"subnet"`
LanIp string `json:"lanIp"`
Selector []string `json:"selector"`
Tolerations []VpcNatToleration `json:"tolerations"`
Affinity corev1.Affinity `json:"affinity"`
}

type VpcNatToleration struct {
Key string `json:"key"`
Operator string `json:"operator"`
Value string `json:"value"`
Effect string `json:"effect"`
TolerationSeconds int64 `json:"tolerationSeconds"`
Vpc string `json:"vpc"`
Subnet string `json:"subnet"`
LanIp string `json:"lanIp"`
Selector []string `json:"selector"`
Tolerations []corev1.Toleration `json:"tolerations"`
Affinity corev1.Affinity `json:"affinity"`
}

// +genclient
Expand Down
24 changes: 6 additions & 18 deletions pkg/apis/kubeovn/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 1 addition & 16 deletions pkg/controller/vpc_nat_gateway.go
Expand Up @@ -685,21 +685,6 @@ 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,
Expand Down Expand Up @@ -730,7 +715,7 @@ func (c *Controller) genNatGwStatefulSet(gw *kubeovnv1.VpcNatGateway, oldSts *v1
},
},
NodeSelector: selectors,
Tolerations: tolerations,
Tolerations: gw.Spec.Tolerations,
Affinity: &gw.Spec.Affinity,
},
},
Expand Down
7 changes: 7 additions & 0 deletions yamls/crd.yaml
Expand Up @@ -191,10 +191,17 @@ spec:
type: string
operator:
type: string
enum:
- Equal
- Exists
value:
type: string
effect:
type: string
enum:
- NoExecute
- NoSchedule
- PreferNoSchedule
tolerationSeconds:
type: integer
affinity:
Expand Down

0 comments on commit 42a8686

Please sign in to comment.