Skip to content

Commit

Permalink
fix: validate namespace switch annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed Mar 28, 2019
1 parent fcb6b5f commit 3e78ddc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 0 additions & 2 deletions dist/images/start-ovn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ DB_NB_PORT=${1:-6641}
DB_SB_ADDR=${1:-0.0.0.0}
DB_SB_PORT=${1:-6642}

rm -rf /var/run/openvswitch

# Start ovn-northd, ovn-nb and ovn-sb
/usr/share/openvswitch/scripts/ovn-ctl restart_northd

Expand Down
7 changes: 7 additions & 0 deletions pkg/controller/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func (c *Controller) handleAddNamespace(key string) error {
return err
}

// return if switch already exists
ss, err := c.ovnClient.ListLogicalSwitch()
if err != nil {
return err
Expand All @@ -133,6 +134,12 @@ func (c *Controller) handleAddNamespace(key string) error {
}
}

if cidr == "" || gateway == "" {
return fmt.Errorf("cidr and gateway are required for namespace %s", key)
}
if excludeIps == "" {
excludeIps = gateway
}
// If multiple namespace use same ls name, only first one will success
return c.ovnClient.CreateLogicalSwitch(ls, cidr, gateway, excludeIps)

Expand Down
1 change: 0 additions & 1 deletion pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ func (c *Controller) handleAddPod(key string) error {
// The Pod resource may no longer exist, in which case we stop
// processing.
if errors.IsNotFound(err) {
utilruntime.HandleError(fmt.Errorf("pod '%s' in work queue no longer exists", key))
return nil
}
return err
Expand Down
5 changes: 5 additions & 0 deletions pkg/ovs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"k8s.io/klog"
"os/exec"
"strings"
"time"
)

type Client struct {
Expand All @@ -31,7 +32,11 @@ var GlobalUdpLb string
func (c Client) ovnCommand(arg ...string) (string, error) {
cmdArgs := []string{fmt.Sprintf("--db=%s", c.OvnNbAddress)}
cmdArgs = append(cmdArgs, arg...)

start := time.Now()
raw, err := exec.Command(OvnNbCtl, cmdArgs...).CombinedOutput()
elapsed := float64((time.Since(start)) / time.Millisecond)
klog.Infof("ovn-nbctl command %s in %vms", strings.Join(cmdArgs, " "), elapsed)
if err != nil {
return "", fmt.Errorf("%s, %v", string(raw), err)
}
Expand Down

0 comments on commit 3e78ddc

Please sign in to comment.