Advanced Topics
This page covers advanced development topics including profiling and CI infrastructure.
Profiling
Golang pprof profiler can be enabled for debugging and performance analysis.
Enabling the Profiler
- Enable profiler in
operator.yamlby changing value ofENABLE_PROFILERto True - You can change profiler port by editing
PROFILER_PORT- default is 6060 - Deploy new code to cluster - example:
make cluster-sync - Find nmstate-handler pod name -
kubectl get pods -n nmstate - Create port forwarding to pod - example:
kubectl port-forward pod pod_name 6060:6060 -n nmstate - Use
go tool pprof ...to gather relevant metrics
Profiling Examples
- Open in browser
http://localhost:6060/debug/pprof/ - Download memory graph
go tool pprof -png http://localhost:6060/debug/pprof/heap > out.png - Open CLI for cpu 30s sample data
go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30
More examples: https://golang.org/pkg/net/http/pprof/
CI Infrastructure
The kubernetes-nmstate project uses the following CI infrastructure:
- Prow - Main CI system
- Flakefinder - Flaky test detection
Code Structure Notes
- Controllers use controller-runtime reconciliation pattern
- Handler filters events to only its node using labels.SelectorFromSet
- NetworkManager compatibility: >= 1.22 for versions > 0.15.0
- The handler requires a file lock (
pkg/file/lock.go) to prevent concurrent nmstatectl operations - Profiling can be enabled via ENABLE_PROFILER env var (default port 6060)