Skip to content

Commit

Permalink
fix: reset ovn0 addr
Browse files Browse the repository at this point in the history
Users may clean up kube-ovn but without cleanup the node annotations and reinstall kube-ovn. As node number is unlikely to a great amount, so we reset the ovn0 port every time the controller restart to prevent some weird incident

(cherry picked from commit c755ef2)
  • Loading branch information
oilbeater committed Mar 9, 2021
1 parent 8152bdf commit cce2bb4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 3 additions & 2 deletions pkg/controller/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,9 @@ func (c *Controller) handleAddNode(key string) error {

var v4IP, v6IP, mac string
portName := fmt.Sprintf("node-%s", key)
if node.Annotations[util.AllocatedAnnotation] == "true" {
return nil
if node.Annotations[util.IpAddressAnnotation] != "" && node.Annotations[util.MacAddressAnnotation] != "" {
v4IP, v6IP = util.SplitStringIP(node.Annotations[util.IpAddressAnnotation])
mac = node.Annotations[util.MacAddressAnnotation]
} else {
v4IP, v6IP, mac, err = c.ipam.GetRandomAddress(portName, c.config.NodeSwitch)
if err != nil {
Expand Down
12 changes: 8 additions & 4 deletions test/e2e/ip/static_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import (
"k8s.io/apimachinery/pkg/labels"
)

const (
TestImage = "kubeovn/pause:3.2"
)

var _ = Describe("[IP Allocation]", func() {
namespace := "static-ip"
f := framework.NewFramework("ip allocation", fmt.Sprintf("%s/.kube/config", os.Getenv("HOME")))
Expand All @@ -37,7 +41,7 @@ var _ = Describe("[IP Allocation]", func() {
Containers: []corev1.Container{
{
Name: name,
Image: "nginx:alpine",
Image: TestImage,
ImagePullPolicy: corev1.PullIfNotPresent,
},
},
Expand Down Expand Up @@ -87,7 +91,7 @@ var _ = Describe("[IP Allocation]", func() {
Containers: []corev1.Container{
{
Name: name,
Image: "nginx:alpine",
Image: TestImage,
ImagePullPolicy: corev1.PullIfNotPresent,
},
},
Expand Down Expand Up @@ -159,7 +163,7 @@ var _ = Describe("[IP Allocation]", func() {
Containers: []corev1.Container{
{
Name: name,
Image: "nginx:alpine",
Image: TestImage,
ImagePullPolicy: corev1.PullIfNotPresent,
},
},
Expand Down Expand Up @@ -203,7 +207,7 @@ var _ = Describe("[IP Allocation]", func() {
Containers: []corev1.Container{
{
Name: name,
Image: "nginx:alpine",
Image: TestImage,
ImagePullPolicy: corev1.PullIfNotPresent,
},
},
Expand Down

0 comments on commit cce2bb4

Please sign in to comment.