Skip to content

Commit

Permalink
feat: add pprof and use it as probe
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed Jun 4, 2019
1 parent a9c0ca2 commit 48da0fe
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 5 deletions.
5 changes: 5 additions & 0 deletions cmd/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"fmt"
"net/http"
_ "net/http/pprof"
"os"
"os/exec"
"strings"
Expand All @@ -24,6 +26,9 @@ func main() {
}

go loopOvnNbctlDaemon(config)
go func() {
klog.Fatal(http.ListenAndServe(fmt.Sprintf("localhost:%d", config.PprofPort), nil))
}()

err = controller.InitClusterRouter(config)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions cmd/daemon/cniserver.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

import (
"fmt"
"net/http"
_ "net/http/pprof"
"os"
"time"

Expand Down Expand Up @@ -36,6 +39,9 @@ func main() {
}
kubeInformerFactory.Start(stopCh)
go ctl.Run(stopCh)
go func() {
klog.Fatal(http.ListenAndServe(fmt.Sprintf("localhost:%d", config.PprofPort), nil))
}()
daemon.RunServer(config)
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Configuration struct {
PodNamespace string

WorkerNum int
PprofPort int
}

// ParseFlags parses cmd args then init kubeclient and conf
Expand All @@ -62,6 +63,7 @@ func ParseFlags() (*Configuration, error) {
argClusterUdpLoadBalancer = pflag.String("cluster-udp-loadbalancer", "cluster-udp-loadbalancer", "The name for cluster udp loadbalancer")

argWorkerNum = pflag.Int("worker-num", 3, "The parallelism of each worker, default: 3")
argPprofPort = pflag.Int("pprof-port", 10660, "The port to get profiling data, default 10660")
)

flag.Set("alsologtostderr", "true")
Expand Down Expand Up @@ -102,6 +104,7 @@ func ParseFlags() (*Configuration, error) {
ClusterTcpLoadBalancer: *argClusterTcpLoadBalancer,
ClusterUdpLoadBalancer: *argClusterUdpLoadBalancer,
WorkerNum: *argWorkerNum,
PprofPort: *argPprofPort,
PodName: os.Getenv("POD_NAME"),
PodNamespace: os.Getenv("KUBE_NAMESPACE"),
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/daemon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Configuration struct {
KubeClient kubernetes.Interface
NodeName string
ServiceClusterIPRange string
PprofPort int
}

// ParseFlags will parse cmd args then init kubeClient and configuration
Expand All @@ -32,6 +33,7 @@ func ParseFlags() (*Configuration, error) {
argOvsSocket = pflag.String("ovs-socket", "", "The socket to local ovs-server")
argKubeConfigFile = pflag.String("kubeconfig", "", "Path to kubeconfig file with authorization and master location information. If not set use the inCluster token.")
argServiceClusterIPRange = pflag.String("service-cluster-ip-range", "10.96.0.0/12", "The kubernetes service cluster ip range")
argPprofPort = pflag.Int("pprof-port", 10665, "The port to get profiling data, default 10665")
)

// mute log for ipset lib
Expand Down Expand Up @@ -65,6 +67,7 @@ func ParseFlags() (*Configuration, error) {
BindSocket: *argBindSocket,
OvsSocket: *argOvsSocket,
KubeConfigFile: *argKubeConfigFile,
PprofPort: *argPprofPort,
NodeName: nodeName,
ServiceClusterIPRange: *argServiceClusterIPRange,
}
Expand Down
47 changes: 44 additions & 3 deletions yamls/kube-ovn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ spec:
hostNetwork: true
containers:
- name: kube-ovn-controller
image: "index.alauda.cn/alaudak8s/kube-ovn-controller:v0.4.1"
image: "index.alauda.cn/alaudak8s/kube-ovn-controller:v0.5.0-pre"
imagePullPolicy: Always
command:
- /kube-ovn/start-controller.sh
Expand All @@ -55,6 +55,26 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
readinessProbe:
exec:
command:
- nc
- -z
- -w3
- 127.0.0.1
- "10660"
periodSeconds: 3
livenessProbe:
exec:
command:
- nc
- -z
- -w3
- 127.0.0.1
- "10660"
initialDelaySeconds: 30
periodSeconds: 7
failureThreshold: 5
nodeSelector:
beta.kubernetes.io/os: "linux"

Expand Down Expand Up @@ -88,7 +108,7 @@ spec:
hostPID: true
initContainers:
- name: install-cni
image: "index.alauda.cn/alaudak8s/kube-ovn-cni:v0.4.1"
image: "index.alauda.cn/alaudak8s/kube-ovn-cni:v0.5.0-pre"
imagePullPolicy: Always
command: ["/kube-ovn/install-cni.sh"]
volumeMounts:
Expand All @@ -98,7 +118,7 @@ spec:
name: cni-bin
containers:
- name: cni-server
image: "index.alauda.cn/alaudak8s/kube-ovn-cni:v0.4.1"
image: "index.alauda.cn/alaudak8s/kube-ovn-cni:v0.5.0-pre"
imagePullPolicy: Always
securityContext:
runAsUser: 0
Expand All @@ -115,6 +135,26 @@ spec:
volumeMounts:
- mountPath: /run/openvswitch
name: host-run-ovs
readinessProbe:
exec:
command:
- nc
- -z
- -w3
- 127.0.0.1
- "10665"
periodSeconds: 3
livenessProbe:
exec:
command:
- nc
- -z
- -w3
- 127.0.0.1
- "10665"
initialDelaySeconds: 30
periodSeconds: 7
failureThreshold: 5
nodeSelector:
beta.kubernetes.io/os: "linux"
volumes:
Expand All @@ -127,3 +167,4 @@ spec:
- name: cni-bin
hostPath:
path: /opt/cni/bin

4 changes: 2 additions & 2 deletions yamls/ovn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ spec:
hostNetwork: true
containers:
- name: ovn-central
image: "index.alauda.cn/alaudak8s/kube-ovn-db:v0.4.1"
image: "index.alauda.cn/alaudak8s/kube-ovn-db:v0.5.0-pre"
imagePullPolicy: Always
env:
- name: POD_IP
Expand Down Expand Up @@ -257,7 +257,7 @@ spec:
hostPID: true
containers:
- name: openvswitch
image: "index.alauda.cn/alaudak8s/kube-ovn-node:v0.4.1"
image: "index.alauda.cn/alaudak8s/kube-ovn-node:v0.5.0-pre"
imagePullPolicy: Always
securityContext:
runAsUser: 0
Expand Down

0 comments on commit 48da0fe

Please sign in to comment.