Skip to content

Commit

Permalink
fix: validate vpc subnet
Browse files Browse the repository at this point in the history
  • Loading branch information
fanriming committed Nov 25, 2020
1 parent c4279d1 commit 8deb5d8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/util/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ 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)
if subnet.Spec.Vpc == DefaultVpc {
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 8deb5d8

Please sign in to comment.