Skip to content

Commit

Permalink
modify static gw changed problem
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed Jan 11, 2021
1 parent 925f90f commit d287063
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
10 changes: 9 additions & 1 deletion pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,15 @@ func checkAndUpdateCIDR(subnet *kubeovnv1.Subnet) (bool, error) {

func checkAndUpdateGateway(subnet *kubeovnv1.Subnet) (bool, error) {
changed := false
gw, err := util.GetGwByCidr(subnet.Spec.CIDRBlock)
var gw string
var err error
if subnet.Spec.Gateway == "" {
gw, err = util.GetGwByCidr(subnet.Spec.CIDRBlock)
} else if util.CheckProtocol(subnet.Spec.Gateway) != util.CheckProtocol(subnet.Spec.CIDRBlock) {
gw, err = util.AppendGwByCidr(subnet.Spec.Gateway, subnet.Spec.CIDRBlock)
} else {
gw = subnet.Spec.Gateway
}
if err != nil {
klog.Error(err)
return false, err
Expand Down
26 changes: 26 additions & 0 deletions pkg/util/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,32 @@ func GetGwByCidr(cidrStr string) (string, error) {
return strings.Join(gws, ","), nil
}

func AppendGwByCidr(gateway, cidrStr string) (string, error) {
var gws []string
for _, cidr := range strings.Split(cidrStr, ",") {
if CheckProtocol(gateway) == CheckProtocol(cidr) {
gws = append(gws, gateway)
continue
} else {
gw, err := FirstSubnetIP(cidr)
if err != nil {
return "", err
}
var gwArray [2]string
if CheckProtocol(gateway) == kubeovnv1.ProtocolIPv4 {
gwArray[0] = gateway
gwArray[1] = gw
} else {
gwArray[0] = gw
gwArray[1] = gateway
}
gws = gwArray[:]
}
}

return strings.Join(gws, ","), nil
}

func SplitIpsByProtocol(excludeIps []string) ([]string, []string) {
var v4ExcludeIps, v6ExcludeIps []string
for _, ex := range excludeIps {
Expand Down
12 changes: 6 additions & 6 deletions yamls/ovn-dpdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ metadata:
kubernetes.io/description: |
OVN components: northd, nb and sb.
spec:
replicas: $count
replicas: 1
strategy:
rollingUpdate:
maxSurge: 0%
Expand Down Expand Up @@ -207,8 +207,8 @@ spec:
shareProcessNamespace: true
containers:
- name: ovn-central
image: "$REGISTRY/kube-ovn:$VERSION"
imagePullPolicy: $IMAGE_PULL_POLICY
image: "kubeovn/kube-ovn:v1.6.0"
imagePullPolicy: IfNotPresent
command: ["/kube-ovn/start-db.sh"]
securityContext:
capabilities:
Expand Down Expand Up @@ -269,8 +269,8 @@ spec:
failureThreshold: 5
timeoutSeconds: 45
- name: ovn-monitor
image: "$REGISTRY/kube-ovn:$VERSION"
imagePullPolicy: $IMAGE_PULL_POLICY
image: "kubeovn/kube-ovn:v1.6.0"
imagePullPolicy: IfNotPresent
command: ["/kube-ovn/start-ovn-monitor.sh"]
env:
- name: ENABLE_SSL
Expand Down Expand Up @@ -387,7 +387,7 @@ spec:
containers:
- name: openvswitch
image: "kubeovn/kube-ovn-dpdk:$DPDK_VERSION"
imagePullPolicy: $IMAGE_PULL_POLICY
imagePullPolicy: IfNotPresent
command: ["/kube-ovn/start-ovs-dpdk.sh"]
securityContext:
runAsUser: 0
Expand Down
6 changes: 3 additions & 3 deletions yamls/ovn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ kind: Service
apiVersion: v1
metadata:
name: kube-ovn-monitor
namespace: ${NAMESPACE}
namespace: kube-system
labels:
app: kube-ovn-monitor
spec:
Expand Down Expand Up @@ -269,8 +269,8 @@ spec:
failureThreshold: 5
timeoutSeconds: 45
- name: ovn-monitor
image: "$REGISTRY/kube-ovn:$VERSION"
imagePullPolicy: $IMAGE_PULL_POLICY
image: "kubeovn/kube-ovn:v1.6.0"
imagePullPolicy: IfNotPresent
command: ["/kube-ovn/start-ovn-monitor.sh"]
env:
- name: ENABLE_SSL
Expand Down

0 comments on commit d287063

Please sign in to comment.