Skip to content
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
1 change: 1 addition & 0 deletions cns/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (

type CNSConfig struct {
ChannelMode string
EnablePprof bool
InitializeFromCNI bool
ManagedSettings ManagedSettings
MetricsBindAddress string
Expand Down
7 changes: 2 additions & 5 deletions cns/healthserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@ import (
"github.com/labstack/echo/v4"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.uber.org/zap"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/metrics"
)

func Start(log *zap.Logger, addr string) {
e := echo.New()

e.GET("/healthz", healthz)
e.GET("/healthz", echo.WrapHandler(http.StripPrefix("/healthz", &healthz.Handler{})))
e.GET("/metrics", echo.WrapHandler(promhttp.HandlerFor(metrics.Registry, promhttp.HandlerOpts{
ErrorHandling: promhttp.HTTPErrorOnError,
})))
if err := e.Start(addr); err != nil {
log.Error("failed to run healthserver", zap.Error(err))
}
}

func healthz(c echo.Context) error {
return c.NoContent(http.StatusOK) //nolint:wrapcheck // ignore
}
20 changes: 20 additions & 0 deletions cns/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"net/http/pprof"
"os"
"os/signal"
"runtime"
Expand Down Expand Up @@ -55,6 +56,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/healthz"
)

const (
Expand Down Expand Up @@ -1040,6 +1042,24 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
return errors.Wrapf(err, "failed to setup reconciler with manager")
}

// adding some routes to the root service mux
mux := httpRestServiceImplementation.Listener.GetMux()
mux.Handle("/readyz", http.StripPrefix("/readyz", &healthz.Handler{}))
if cnsconfig.EnablePprof {
// add pprof endpoints
mux.Handle("/debug/pprof/allocs", pprof.Handler("allocs"))
mux.Handle("/debug/pprof/block", pprof.Handler("block"))
mux.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine"))
mux.Handle("/debug/pprof/heap", pprof.Handler("heap"))
mux.Handle("/debug/pprof/mutex", pprof.Handler("mutex"))
mux.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
}

// Start the Manager which starts the reconcile loop.
// The Reconciler will send an initial NodeNetworkConfig update to the PoolMonitor, starting the
// Monitor's internal loop.
Expand Down