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

koordetector: make koordetector run and compatible with different kernels #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .licenseignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
vendor
pkg/koordetector/util/cpu_schedule_latency/bpf_bpfeb.go
pkg/koordetector/util/cpu_schedule_latency/bpf_bpfel.go
10 changes: 6 additions & 4 deletions docker/interference-manager.dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM golang:1.17 as builder
FROM golang:1.17-alpine as builder
WORKDIR /go/src/github.com/koordinator-sh/koordetector
RUN apk add --update make git bash rsync gcc musl-dev

COPY ../go.mod go.mod
COPY ../go.sum go.sum
COPY go.mod go.mod
COPY go.sum go.sum

RUN go mod download

Expand All @@ -13,7 +14,8 @@ COPY pkg/ pkg/

RUN GOOS=linux GOARCH=amd64 go build -a -o interference-manager cmd/interference-manager/main.go

FROM gcr.io/distroless/static:nonroot
FROM alpine:3.12
RUN apk add --update bash net-tools iproute2 logrotate less rsync util-linux lvm2
WORKDIR /
COPY --from=builder /go/src/github.com/koordinator-sh/koordetector/interference-manager .
ENTRYPOINT ["/interference-manager"]
11 changes: 7 additions & 4 deletions docker/koordetector.dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM golang:1.17 as builder
FROM golang:1.17-alpine as builder
WORKDIR /go/src/github.com/koordinator-sh/koordetector
RUN apk add --update make git bash rsync gcc musl-dev

COPY ../go.mod go.mod
COPY ../go.sum go.sum
COPY go.mod go.mod
COPY go.sum go.sum

RUN go mod download

Expand All @@ -13,7 +14,9 @@ COPY pkg/ pkg/

RUN GOOS=linux GOARCH=amd64 go build -a -o koordetector cmd/koordetector/main.go

FROM gcr.io/distroless/static:nonroot
FROM alpine:3.12
RUN apk add --update bash net-tools iproute2 logrotate less rsync util-linux lvm2
WORKDIR /
COPY --from=builder /go/src/github.com/koordinator-sh/koordetector/koordetector .
COPY --from=builder /go/src/github.com/koordinator-sh/koordetector/pkg/koordetector/util/ebpf/core .
ENTRYPOINT ["/koordetector"]
13 changes: 1 addition & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.17

require (
github.com/cilium/ebpf v0.8.1
github.com/docker/docker v20.10.21+incompatible
github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.1
github.com/koordinator-sh/koordinator v1.1.1-0.20230301120008-b66fbe0f57f0
github.com/prometheus/client_golang v1.14.0
Expand Down Expand Up @@ -33,10 +34,7 @@ require (
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/bits-and-blooms/bitset v1.2.0 // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
Expand All @@ -51,10 +49,8 @@ require (
github.com/cyphar/filepath-securejoin v0.2.2 // indirect
github.com/davecgh/go-spew v1.1.1 // 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
Expand All @@ -80,15 +76,11 @@ require (
github.com/imdario/mergo v0.3.12 // 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
Expand All @@ -103,7 +95,6 @@ require (
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/pmezard/go-difflib v1.0.0 // indirect
Expand Down Expand Up @@ -137,8 +128,6 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.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/apiextensions-apiserver v0.22.6 // indirect
k8s.io/apiserver v0.26.0 // indirect
k8s.io/cloud-provider v0.22.6 // indirect
Expand Down
13 changes: 0 additions & 13 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBp
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/GoogleCloudPlatform/k8s-cloud-provider v0.0.0-20200415212048-7901bc822317/go.mod h1:DF8FZRxMHMGv/vP2lQP6h+dYzzjpuRn24VeRiYn3qjQ=
github.com/JeffAshton/win_pdh v0.0.0-20161109143554-76bb4ee9f0ab h1:UKkYhof1njT1/xq4SEg5z+VpTgjmNeHwPGRQl7takDI=
github.com/JeffAshton/win_pdh v0.0.0-20161109143554-76bb4ee9f0ab/go.mod h1:3VYc5hodBMJ5+l/7J4xAyMeuM2PNuepvHlGs8yilUCA=
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd/go.mod h1:64YHyfSL2R96J44Nlwm39UHepQbyR5q10x7iYa1ks2E=
github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA=
Expand All @@ -97,7 +96,6 @@ github.com/Microsoft/hcsshim v0.8.16/go.mod h1:o5/SZqmR7x9JNKsW3pu+nqHm0MF8vbA+V
github.com/Microsoft/hcsshim v0.8.23/go.mod h1:4zegtUJth7lAvFyc6cH2gGQ5B3OFQim01nnU2M8jKDg=
github.com/Microsoft/hcsshim/test v0.0.0-20201218223536-d3e5debf77da/go.mod h1:5hlzMzRKMLyo42nCZ9oml8AdTlq/0cvIaBv6tK1RehU=
github.com/Microsoft/hcsshim/test v0.0.0-20210227013316-43a75bb4edd3/go.mod h1:mw7qgWloBUl75W/gVH3cQszUg1+gUITj7D6NY7ywVnY=
github.com/NVIDIA/go-nvml v0.11.6-0.0.20220823120812-7e2082095e82 h1:x751Xx1tdxkiA/sdkv2J769n21UbYKzVOpe9S/h1M3k=
github.com/NVIDIA/go-nvml v0.11.6-0.0.20220823120812-7e2082095e82/go.mod h1:hy7HYeQy335x6nEss0Ne3PYqleRa6Ct+VKD9RQ4nyFs=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
Expand All @@ -124,7 +122,6 @@ github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:l
github.com/auth0/go-jwt-middleware v1.0.1/go.mod h1:YSeUX3z6+TF2H+7padiEqNJ73Zy9vXW72U//IgN0BIM=
github.com/aws/aws-sdk-go v1.15.11/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0=
github.com/aws/aws-sdk-go v1.35.24/go.mod h1:tlPOdRjfxPBpNIwqDj61rmsnA85v9jc0Ps9+muhnW+k=
github.com/aws/aws-sdk-go v1.38.49 h1:E31vxjCe6a5I+mJLmUGaZobiWmg9KdWaud9IfceYeYQ=
github.com/aws/aws-sdk-go v1.38.49/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
Expand Down Expand Up @@ -187,7 +184,6 @@ github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWH
github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h6jFvWxBdQXxjopDMZyH2UVceIRfR84bdzbkoKrsWNo=
github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA=
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
github.com/container-storage-interface/spec v1.5.0 h1:lvKxe3uLgqQeVQcrnL2CPQKISoKjTJxojEs9cBk+HXo=
github.com/container-storage-interface/spec v1.5.0/go.mod h1:8K96oQNkJ7pFcC2R9Z1ynGGBB1I93kcS6PGg3SsOk8s=
github.com/containerd/aufs v0.0.0-20200908144142-dab0cbea06f4/go.mod h1:nukgQABAEopAHvB6j7cnP5zJ+/3aVcE7hCYqvIwAHyE=
github.com/containerd/aufs v0.0.0-20201003224125-76a6863f2989/go.mod h1:AkGGQs9NM2vtYHaUen+NljV0/baGCAPELGm2q9ZXpWU=
Expand Down Expand Up @@ -343,7 +339,6 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153 h1:yUdfgN0XgIJw7foRItutHYUIhlcKzcSf5vDpdhQAKTc=
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/emicklei/go-restful v2.9.5+incompatible h1:spTtZBk5DYEvbxMVutUuTyh1Ao2r4iyvLdACqsl/Ljk=
github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/emicklei/go-restful/v3 v3.9.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down Expand Up @@ -595,16 +590,12 @@ github.com/jedib0t/go-pretty/v6 v6.4.0 h1:YlI/2zYDrweA4MThiYMKtGRfT+2qZOO65ulej8
github.com/jedib0t/go-pretty/v6 v6.4.0/go.mod h1:MgmISkTWDSFu0xOqiZ0mKNntMQ2mDgOcwOkwBEkMDJI=
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.0.0-20160803190731-bd40a432e4c7/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ=
Expand Down Expand Up @@ -677,7 +668,6 @@ github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-shellwords v1.0.3/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o=
github.com/mattn/go-sqlite3 v1.14.12/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U=
github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
Expand Down Expand Up @@ -784,7 +774,6 @@ github.com/openkruise/kruise-api v1.3.0/go.mod h1:9ZX+ycdHKNzcA5ezAf35xOa2Mwfa2B
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/paypal/load-watcher v0.2.1/go.mod h1:MMCDf8aXF5k+K2q6AtMOBZItCvZ3oFAk+zNO4OAtp0w=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
Expand Down Expand Up @@ -1554,10 +1543,8 @@ gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/sqlite v1.3.6 h1:Fi8xNYCUplOqWiPa3/GuCeowRNBRGTf62DEmhMDHeQQ=
gorm.io/driver/sqlite v1.3.6/go.mod h1:Sg1/pvnKtbQ7jLXxfZa+jSHvoX8hoZA8cn4xllOMTgE=
gorm.io/gorm v1.23.4/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
gorm.io/gorm v1.23.10 h1:4Ne9ZbzID9GUxRkllxN4WjJKpsHx8YbKvekVdgyWh24=
gorm.io/gorm v1.23.10/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
Expand Down
12 changes: 11 additions & 1 deletion pkg/features/koordetector_features.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ import (
"k8s.io/component-base/featuregate"
)

const (
// owner: @songtao98 @zwzhang0107
// alpha: v1.0
//
// CSLCollector enables cpu schedule latency collector feature of koordetector.
CSLCollector featuregate.Feature = "CSLCollector"
)

func init() {
runtime.Must(DefaultMutableKoordetectorFeatureGate.Add(defaultKoordetectorFeatureGates))
}
Expand All @@ -29,5 +37,7 @@ var (
DefaultMutableKoordetectorFeatureGate featuregate.MutableFeatureGate = featuregate.NewFeatureGate()
DefaultKoordetectorFeatureGate featuregate.FeatureGate = DefaultMutableKoordetectorFeatureGate

defaultKoordetectorFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{}
defaultKoordetectorFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{
CSLCollector: {Default: false, PreRelease: featuregate.Alpha},
}
)
17 changes: 14 additions & 3 deletions pkg/koordetector/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,36 @@ import (
"flag"
"strings"

"github.com/koordinator-sh/koordinator/pkg/koordlet/util/system"
"k8s.io/client-go/rest"
cliflag "k8s.io/component-base/cli/flag"
"sigs.k8s.io/controller-runtime/pkg/client/config"

"github.com/koordinator-sh/koordetector/pkg/features"
maframework "github.com/koordinator-sh/koordetector/pkg/koordetector/metricsadvisor/framework"
"github.com/koordinator-sh/koordetector/pkg/koordetector/statesinformer"
)

type Configuration struct {
KubeRestConf *rest.Config
FeatureGates map[string]bool
KubeRestConf *rest.Config
FeatureGates map[string]bool
StatesInformerConf *statesinformer.Config
CollectorConf *maframework.Config
}

func NewConfiguration() *Configuration {
return &Configuration{}
return &Configuration{
StatesInformerConf: statesinformer.NewDefaultConfig(),
CollectorConf: maframework.NewDefaultConfig(),
}
}

func (c *Configuration) InitFlags(fs *flag.FlagSet) {
fs.Var(cliflag.NewMapStringBool(&c.FeatureGates), "feature-gates", "A set of key=value pairs that describe feature gates for alpha/experimental features. "+
"Options are:\n"+strings.Join(features.DefaultKoordetectorFeatureGate.KnownFeatures(), "\n"))
system.Conf.InitFlags(fs)
c.StatesInformerConf.InitFlags(fs)
c.CollectorConf.InitFlags(fs)
}

func (c *Configuration) InitClient() error {
Expand Down
71 changes: 66 additions & 5 deletions pkg/koordetector/koordetector.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,24 @@ limitations under the License.
package koordetector

import (
"context"
"fmt"
"os"
"time"

"github.com/koordinator-sh/koordinator/pkg/koordlet/metricsadvisor"
"github.com/koordinator-sh/koordinator/pkg/koordlet/util/system"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apiruntime "k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
clientset "k8s.io/client-go/kubernetes"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/cache"
"k8s.io/klog/v2"

"github.com/koordinator-sh/koordetector/pkg/koordetector/config"
"github.com/koordinator-sh/koordetector/pkg/koordetector/metrics"
"github.com/koordinator-sh/koordetector/pkg/koordetector/metricsadvisor"
"github.com/koordinator-sh/koordetector/pkg/koordetector/statesinformer"
)

Expand Down Expand Up @@ -56,18 +62,48 @@ func NewDaemon(config *config.Configuration) (Daemon, error) {
return nil, fmt.Errorf("failed to new daemon: NODE_NAME env is empty")
}
klog.Infof("NODE_NAME is %v,start time %v", nodeName, float64(time.Now().Unix()))
// metrics.RecordKoordletStartTime(nodeName, float64(time.Now().Unix()))
metrics.RecordKoordetectorStartTime(nodeName, float64(time.Now().Unix()))

kubeClient := clientset.NewForConfigOrDie(config.KubeRestConf)

// only sync pod info
statesInformerConf := statesinformer.NewDefaultConfig()

statesInformer := statesinformer.NewStatesInformer(statesInformerConf, kubeClient, nodeName)
statesInformer := statesinformer.NewStatesInformer(config.StatesInformerConf, kubeClient, nodeName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now we can consider import statesinformer pkg from koordlet directly?


// setup cgroup path formatter from cgroup driver type
var detectCgroupDriver system.CgroupDriverType
if pollErr := wait.PollImmediate(time.Second*10, time.Minute, func() (bool, error) {
driver := system.GuessCgroupDriverFromCgroupName()
if driver.Validate() {
detectCgroupDriver = driver
return true, nil
}
klog.Infof("can not detect cgroup driver from 'kubepods' cgroup name")

node, err := kubeClient.CoreV1().Nodes().Get(context.TODO(), nodeName, v1.GetOptions{})
if err != nil || node == nil {
klog.Error("Can't get node")
return false, nil
}

port := int(node.Status.DaemonEndpoints.KubeletEndpoint.Port)
if driver, err := system.GuessCgroupDriverFromKubeletPort(port); err == nil && driver.Validate() {
detectCgroupDriver = driver
return true, nil
} else {
klog.Errorf("guess kubelet cgroup driver failed, retry...: %v", err)
return false, nil
}
}); pollErr != nil {
return nil, fmt.Errorf("can not detect kubelet cgroup driver: %v", pollErr)
}
system.SetupCgroupPathFormatter(detectCgroupDriver)
klog.Infof("Node %s use '%s' as cgroup driver", nodeName, string(detectCgroupDriver))

// add metric collector
collectorService := metricsadvisor.NewMetricAdvisor(config.CollectorConf, statesInformer)

d := &daemon{
collector: collectorService,
statesInformer: statesInformer,
}
return d, nil
Expand All @@ -77,7 +113,32 @@ func (d *daemon) Run(stopCh <-chan struct{}) {
defer utilruntime.HandleCrash()
klog.Infof("Starting daemon")

// start states informer
go func() {
if err := d.statesInformer.Run(stopCh); err != nil {
klog.Fatalf("Unable to run the states informer: ", err)
}
}()
// wait for metric advisor sync
if !cache.WaitForCacheSync(stopCh, d.statesInformer.HasSynced) {
klog.Fatalf("time out waiting for states informer to sync")
}

// start metric advisor
go func() {
if err := d.collector.Run(stopCh); err != nil {
klog.Fatalf("Unable to run the metric advisor: ", err)
}
}()

// wait for metric advisor sync
if !cache.WaitForCacheSync(stopCh, d.collector.HasSynced) {
klog.Fatalf("time out waiting for metric advisor to sync")
}

klog.Info("Start daemon successfully")
<-stopCh
// close all gc goroutines for prometheus metrics
metrics.StopAllExpireMetrics()
klog.Info("Shutting down daemon")
}
Loading