Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: kube-ovn-controller cannot be ready when ENABLE_METRICS is false #4886

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion charts/kube-ovn/templates/controller-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ spec:
- /kube-ovn/kube-ovn-healthcheck
- --port=10660
- --tls={{- .Values.func.SECURE_SERVING }}
- --enable-metrics={{- .Values.networking.ENABLE_METRICS }}
periodSeconds: 3
timeoutSeconds: 5
livenessProbe:
Expand All @@ -204,6 +205,7 @@ spec:
- /kube-ovn/kube-ovn-healthcheck
- --port=10660
- --tls={{- .Values.func.SECURE_SERVING }}
- --enable-metrics={{- .Values.networking.ENABLE_METRICS }}
initialDelaySeconds: 300
periodSeconds: 7
failureThreshold: 5
Expand Down Expand Up @@ -231,4 +233,3 @@ spec:
secret:
optional: true
secretName: kube-ovn-tls

3 changes: 3 additions & 0 deletions charts/kube-ovn/templates/monitor-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ spec:
- --logtostderr=false
- --alsologtostderr=true
- --log_file_max_size=200
- --enable-metrics={{- .Values.networking.ENABLE_METRICS }}
securityContext:
runAsUser: {{ include "kubeovn.runAsUser" . }}
privileged: false
Expand Down Expand Up @@ -130,6 +131,7 @@ spec:
- /kube-ovn/kube-ovn-healthcheck
- --port=10661
- --tls={{- .Values.func.SECURE_SERVING }}
- --enable-metrics={{- .Values.networking.ENABLE_METRICS }}
timeoutSeconds: 5
readinessProbe:
failureThreshold: 3
Expand All @@ -141,6 +143,7 @@ spec:
- /kube-ovn/kube-ovn-healthcheck
- --port=10661
- --tls={{- .Values.func.SECURE_SERVING }}
- --enable-metrics={{- .Values.networking.ENABLE_METRICS }}
timeoutSeconds: 5
nodeSelector:
kubernetes.io/os: "linux"
Expand Down
2 changes: 2 additions & 0 deletions charts/kube-ovn/templates/ovncni-ds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ spec:
- /kube-ovn/kube-ovn-healthcheck
- --port=10665
- --tls={{- .Values.func.SECURE_SERVING }}
- --enable-metrics={{- .Values.networking.ENABLE_METRICS }}
timeoutSeconds: 5
livenessProbe:
failureThreshold: 3
Expand All @@ -210,6 +211,7 @@ spec:
- /kube-ovn/kube-ovn-healthcheck
- --port=10665
- --tls={{- .Values.func.SECURE_SERVING }}
- --enable-metrics={{- .Values.networking.ENABLE_METRICS }}
timeoutSeconds: 5
resources:
requests:
Expand Down
37 changes: 29 additions & 8 deletions cmd/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,36 @@ func CmdMain() {
}()
}

if !config.EnableMetrics {
return
}
metrics.InitKlogMetrics()
metrics.InitClientGoMetrics()
addr := util.JoinHostPort(metricsAddr, config.PprofPort)
if err := metrics.Run(ctx, config.KubeRestConfig, addr, config.SecureServing, servePprofInMetricsServer); err != nil {
util.LogFatalAndExit(err, "failed to run metrics server")
if config.EnableMetrics {
metrics.InitKlogMetrics()
metrics.InitClientGoMetrics()
addr := util.JoinHostPort(metricsAddr, config.PprofPort)
if err := metrics.Run(ctx, config.KubeRestConfig, addr, config.SecureServing, servePprofInMetricsServer); err != nil {
util.LogFatalAndExit(err, "failed to run metrics server")
}
} else {
klog.Info("metrics server is disabled")
listerner, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.ParseIP(metricsAddr), Port: int(config.PprofPort)})
if err != nil {
util.LogFatalAndExit(err, "failed to listen on %s", util.JoinHostPort(metricsAddr, config.PprofPort))
}
svr := manager.Server{
Name: "health-check",
Server: &http.Server{
Handler: http.NewServeMux(),
MaxHeaderBytes: 1 << 20,
IdleTimeout: 90 * time.Second,
ReadHeaderTimeout: 32 * time.Second,
},
zhaocongqi marked this conversation as resolved.
Show resolved Hide resolved
Listener: listerner,
}
go func() {
if err = svr.Start(ctx); err != nil {
util.LogFatalAndExit(err, "failed to run health check server")
}
}()
}

<-ctx.Done()
}()

Expand Down
35 changes: 29 additions & 6 deletions cmd/daemon/cniserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ import (
func main() {
defer klog.Flush()

daemon.InitMetrics()
metrics.InitKlogMetrics()

config := daemon.ParseFlags()
klog.Info(versions.String())

Expand Down Expand Up @@ -149,10 +146,36 @@ func main() {
}()
}

listenAddr := util.JoinHostPort(addr, config.PprofPort)
if err = metrics.Run(ctx, nil, listenAddr, config.SecureServing, servePprofInMetricsServer); err != nil {
util.LogFatalAndExit(err, "failed to run metrics server")
if config.EnableMetrics {
daemon.InitMetrics()
metrics.InitKlogMetrics()
listenAddr := util.JoinHostPort(addr, config.PprofPort)
if err = metrics.Run(ctx, nil, listenAddr, config.SecureServing, servePprofInMetricsServer); err != nil {
util.LogFatalAndExit(err, "failed to run metrics server")
}
} else {
klog.Info("metrics server is disabled")
listerner, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.ParseIP(addr), Port: int(config.PprofPort)})
if err != nil {
util.LogFatalAndExit(err, "failed to listen on %s", util.JoinHostPort(addr, config.PprofPort))
}
svr := manager.Server{
Name: "health-check",
Server: &http.Server{
Handler: http.NewServeMux(),
MaxHeaderBytes: 1 << 20,
IdleTimeout: 90 * time.Second,
ReadHeaderTimeout: 32 * time.Second,
},
Listener: listerner,
}
go func() {
if err = svr.Start(ctx); err != nil {
util.LogFatalAndExit(err, "failed to run health check server")
}
}()
}

<-stopCh
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/health_check/health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
func CmdMain() {
port := pflag.Int32("port", 0, "Target port")
tls := pflag.Bool("tls", false, "Dial the server with TLS")
enableMetrics := pflag.Bool("enable-metrics", true, "Whether to support metrics query")

klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
klog.InitFlags(klogFlags)
Expand Down Expand Up @@ -46,7 +47,7 @@ func CmdMain() {
}

addr := util.JoinHostPort(ip, *port)
if *tls {
if *enableMetrics && *tls {
addr = "tls://" + addr
} else {
addr = "tcp://" + addr
Expand Down
59 changes: 39 additions & 20 deletions cmd/ovn_monitor/ovn_monitor.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package ovn_monitor

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

"k8s.io/klog/v2"
"kernel.org/pub/linux/libs/security/libcap/cap"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"

"github.com/kubeovn/kube-ovn/pkg/metrics"
Expand All @@ -15,8 +17,6 @@ import (
"github.com/kubeovn/kube-ovn/versions"
)

const port = 10661

func CmdMain() {
defer klog.Flush()

Expand All @@ -30,24 +30,43 @@ func CmdMain() {
util.LogFatalAndExit(err, "failed to parse config")
}

addr := config.ListenAddress
if os.Getenv("ENABLE_BIND_LOCAL_IP") == "true" {
if ips := strings.Split(os.Getenv("POD_IPS"), ","); len(ips) == 1 {
addr = util.JoinHostPort(ips[0], port)
}
}

exporter := ovn.NewExporter(config)
if err = exporter.StartConnection(); err != nil {
klog.Errorf("%s failed to connect db socket properly: %s", ovn.GetExporterName(), err)
go exporter.TryClientConnection()
}
exporter.StartOvnMetrics()

ctrl.SetLogger(klog.NewKlogr())
ctx := signals.SetupSignalHandler()
if err = metrics.Run(ctx, nil, addr, config.SecureServing, false); err != nil {
util.LogFatalAndExit(err, "failed to run metrics server")

metricsAddr := util.GetDefaultListenAddr()
if config.EnableMetrics {
exporter := ovn.NewExporter(config)
if err = exporter.StartConnection(); err != nil {
klog.Errorf("%s failed to connect db socket properly: %s", ovn.GetExporterName(), err)
go exporter.TryClientConnection()
}
exporter.StartOvnMetrics()
addr := util.JoinHostPort(metricsAddr, config.MetricsPort)
if err = metrics.Run(ctx, nil, addr, config.SecureServing, false); err != nil {
util.LogFatalAndExit(err, "failed to run metrics server")
}
} else {
klog.Info("metrics server is disabled")
listerner, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.ParseIP(util.GetDefaultListenAddr()), Port: int(config.MetricsPort)})
if err != nil {
util.LogFatalAndExit(err, "failed to listen on %s", util.JoinHostPort(metricsAddr, config.MetricsPort))
}
svr := manager.Server{
Name: "health-check",
Server: &http.Server{
Handler: http.NewServeMux(),
MaxHeaderBytes: 1 << 20,
IdleTimeout: 90 * time.Second,
ReadHeaderTimeout: 32 * time.Second,
},
Listener: listerner,
}
go func() {
if err = svr.Start(ctx); err != nil {
util.LogFatalAndExit(err, "failed to run health check server")
}
}()
}

<-ctx.Done()
}
8 changes: 5 additions & 3 deletions cmd/speaker/speaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ func CmdMain() {
ctrl.SetLogger(klog.NewKlogr())
ctx := signals.SetupSignalHandler()
go func() {
metrics.InitKlogMetrics()
if err = metrics.Run(ctx, nil, util.JoinHostPort("0.0.0.0", config.PprofPort), false, false); err != nil {
util.LogFatalAndExit(err, "failed to run metrics server")
if config.EnableMetrics {
metrics.InitKlogMetrics()
if err = metrics.Run(ctx, nil, util.JoinHostPort("0.0.0.0", config.PprofPort), false, false); err != nil {
util.LogFatalAndExit(err, "failed to run metrics server")
}
}
<-ctx.Done()
}()
Expand Down
11 changes: 11 additions & 0 deletions dist/images/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ENABLE_LB_SVC=${ENABLE_LB_SVC:-false}
ENABLE_NAT_GW=${ENABLE_NAT_GW:-true}
ENABLE_KEEP_VM_IP=${ENABLE_KEEP_VM_IP:-true}
ENABLE_ARP_DETECT_IP_CONFLICT=${ENABLE_ARP_DETECT_IP_CONFLICT:-true}
ENABLE_METRICS=${ENABLE_METRICS:-true}
# comma-separated string of nodelocal DNS ip addresses
NODE_LOCAL_DNS_IP=${NODE_LOCAL_DNS_IP:-}
ENABLE_IC=${ENABLE_IC:-$(kubectl get node --show-labels | grep -qw "ovn.kubernetes.io/ic-gw" && echo true || echo false)}
Expand Down Expand Up @@ -4719,6 +4720,7 @@ spec:
- --log_file_max_size=200
- --enable-lb-svc=$ENABLE_LB_SVC
- --keep-vm-ip=$ENABLE_KEEP_VM_IP
- --enable-metrics=$ENABLE_METRICS
- --node-local-dns-ip=$NODE_LOCAL_DNS_IP
- --enable-ovn-ipsec=$ENABLE_OVN_IPSEC
- --secure-serving=${SECURE_SERVING}
Expand Down Expand Up @@ -4782,6 +4784,7 @@ spec:
- /kube-ovn/kube-ovn-healthcheck
- --port=10660
- --tls=${SECURE_SERVING}
- --enable-metrics=$ENABLE_METRICS
periodSeconds: 3
timeoutSeconds: 5
livenessProbe:
Expand All @@ -4790,6 +4793,7 @@ spec:
- /kube-ovn/kube-ovn-healthcheck
- --port=10660
- --tls=${SECURE_SERVING}
- --enable-metrics=$ENABLE_METRICS
initialDelaySeconds: 300
periodSeconds: 7
failureThreshold: 5
Expand Down Expand Up @@ -4911,6 +4915,7 @@ spec:
- --alsologtostderr=true
- --log_file=/var/log/kube-ovn/kube-ovn-cni.log
- --log_file_max_size=200
- --enable-metrics=$ENABLE_METRICS
- --kubelet-dir=$KUBELET_DIR
- --enable-tproxy=$ENABLE_TPROXY
- --ovs-vsctl-concurrency=$OVS_VSCTL_CONCURRENCY
Expand Down Expand Up @@ -5001,6 +5006,7 @@ spec:
- /kube-ovn/kube-ovn-healthcheck
- --port=10665
- --tls=${SECURE_SERVING}
- --enable-metrics=$ENABLE_METRICS
timeoutSeconds: 5
readinessProbe:
failureThreshold: 3
Expand All @@ -5011,6 +5017,7 @@ spec:
- /kube-ovn/kube-ovn-healthcheck
- --port=10665
- --tls=${SECURE_SERVING}
- --enable-metrics=$ENABLE_METRICS
timeoutSeconds: 5
resources:
requests:
Expand Down Expand Up @@ -5128,6 +5135,7 @@ spec:
- --alsologtostderr=true
- --log_file=/var/log/kube-ovn/kube-ovn-pinger.log
- --log_file_max_size=200
- --enable-metrics=$ENABLE_METRICS
imagePullPolicy: $IMAGE_PULL_POLICY
securityContext:
runAsUser: ${RUN_AS_USER}
Expand Down Expand Up @@ -5279,6 +5287,7 @@ spec:
- --logtostderr=false
- --alsologtostderr=true
- --log_file_max_size=200
- --enable-metrics=$ENABLE_METRICS
securityContext:
runAsUser: ${RUN_AS_USER}
privileged: false
Expand Down Expand Up @@ -5342,6 +5351,7 @@ spec:
- /kube-ovn/kube-ovn-healthcheck
- --port=10661
- --tls=${SECURE_SERVING}
- --enable-metrics=$ENABLE_METRICS
timeoutSeconds: 5
readinessProbe:
failureThreshold: 3
Expand All @@ -5353,6 +5363,7 @@ spec:
- /kube-ovn/kube-ovn-healthcheck
- --port=10661
- --tls=${SECURE_SERVING}
- --enable-metrics=$ENABLE_METRICS
timeoutSeconds: 5
nodeSelector:
kubernetes.io/os: "linux"
Expand Down
Loading
Loading