Skip to content
Closed
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
33 changes: 29 additions & 4 deletions cns/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ import (
"github.com/Azure/azure-container-networking/store"
"github.com/avast/retry-go/v3"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus/promhttp"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
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"
"sigs.k8s.io/controller-runtime/pkg/metrics"
)

const (
Expand Down Expand Up @@ -977,10 +980,9 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
})

manager, err := ctrl.NewManager(kubeConfig, ctrl.Options{
Scheme: nodenetworkconfig.Scheme,
MetricsBindAddress: cnsconfig.MetricsBindAddress,
Namespace: "kube-system", // TODO(rbtr): namespace should be in the cns config
NewCache: nodeScopedCache,
Scheme: nodenetworkconfig.Scheme,
Namespace: "kube-system", // TODO(rbtr): namespace should be in the cns config
NewCache: nodeScopedCache,
})
if err != nil {
return errors.Wrap(err, "failed to create manager")
Expand All @@ -999,6 +1001,28 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
return errors.Wrapf(err, "failed to setup reconciler with manager")
}

mux := http.NewServeMux()

/*pprof endpoints
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)
*/

//to reduce
mux.Handle("/metrics", promhttp.HandlerFor(metrics.Registry, promhttp.HandlerOpts{
ErrorHandling: promhttp.HTTPErrorOnError,
}))
healthzhandler := healthz.Handler{}
healthzhandler.Checks["ping"] = healthz.Ping
mux.Handle("/heathz", &healthzhandler)

go func() {
http.ListenAndServe(cnsconfig.MetricsBindAddress, mux)
}()

// 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 Expand Up @@ -1043,6 +1067,7 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
}
}
}()

logger.Printf("initialized and started SyncHostNCVersion loop")

return nil
Expand Down