Skip to content

Commit

Permalink
koordetector: add main pkg (#10)
Browse files Browse the repository at this point in the history
Signed-off-by: 佑祎 <zzw261520@alibaba-inc.com>
  • Loading branch information
zwzhang0107 authored Mar 2, 2023
1 parent 9071d03 commit 1736159
Show file tree
Hide file tree
Showing 7 changed files with 1,275 additions and 102 deletions.
69 changes: 69 additions & 0 deletions cmd/koordetector/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package koordetector

import (
"flag"
"github.com/koordinator-sh/koordetector/cmd/koordetector/options"
"github.com/koordinator-sh/koordetector/pkg/features"
"github.com/koordinator-sh/koordetector/pkg/koordetector"
"github.com/koordinator-sh/koordetector/pkg/koordetector/config"
"github.com/prometheus/client_golang/prometheus/promhttp"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
"net/http"
"os"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
"time"
)

func init() {}

func main() {
cfg := config.NewConfiguration()
cfg.InitFlags(flag.CommandLine)
flag.Parse()

go wait.Forever(klog.Flush, 5*time.Second)
defer klog.Flush()

if *options.EnablePprof {
go func() {
klog.V(4).Infof("Starting pprof on %v", *options.PprofAddr)
if err := http.ListenAndServe(*options.PprofAddr, nil); err != nil {
klog.Errorf("Unable to start pprof on %v, error: %v", *options.PprofAddr, err)
}
}()
}

if err := features.DefaultMutableKoordetectorFeatureGate.SetFromMap(cfg.FeatureGates); err != nil {
klog.Fatalf("Unable to setup feature-gates: %v", err)
}

stopCtx := signals.SetupSignalHandler()


// Get a config to talk to the apiserver
klog.Info("Setting up client for koordlet")
err := cfg.InitClient()
if err != nil {
klog.Error("Unable to setup client config: ", err)
os.Exit(1)
}

d, err := koordetector.NewDaemon(cfg)
if err != nil {
klog.Error("Unable to setup koordlet daemon: ", err)
os.Exit(1)
}

// Expose the Prometheus http endpoint
go func() {
klog.Infof("Starting prometheus server on %v", *options.ServerAddr)
http.Handle("/metrics", promhttp.Handler())
// http.HandleFunc("/healthz", d.HealthzHandler())
klog.Fatalf("Prometheus monitoring failed: %v", http.ListenAndServe(*options.ServerAddr, nil))
}()

// Start the Cmd
klog.Info("Starting the koordlet daemon")
d.Run(stopCtx.Done())
}
9 changes: 9 additions & 0 deletions cmd/koordetector/options/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package options

import "flag"

var (
ServerAddr = flag.String("addr", ":9416", "port of koordlet server")
EnablePprof = flag.Bool("enable-pprof", false, "Enable pprof for controller manager.")
PprofAddr = flag.String("pprof-addr", ":9417", "The address the pprof binds to.")
)
201 changes: 165 additions & 36 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,200 @@ module github.com/koordinator-sh/koordetector
go 1.17

require (
github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.1
github.com/koordinator-sh/koordinator v1.1.1-0.20230301120008-b66fbe0f57f0
github.com/onsi/ginkgo v1.16.4
github.com/onsi/gomega v1.15.0
k8s.io/apimachinery v0.22.6
k8s.io/client-go v0.22.6
github.com/onsi/gomega v1.23.0
github.com/prometheus/client_golang v1.14.0
k8s.io/apimachinery v0.26.0
k8s.io/client-go v0.26.0
k8s.io/component-base v0.26.0
k8s.io/klog/v2 v2.80.1
sigs.k8s.io/controller-runtime v0.10.3
)

require (
cloud.google.com/go v0.54.0 // indirect
cloud.google.com/go v0.65.0 // indirect
github.com/Azure/azure-sdk-for-go v55.0.0+incompatible // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.18 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.13 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
github.com/Azure/go-autorest/autorest/validation v0.1.0 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/JeffAshton/win_pdh v0.0.0-20161109143554-76bb4ee9f0ab // indirect
github.com/Microsoft/go-winio v0.4.17 // indirect
github.com/NVIDIA/go-nvml v0.11.6-0.0.20220823120812-7e2082095e82 // indirect
github.com/aws/aws-sdk-go v1.38.49 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/bits-and-blooms/bitset v1.2.0 // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/cakturk/go-netstat v0.0.0-20200220111822-e5b49efee7a5 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/checkpoint-restore/go-criu/v5 v5.0.0 // indirect
github.com/cilium/ebpf v0.6.2 // indirect
github.com/containerd/console v1.0.2 // indirect
github.com/containerd/containerd v1.5.10 // indirect
github.com/containerd/ttrpc v1.1.0 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/cyphar/filepath-securejoin v0.2.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/evanphx/json-patch v4.11.0+incompatible // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/docker v20.10.21+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
github.com/euank/go-kmsg-parser v2.0.0+incompatible // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/go-logr/logr v0.4.0 // indirect
github.com/go-logr/zapr v0.4.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.8.1 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/zapr v1.2.3 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.10.0 // indirect
github.com/goccy/go-json v0.9.7 // indirect
github.com/godbus/dbus/v5 v5.0.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.5 // indirect
github.com/google/cadvisor v0.39.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/hodgesds/perf-utils v0.5.1 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jedib0t/go-pretty/v6 v6.4.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/karrick/godirwalk v1.16.1 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
github.com/mistifyio/go-zfs v2.1.2-0.20190413222219-f784269be439+incompatible // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/moby/sys/mountinfo v0.4.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170603005431-491d3605edfb // indirect
github.com/mrunalp/fileutils v0.5.0 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/opencontainers/runc v1.0.2 // indirect
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 // indirect
github.com/opencontainers/selinux v1.8.2 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/seccomp/libseccomp-golang v0.9.1 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spf13/cobra v1.6.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/atomic v1.7.0 // indirect
github.com/stretchr/testify v1.8.1 // indirect
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852 // indirect
github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae // indirect
go.etcd.io/etcd/api/v3 v3.5.5 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.5 // indirect
go.etcd.io/etcd/client/v3 v3.5.5 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.19.0 // indirect
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 // indirect
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
golang.org/x/sys v0.0.0-20210817190340-bfb29a6856f2 // indirect
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
golang.org/x/text v0.3.6 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/net v0.3.1-0.20221206200815-1e63c2f08a10 // indirect
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/term v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.26.0 // indirect
google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 // indirect
google.golang.org/grpc v1.49.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/api v0.22.6 // indirect
k8s.io/apiextensions-apiserver v0.22.2 // indirect
k8s.io/component-base v0.22.2 // indirect
k8s.io/klog/v2 v2.9.0 // indirect
k8s.io/kube-openapi v0.0.0-20211109043538-20434351676c // indirect
k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/sqlite v1.3.6 // indirect
gorm.io/gorm v1.23.10 // indirect
k8s.io/api v0.26.0 // indirect
k8s.io/apiextensions-apiserver v0.22.6 // indirect
k8s.io/apiserver v0.26.0 // indirect
k8s.io/cloud-provider v0.22.6 // indirect
k8s.io/component-helpers v0.26.0 // indirect
k8s.io/cri-api v0.22.6 // indirect
k8s.io/csi-translation-lib v0.22.6 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/kube-scheduler v0.22.6 // indirect
k8s.io/kubelet v0.22.6 // indirect
k8s.io/kubernetes v1.22.6 // indirect
k8s.io/legacy-cloud-providers v0.0.0 // indirect
k8s.io/mount-utils v0.22.6 // indirect
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448 // indirect
sigs.k8s.io/scheduler-plugins v0.22.6 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace (
github.com/google/cadvisor => github.com/koordinator-sh/cadvisor v0.0.0-20220919031936-833eb74e858e
go.opentelemetry.io/contrib => go.opentelemetry.io/contrib v0.20.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc => go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.20.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp => go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.20.0
go.opentelemetry.io/otel => go.opentelemetry.io/otel v0.20.0
go.opentelemetry.io/otel/metric => go.opentelemetry.io/otel/metric v0.20.0
go.opentelemetry.io/otel/sdk => go.opentelemetry.io/otel/sdk v0.20.0
go.opentelemetry.io/otel/trace => go.opentelemetry.io/otel/trace v0.20.0
go.opentelemetry.io/proto/otlp => go.opentelemetry.io/proto/otlp v0.7.0
golang.org/x/crypto => golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
golang.org/x/time => golang.org/x/time v0.3.0
k8s.io/api => k8s.io/api v0.22.6
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.22.6
k8s.io/apimachinery => k8s.io/apimachinery v0.22.6
k8s.io/apiserver => k8s.io/apiserver v0.22.6
k8s.io/cli-runtime => k8s.io/cli-runtime v0.22.6
k8s.io/client-go => k8s.io/client-go v0.22.6
k8s.io/cloud-provider => k8s.io/cloud-provider v0.22.6
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.22.6
k8s.io/code-generator => k8s.io/code-generator v0.22.6
k8s.io/component-base => k8s.io/component-base v0.22.6
k8s.io/component-helpers => k8s.io/component-helpers v0.22.6
k8s.io/controller-manager => k8s.io/controller-manager v0.22.6
k8s.io/cri-api => k8s.io/cri-api v0.22.6
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.22.6
k8s.io/gengo => k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.22.6
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.22.6
k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20211109043538-20434351676c
k8s.io/kube-proxy => k8s.io/kube-proxy v0.22.6
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.22.6
k8s.io/kubectl => k8s.io/kubectl v0.22.6
k8s.io/kubelet => k8s.io/kubelet v0.22.6
k8s.io/kubernetes => k8s.io/kubernetes v1.22.6
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.22.6
k8s.io/metrics => k8s.io/metrics v0.22.6
k8s.io/mount-utils => k8s.io/mount-utils v0.22.6
k8s.io/pod-security-admission => k8s.io/pod-security-admission v0.22.6
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.22.6
sigs.k8s.io/descheduler => sigs.k8s.io/descheduler v0.26.1-0.20230216092500-02b1e8b8b9c1
sigs.k8s.io/scheduler-plugins => sigs.k8s.io/scheduler-plugins v0.22.6
)
Loading

0 comments on commit 1736159

Please sign in to comment.