Skip to content

Commit 356727d

Browse files
committed
initial commit
1 parent 73e7a58 commit 356727d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2623
-0
lines changed

.dockerignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Dockerfile
2+
deploy/
3+
bin/
4+
.dockerignore
5+
scripts/

.gitignore

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
# Created by https://www.toptal.com/developers/gitignore/api/go,visualstudiocode
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=go,visualstudiocode
4+
5+
### Go ###
6+
# If you prefer the allow list template instead of the deny list, see community template:
7+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
8+
#
9+
# Binaries for programs and plugins
10+
*.exe
11+
*.exe~
12+
*.dll
13+
*.so
14+
*.dylib
15+
16+
# Test binary, built with `go test -c`
17+
*.test
18+
19+
# Output of the go coverage tool, specifically when used with LiteIDE
20+
*.out
21+
22+
# Dependency directories (remove the comment below to include it)
23+
# vendor/
24+
25+
# Go workspace file
26+
go.work
27+
28+
### Go Patch ###
29+
/vendor/
30+
/Godeps/
31+
32+
### VisualStudioCode ###
33+
.vscode/*
34+
!.vscode/settings.json
35+
!.vscode/tasks.json
36+
!.vscode/launch.json
37+
!.vscode/extensions.json
38+
!.vscode/*.code-snippets
39+
40+
# Local History for Visual Studio Code
41+
.history/
42+
43+
# Built Visual Studio Code Extensions
44+
*.vsix
45+
46+
### VisualStudioCode Patch ###
47+
# Ignore all local history of files
48+
.history
49+
.ionide
50+
51+
# Support for Project snippet scope
52+
.vscode/*.code-snippets
53+
54+
# Ignore code-workspaces
55+
*.code-workspace
56+
57+
bin/
58+
.env
59+
.vscode/
60+
.local/

Dockerfile

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
FROM golang:1.18 as common_builder
2+
3+
WORKDIR /build
4+
COPY go.mod .
5+
COPY go.sum .
6+
RUN go mod download
7+
8+
COPY Makefile .
9+
COPY internal/common ./internal/common
10+
11+
FROM common_builder as device_plugin_builder
12+
13+
COPY cmd/device-plugin ./cmd/device-plugin
14+
COPY internal/deviceplugin ./internal/deviceplugin
15+
RUN make compile
16+
17+
FROM common_builder as status_updater_builder
18+
19+
COPY cmd/status-updater ./cmd/status-updater
20+
COPY internal/status-updater ./internal/status-updater
21+
RUN make compile
22+
23+
FROM common_builder as status_exporter_builder
24+
25+
COPY cmd/status-exporter ./cmd/status-exporter
26+
COPY internal/status-exporter ./internal/status-exporter
27+
RUN make compile
28+
29+
FROM golang:1.18 as device_plugin
30+
31+
COPY --from=device_plugin_builder /build/bin/device-plugin /bin/
32+
ENTRYPOINT ["/bin/device-plugin"]
33+
34+
FROM golang:1.18 as status_updater
35+
36+
COPY --from=status_updater_builder /build/bin/status-updater /bin/
37+
ENTRYPOINT ["/bin/status-updater"]
38+
39+
FROM golang:1.18 as status_exporter
40+
41+
COPY --from=status_exporter_builder /build/bin/status-exporter /bin/
42+
ENTRYPOINT ["/bin/status-exporter"]
43+
44+
45+
###### Debug images
46+
FROM golang:1.18 as debugger
47+
RUN go install github.com/go-delve/delve/cmd/dlv@latest
48+
49+
FROM debugger as device_plugin_debug
50+
51+
COPY --from=device_plugin_builder /build/bin/device-plugin /bin/
52+
ENTRYPOINT ["/go/bin/dlv", "exec", "--headless", "-l", ":10000", "--api-version=2", "/bin/device-plugin", "--"]
53+
54+
FROM debugger as status_updater_debug
55+
56+
COPY --from=status_updater_builder /build/bin/status-updater /bin/
57+
ENTRYPOINT ["/go/bin/dlv", "exec", "--headless", "-l", ":10000", "--api-version=2", "/bin/status-updater", "--"]

Makefile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
BUILD_DIR="./bin"
2+
3+
compile:
4+
go build -o ${BUILD_DIR}/ ./cmd/...
5+
6+
device-plugin-image:
7+
docker build -t device-plugin --target device_plugin .
8+
9+
status-updater-image:
10+
docker build -t status-updater --target status_updater .
11+
12+
status-exporter-image:
13+
docker build -t status-exporter --target status_exporter .
14+
15+
images: device-plugin-image status-updater-image status-exporter-image
16+
17+
all: compile-all

cmd/device-plugin/main.go

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"os"
6+
"os/signal"
7+
"syscall"
8+
9+
"github.com/run-ai/gpu-mock-stack/internal/common/topology"
10+
"github.com/run-ai/gpu-mock-stack/internal/deviceplugin"
11+
)
12+
13+
func main() {
14+
log.Println("Fake Device Plugin Running")
15+
16+
validateEnvs()
17+
18+
topology, err := topology.GetNodeTopologyFromFs(os.Getenv("TOPOLOGY_PATH"), os.Getenv("NODE_NAME"))
19+
if err != nil {
20+
log.Printf("Failed to get topology: %s\n", err)
21+
os.Exit(1)
22+
}
23+
24+
devicePlugin := deviceplugin.NewDevicePlugin(topology)
25+
devicePlugin.Serve()
26+
27+
sig := make(chan os.Signal, 1)
28+
signal.Notify(sig, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
29+
30+
s := <-sig
31+
log.Printf("Received signal \"%v\"\n", s)
32+
}
33+
34+
func validateEnvs() {
35+
requiredEnvs := []string{"TOPOLOGY_PATH", "NODE_NAME"}
36+
for _, env := range requiredEnvs {
37+
if os.Getenv(env) == "" {
38+
log.Printf("%s must be set\n", env)
39+
os.Exit(1)
40+
}
41+
}
42+
}

cmd/status-exporter/main.go

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"os"
6+
"os/signal"
7+
"syscall"
8+
9+
"github.com/run-ai/gpu-mock-stack/internal/status-exporter/export/labels"
10+
"github.com/run-ai/gpu-mock-stack/internal/status-exporter/export/metrics"
11+
"github.com/run-ai/gpu-mock-stack/internal/status-exporter/watch"
12+
"k8s.io/client-go/kubernetes"
13+
"k8s.io/client-go/rest"
14+
)
15+
16+
func main() {
17+
log.Println("Fake Status Exporter Running")
18+
19+
validateEnvs()
20+
21+
config, err := rest.InClusterConfig()
22+
if err != nil {
23+
panic(err.Error())
24+
}
25+
kubeclient := kubernetes.NewForConfigOrDie(config)
26+
27+
// Watch for changes, and export metrics
28+
stopper := make(chan struct{})
29+
watcher := watch.NewKubeWatcher(kubeclient)
30+
metricExporter := metrics.NewMetricsExporter(watcher)
31+
labelsExporter := labels.NewLabelsExporter(watcher, kubeclient)
32+
33+
// Wait for
34+
go watcher.Watch(stopper)
35+
go metricExporter.Run(stopper)
36+
go labelsExporter.Run(stopper)
37+
38+
sig := make(chan os.Signal, 1)
39+
signal.Notify(sig, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
40+
41+
s := <-sig
42+
log.Printf("Received signal \"%v\"\n", s)
43+
close(stopper)
44+
}
45+
46+
func validateEnvs() {
47+
requiredEnvs := []string{"NODE_NAME", "TOPOLOGY_CM_NAME", "TOPOLOGY_CM_NAMESPACE"}
48+
for _, env := range requiredEnvs {
49+
if os.Getenv(env) == "" {
50+
log.Printf("%s must be set\n", env)
51+
os.Exit(1)
52+
}
53+
}
54+
}

cmd/status-updater/main.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"os"
6+
"os/signal"
7+
"syscall"
8+
9+
"github.com/run-ai/gpu-mock-stack/internal/status-updater/handle"
10+
"github.com/run-ai/gpu-mock-stack/internal/status-updater/inform"
11+
"k8s.io/client-go/kubernetes"
12+
"k8s.io/client-go/rest"
13+
)
14+
15+
func main() {
16+
log.Println("Fake Status Updater Running")
17+
18+
validateEnvs()
19+
20+
config, err := rest.InClusterConfig()
21+
if err != nil {
22+
panic(err.Error())
23+
}
24+
kubeclient := kubernetes.NewForConfigOrDie(config)
25+
26+
informer := inform.NewInformer(kubeclient)
27+
handler := handle.NewPodEventHandler(kubeclient, informer)
28+
29+
stopper := make(chan struct{})
30+
go handler.Run(stopper)
31+
go informer.Run(stopper)
32+
33+
sig := make(chan os.Signal, 1)
34+
signal.Notify(sig, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
35+
36+
s := <-sig
37+
log.Printf("Received signal \"%v\"\n", s)
38+
close(stopper)
39+
}
40+
41+
func validateEnvs() {
42+
requiredEnvs := []string{"TOPOLOGY_CM_NAME", "TOPOLOGY_CM_NAMESPACE"}
43+
for _, env := range requiredEnvs {
44+
if os.Getenv(env) == "" {
45+
log.Printf("%s must be set\n", env)
46+
os.Exit(1)
47+
}
48+
}
49+
}

deploy/fake-gpu-operator/.helmignore

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

deploy/fake-gpu-operator/Chart.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: fake-gpu-operator
3+
description: A Helm chart for Kubernetes
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "1.16.0"

0 commit comments

Comments
 (0)