Skip to content

Commit

Permalink
add subnet match check when change subnet gatewayType from centralize…
Browse files Browse the repository at this point in the history
…d to distributed (#2891)
  • Loading branch information
hongzhen-ma committed Jun 1, 2023
1 parent 188a9aa commit e84053f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,6 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20190905181640-827449938966/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
23 changes: 11 additions & 12 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ func (c Controller) patchSubnetStatus(subnet *kubeovnv1.Subnet, reason string, e
c.recorder.Eventf(subnet, v1.EventTypeWarning, reason, errStr)
} else {
subnet.Status.Validated(reason, "")
c.recorder.Eventf(subnet, v1.EventTypeNormal, reason, errStr)
if reason == "SetPrivateLogicalSwitchSuccess" || reason == "ResetLogicalSwitchAclSuccess" || reason == "ReconcileCentralizedGatewaySuccess" {
subnet.Status.Ready(reason, "")
}
Expand Down Expand Up @@ -826,21 +827,19 @@ func (c *Controller) reconcileGateway(subnet *kubeovnv1.Subnet) error {
} else {
// if gw is distributed remove activateGateway field
if subnet.Spec.GatewayType == kubeovnv1.GWDistributedType {
if subnet.Spec.GatewayNode == "" {
return nil
}
subnet.Spec.GatewayNode = ""
bytes, err := subnet.Status.Bytes()
if err != nil {
return err
}
_, err = c.config.KubeOvnClient.KubeovnV1().Subnets().Patch(context.Background(), subnet.Name, types.MergePatchType, bytes, metav1.PatchOptions{}, "")
if err != nil {
return err
if subnet.Spec.GatewayNode != "" || subnet.Status.ActivateGateway != "" {
klog.Infof("change subnet %s gatewayType from centralized to distributed", subnet.Name)
subnet.Spec.GatewayNode = ""
if _, err := c.config.KubeOvnClient.KubeovnV1().Subnets().Update(context.Background(), subnet, metav1.UpdateOptions{}); err != nil {
klog.Errorf("failed to remove gatewayNode from subnet %s, %v", subnet.Name, err)
return err
}
subnet.Status.ActivateGateway = ""
c.patchSubnetStatus(subnet, "ChangeToDistributedGw", "")
}

for _, pod := range pods {
if !isPodAlive(pod) {
if !isPodAlive(pod) || pod.Annotations[util.IpAddressAnnotation] == "" || pod.Annotations[util.LogicalSwitchAnnotation] != subnet.Name {
continue
}
if c.config.EnableEipSnat && (pod.Annotations[util.EipAnnotation] != "" || pod.Annotations[util.SnatAnnotation] != "") {
Expand Down

0 comments on commit e84053f

Please sign in to comment.