Skip to content

Commit

Permalink
add nodeSelector for vpc-nat-gateway pod
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed Dec 3, 2021
1 parent 4499505 commit 75604b5
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dist/images/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ spec:
type: string
vpc:
type: string
selector:
type: array
items:
type: string
subresources:
status: {}
conversion:
Expand Down
3 changes: 3 additions & 0 deletions docs/vpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ spec:
snatRules:
- eip: 192.168.0.112
internalCIDR: 10.0.1.0/24
selector: # NodeSelector for vpc-nat-gw pod, the item of array should be string type with key:value format
- "kubernetes.io/hostname: kube-ovn-worker"
- "kubernetes.io/os: linux"
```

3. Add static route to VPC
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/kubeovn/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ type VpcNatSpec struct {
Vpc string `json:"vpc"`
Subnet string `json:"subnet"`
LanIp string `json:"lanIp"`
Selector []string `json:"selector"`
Eips []*Eip `json:"eips,omitempty"`
FloatingIpRules []*FloutingIpRule `json:"floatingIpRules,omitempty"`
DnatRules []*DnatRule `json:"dnatRules,omitempty"`
Expand Down
5 changes: 5 additions & 0 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.

11 changes: 11 additions & 0 deletions pkg/controller/vpc_nat_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,16 @@ func (c *Controller) genNatGwDeployment(gw *kubeovnv1.VpcNatGateway) (dp *v1.Dep
util.IpAddressAnnotation: gw.Spec.LanIp,
}

selectors := make(map[string]string)
for _, v := range gw.Spec.Selector {
parts := strings.Split(strings.TrimSpace(v), ":")
if len(parts) != 2 {
continue
}
selectors[strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1])
}
klog.V(3).Infof("prepare for vpc nat gateway pod, node selector: %v", selectors)

dp = &v1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand Down Expand Up @@ -743,6 +753,7 @@ func (c *Controller) genNatGwDeployment(gw *kubeovnv1.VpcNatGateway) (dp *v1.Dep
},
},
},
NodeSelector: selectors,
},
},
Strategy: v1.DeploymentStrategy{
Expand Down
4 changes: 4 additions & 0 deletions yamls/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,10 @@ spec:
type: string
vpc:
type: string
selector:
type: array
items:
type: string
subresources:
status: {}
conversion:
Expand Down

0 comments on commit 75604b5

Please sign in to comment.