Skip to content

Commit

Permalink
remove POD_IPS and use POD_IP instead
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Jan 18, 2023
1 parent ad27d77 commit 8a1a3ca
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 125 deletions.
19 changes: 5 additions & 14 deletions cmd/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package controller
import (
"context"
"fmt"
"net"
"net/http"
"net/http/pprof"
"os"
"strings"
"strconv"
"time"

"github.com/prometheus/client_golang/prometheus/promhttp"
Expand All @@ -20,7 +21,6 @@ import (
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"

kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
"github.com/kubeovn/kube-ovn/pkg/controller"
"github.com/kubeovn/kube-ovn/pkg/ovs"
"github.com/kubeovn/kube-ovn/pkg/util"
Expand Down Expand Up @@ -68,23 +68,14 @@ func CmdMain() {
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
}

addr := "0.0.0.0"
ip := "0.0.0.0"
if os.Getenv("ENABLE_BIND_LOCAL_IP") == "true" {
podIpsEnv := os.Getenv("POD_IPS")
podIps := strings.Split(podIpsEnv, ",")
// when pod in dual mode, golang can't support bind v4 and v6 address in the same time,
// so not support bind local ip when in dual mode
if len(podIps) == 1 {
addr = podIps[0]
if util.CheckProtocol(podIps[0]) == kubeovnv1.ProtocolIPv6 {
addr = fmt.Sprintf("[%s]", podIps[0])
}
}
ip = os.Getenv("POD_IP")
}
// conform to Gosec G114
// https://github.com/securego/gosec#available-rules
server := &http.Server{
Addr: fmt.Sprintf("%s:%d", addr, config.PprofPort),
Addr: net.JoinHostPort(ip, strconv.Itoa(config.PprofPort)),
ReadHeaderTimeout: 3 * time.Second,
Handler: mux,
}
Expand Down
16 changes: 3 additions & 13 deletions cmd/controller_health_check/controller_health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"
"time"

kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
"github.com/kubeovn/kube-ovn/pkg/ovs"
"github.com/kubeovn/kube-ovn/pkg/util"
)
Expand All @@ -25,21 +24,12 @@ func CmdMain() {
os.Exit(1)
}

addr := "127.0.0.1:10660"
ip := "127.0.0.1"
if os.Getenv("ENABLE_BIND_LOCAL_IP") == "true" {
podIpsEnv := os.Getenv("POD_IPS")
podIps := strings.Split(podIpsEnv, ",")
// when pod in dual mode, golang can't support bind v4 and v6 address in the same time,
// so not support bind local ip when in dual mode
if len(podIps) == 1 {
addr = fmt.Sprintf("%s:10660", podIps[0])
if util.CheckProtocol(podIps[0]) == kubeovnv1.ProtocolIPv6 {
addr = fmt.Sprintf("[%s]:10660", podIps[0])
}
}
ip = os.Getenv("POD_IP")
}

conn, err := net.DialTimeout("tcp", addr, 3*time.Second)
conn, err := net.DialTimeout("tcp", net.JoinHostPort(ip, "10660"), 3*time.Second)
if err != nil {
util.LogFatalAndExit(err, "failed to probe the socket")
}
Expand Down
16 changes: 4 additions & 12 deletions cmd/daemon/cniserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"context"
"encoding/json"
"fmt"
"net"
"net/http"
"net/http/pprof"
"os"
"path/filepath"
"strconv"
"strings"
"time"

Expand All @@ -18,7 +20,6 @@ import (
"k8s.io/klog/v2"
"k8s.io/sample-controller/pkg/signals"

kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
kubeovninformer "github.com/kubeovn/kube-ovn/pkg/client/informers/externalversions"
"github.com/kubeovn/kube-ovn/pkg/daemon"
"github.com/kubeovn/kube-ovn/pkg/util"
Expand Down Expand Up @@ -100,21 +101,12 @@ func CmdMain() {

addr := "0.0.0.0"
if os.Getenv("ENABLE_BIND_LOCAL_IP") == "true" {
podIpsEnv := os.Getenv("POD_IPS")
podIps := strings.Split(podIpsEnv, ",")
// when pod in dual mode, golang can't support bind v4 and v6 address in the same time,
// so not support bind local ip when in dual mode
if len(podIps) == 1 {
addr = podIps[0]
if util.CheckProtocol(podIps[0]) == kubeovnv1.ProtocolIPv6 {
addr = fmt.Sprintf("[%s]", podIps[0])
}
}
addr = os.Getenv("POD_IP")
}
// conform to Gosec G114
// https://github.com/securego/gosec#available-rules
server := &http.Server{
Addr: fmt.Sprintf("%s:%d", addr, config.PprofPort),
Addr: net.JoinHostPort(addr, strconv.Itoa(config.PprofPort)),
ReadHeaderTimeout: 3 * time.Second,
Handler: mux,
}
Expand Down
17 changes: 3 additions & 14 deletions cmd/ovn_monitor/ovn_monitor.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package ovn_monitor

import (
"fmt"
"net"
"net/http"
"os"
"strings"
"time"

"github.com/prometheus/client_golang/prometheus/promhttp"
"k8s.io/klog/v2"

kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
ovn "github.com/kubeovn/kube-ovn/pkg/ovnmonitor"
"github.com/kubeovn/kube-ovn/pkg/util"
"github.com/kubeovn/kube-ovn/versions"
Expand Down Expand Up @@ -41,17 +39,8 @@ func CmdMain() {
// https://github.com/securego/gosec#available-rules

addr := config.ListenAddress
if os.Getenv("ENABLE_BIND_LOCAL_IP") == "true" {
podIpsEnv := os.Getenv("POD_IPS")
podIps := strings.Split(podIpsEnv, ",")
// when pod in dual mode, golang can't support bind v4 and v6 address in the same time,
// so not support bind local ip when in dual mode
if len(podIps) == 1 {
addr = fmt.Sprintf("%s:10661", podIps[0])
if util.CheckProtocol(podIps[0]) == kubeovnv1.ProtocolIPv6 {
addr = fmt.Sprintf("[%s]:10661", podIps[0])
}
}
if os.Getenv("ENABLE_BIND_LOCAL_IP") == "true" && addr == ":10661" {
addr = net.JoinHostPort(os.Getenv("POD_IP"), "10661")
}

server := &http.Server{
Expand Down
20 changes: 4 additions & 16 deletions dist/images/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2030,10 +2030,6 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POD_IPS
valueFrom:
fieldRef:
fieldPath: status.podIPs
- name: ENABLE_BIND_LOCAL_IP
value: "$ENABLE_BIND_LOCAL_IP"
resources:
Expand Down Expand Up @@ -2530,10 +2526,6 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POD_IPS
valueFrom:
fieldRef:
fieldPath: status.podIPs
- name: ENABLE_BIND_LOCAL_IP
value: "$ENABLE_BIND_LOCAL_IP"
resources:
Expand Down Expand Up @@ -3036,10 +3028,10 @@ spec:
fieldPath: spec.nodeName
- name: OVN_DB_IPS
value: $addresses
- name: POD_IPS
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIPs
fieldPath: status.podIP
- name: ENABLE_BIND_LOCAL_IP
value: "$ENABLE_BIND_LOCAL_IP"
volumeMounts:
Expand Down Expand Up @@ -3166,10 +3158,6 @@ spec:
value: $MODULES
- name: RPMS
value: $RPMS
- name: POD_IPS
valueFrom:
fieldRef:
fieldPath: status.podIPs
- name: ENABLE_BIND_LOCAL_IP
value: "$ENABLE_BIND_LOCAL_IP"
volumeMounts:
Expand Down Expand Up @@ -3451,10 +3439,10 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_IPS
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIPs
fieldPath: status.podIP
- name: ENABLE_BIND_LOCAL_IP
value: "$ENABLE_BIND_LOCAL_IP"
resources:
Expand Down
10 changes: 2 additions & 8 deletions dist/images/ovn-is-leader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@ ovn-ctl status_ovnnb
ovn-ctl status_ovnsb

BIND_LOCAL_ADDR=127.0.0.1
ENABLE_BIND_LOCAL_IP=${ENABLE_BIND_LOCAL_IP:-false}
if [[ $ENABLE_BIND_LOCAL_IP == "true" ]]; then
POD_IPS_LIST=(${POD_IPS//,/ })
if [[ ${#POD_IPS_LIST[@]} == 1 ]]; then
if [[ $POD_IP =~ .*:.* ]]; then
BIND_LOCAL_ADDR=[${POD_IP}] #ipv6
else
BIND_LOCAL_ADDR=${POD_IP} #ipv4
fi
fi
BIND_LOCAL_ADDR="[${POD_IP}]"
fi

# For data consistency, only store leader address in endpoint
Expand Down
4 changes: 0 additions & 4 deletions kubeovn-helm/templates/central-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POD_IPS
valueFrom:
fieldRef:
fieldPath: status.podIPs
- name: ENABLE_BIND_LOCAL_IP
value: "{{- .Values.func.ENABLE_BIND_LOCAL_IP }}"
resources:
Expand Down
4 changes: 2 additions & 2 deletions kubeovn-helm/templates/controller-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ spec:
fieldPath: spec.nodeName
- name: OVN_DB_IPS
value: "{{ .Values.MASTER_NODES }}"
- name: POD_IPS
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIPs
fieldPath: status.podIP
- name: ENABLE_BIND_LOCAL_IP
value: "{{- .Values.func.ENABLE_BIND_LOCAL_IP }}"
volumeMounts:
Expand Down
4 changes: 2 additions & 2 deletions kubeovn-helm/templates/monitor-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_IPS
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIPs
fieldPath: status.podIP
- name: ENABLE_BIND_LOCAL_IP
value: "{{- .Values.func.ENABLE_BIND_LOCAL_IP }}"
resources:
Expand Down
4 changes: 0 additions & 4 deletions kubeovn-helm/templates/ovncni-ds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ spec:
value: "{{- .Values.performance.MODULES }}"
- name: RPMS
value: "{{- .Values.performance.RPMS }}"
- name: POD_IPS
valueFrom:
fieldRef:
fieldPath: status.podIPs
- name: ENABLE_BIND_LOCAL_IP
value: "{{- .Values.func.ENABLE_BIND_LOCAL_IP }}"
volumeMounts:
Expand Down
12 changes: 4 additions & 8 deletions yamls/kube-ovn-dual-stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_IPS
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIPs
fieldPath: status.podIP
volumeMounts:
- mountPath: /etc/localtime
name: localtime
Expand Down Expand Up @@ -186,10 +186,6 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_IPS
valueFrom:
fieldRef:
fieldPath: status.podIPs
volumeMounts:
- name: host-modules
mountPath: /lib/modules
Expand Down Expand Up @@ -430,10 +426,10 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_IPS
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIPs
fieldPath: status.podIP
resources:
requests:
cpu: 200m
Expand Down
12 changes: 4 additions & 8 deletions yamls/kube-ovn-ipv6.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_IPS
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIPs
fieldPath: status.podIP
volumeMounts:
- mountPath: /var/run/tls
name: kube-ovn-tls
Expand Down Expand Up @@ -175,10 +175,6 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_IPS
valueFrom:
fieldRef:
fieldPath: status.podIPs
volumeMounts:
- name: host-modules
mountPath: /lib/modules
Expand Down Expand Up @@ -402,10 +398,10 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_IPS
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIPs
fieldPath: status.podIP
resources:
requests:
cpu: 200m
Expand Down
12 changes: 4 additions & 8 deletions yamls/kube-ovn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_IPS
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIPs
fieldPath: status.podIP
volumeMounts:
- mountPath: /etc/localtime
name: localtime
Expand Down Expand Up @@ -186,10 +186,6 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_IPS
valueFrom:
fieldRef:
fieldPath: status.podIPs
volumeMounts:
- name: host-modules
mountPath: /lib/modules
Expand Down Expand Up @@ -445,10 +441,10 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_IPS
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIPs
fieldPath: status.podIP
resources:
requests:
cpu: 200m
Expand Down
Loading

0 comments on commit 8a1a3ca

Please sign in to comment.