Skip to content

Commit

Permalink
fix: validate if subnet cidr conflicts with svc ip
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed May 7, 2020
1 parent ccb1050 commit 86c443e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/util/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package util
import (
"fmt"
"net"
"os"
"strconv"
"strings"

Expand Down Expand Up @@ -51,6 +52,11 @@ func ValidateSubnet(subnet kubeovnv1.Subnet) error {
return fmt.Errorf("%s is not a valid gateway type", gwType)
}

k8sApiServer := os.Getenv("KUBERNETES_SERVICE_HOST")
if k8sApiServer != "" && CIDRContainIP(subnet.Spec.CIDRBlock, k8sApiServer) {
return fmt.Errorf("subnet %s cidr %s conflicts with k8s apiserver svc ip %s", subnet.Name, subnet.Spec.CIDRBlock, k8sApiServer)
}

return nil
}

Expand Down

0 comments on commit 86c443e

Please sign in to comment.