Skip to content

Commit

Permalink
Merge pull request #332 from alauda/fix/svc-subnet-conflict
Browse files Browse the repository at this point in the history
fix: validate if subnet cidr conflicts with svc ip
  • Loading branch information
oilbeater committed May 7, 2020
2 parents ccb1050 + 86c443e commit c0fc0d5
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 c0fc0d5

Please sign in to comment.