Skip to content

Commit 75e0fff

Browse files
committed
Claim GPUs during IRI machine create
Contributes to #678
1 parent 99d794f commit 75e0fff

8 files changed

Lines changed: 173 additions & 42 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
bin
99
go.work*
1010

11+
# macOS
12+
.DS_Store
13+
1114
# Test binary, build with `go test -c`
1215
*.test
1316

api/machine.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
apiutils "github.com/ironcore-dev/provider-utils/apiutils/api"
10+
"github.com/ironcore-dev/provider-utils/claimutils/pci"
1011
"k8s.io/utils/ptr"
1112
)
1213

@@ -27,6 +28,7 @@ type MachineSpec struct {
2728

2829
Volumes []*VolumeSpec `json:"volumes"`
2930
NetworkInterfaces []*NetworkInterfaceSpec `json:"networkInterfaces"`
31+
Gpu []pci.Address `json:"gpu"`
3032

3133
ShutdownAt time.Time `json:"shutdownAt,omitempty"`
3234

go.mod

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ require (
1212
github.com/ironcore-dev/ironcore v0.2.5-0.20251024123813-eecafba97af9
1313
github.com/ironcore-dev/ironcore-image v0.2.5
1414
github.com/ironcore-dev/ironcore-net v0.2.4
15-
github.com/ironcore-dev/provider-utils v0.0.0-20251010114402-394db8015df4
15+
github.com/ironcore-dev/provider-utils v0.0.0-20260122120717-e09b622231ba
1616
github.com/moby/term v0.5.2
17-
github.com/onsi/ginkgo/v2 v2.27.4
17+
github.com/onsi/ginkgo/v2 v2.27.5
1818
github.com/onsi/gomega v1.39.0
1919
github.com/prometheus/client_golang v1.23.2
2020
github.com/shirou/gopsutil/v4 v4.25.12
@@ -37,9 +37,8 @@ require (
3737
github.com/Masterminds/semver/v3 v3.4.0 // indirect
3838
github.com/beorn7/perks v1.0.1 // indirect
3939
github.com/cespare/xxhash/v2 v2.3.0 // indirect
40-
github.com/containerd/containerd v1.7.29 // indirect
40+
github.com/containerd/containerd v1.7.30 // indirect
4141
github.com/containerd/errdefs v1.0.0 // indirect
42-
github.com/containerd/errdefs/pkg v0.3.0 // indirect
4342
github.com/containerd/log v0.1.0 // indirect
4443
github.com/containerd/platforms v0.2.1 // indirect
4544
github.com/creack/pty v1.1.21 // indirect
@@ -92,7 +91,7 @@ require (
9291
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
9392
github.com/prometheus/client_model v0.6.2 // indirect
9493
github.com/prometheus/common v0.66.1 // indirect
95-
github.com/prometheus/procfs v0.16.1 // indirect
94+
github.com/prometheus/procfs v0.19.2 // indirect
9695
github.com/sirupsen/logrus v1.9.3 // indirect
9796
github.com/tklauser/go-sysconf v0.3.16 // indirect
9897
github.com/tklauser/numcpus v0.11.0 // indirect

go.sum

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1
66
github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
77
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
88
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
9-
github.com/Microsoft/hcsshim v0.13.0 h1:/BcXOiS6Qi7N9XqUcv27vkIuVOkBEcWstd2pMlWSeaA=
10-
github.com/Microsoft/hcsshim v0.13.0/go.mod h1:9KWJ/8DgU+QzYGupX4tzMhRQE8h6w90lH6HAaclpEok=
9+
github.com/Microsoft/hcsshim v0.11.7 h1:vl/nj3Bar/CvJSYo7gIQPyRWc9f3c6IeSNavBTSZNZQ=
10+
github.com/Microsoft/hcsshim v0.11.7/go.mod h1:MV8xMfmECjl5HdO7U/3/hFVnkmSBjAjmA09d4bExKcU=
1111
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
1212
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
1313
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
@@ -27,23 +27,17 @@ github.com/cenkalti/backoff/v5 v5.0.2/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F9
2727
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
2828
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
2929
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
30-
github.com/containerd/cgroups/v3 v3.0.5 h1:44na7Ud+VwyE7LIoJ8JTNQOa549a8543BmzaJHo6Bzo=
31-
github.com/containerd/cgroups/v3 v3.0.5/go.mod h1:SA5DLYnXO8pTGYiAHXz94qvLQTKfVM5GEVisn4jpins=
32-
github.com/containerd/containerd v1.7.29 h1:90fWABQsaN9mJhGkoVnuzEY+o1XDPbg9BTC9QTAHnuE=
33-
github.com/containerd/containerd v1.7.29/go.mod h1:azUkWcOvHrWvaiUjSQH0fjzuHIwSPg1WL5PshGP4Szs=
34-
github.com/containerd/continuity v0.4.5 h1:ZRoN1sXq9u7V6QoHMcVWGhOwDFqZ4B9i5H6un1Wh0x4=
35-
github.com/containerd/continuity v0.4.5/go.mod h1:/lNJvtJKUQStBzpVQ1+rasXO1LAWtUQssk28EZvJ3nE=
30+
github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw=
31+
github.com/containerd/containerd v1.7.30 h1:/2vezDpLDVGGmkUXmlNPLCCNKHJ5BbC5tJB5JNzQhqE=
32+
github.com/containerd/containerd v1.7.30/go.mod h1:fek494vwJClULlTpExsmOyKCMUAbuVjlFsJQc4/j44M=
33+
github.com/containerd/continuity v0.4.4 h1:/fNVfTJ7wIl/YPMHjf+5H32uFhl63JucB34PlCpMKII=
34+
github.com/containerd/continuity v0.4.4/go.mod h1:/lNJvtJKUQStBzpVQ1+rasXO1LAWtUQssk28EZvJ3nE=
3635
github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI=
3736
github.com/containerd/errdefs v1.0.0/go.mod h1:+YBYIdtsnF4Iw6nWZhJcqGSg/dwvV7tyJ/kCkyJ2k+M=
38-
github.com/containerd/errdefs/pkg v0.3.0 h1:9IKJ06FvyNlexW690DXuQNx2KA2cUJXx151Xdx3ZPPE=
39-
github.com/containerd/errdefs/pkg v0.3.0/go.mod h1:NJw6s9HwNuRhnjJhM7pylWwMyAkmCQvQ4GpJHEqRLVk=
4037
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
4138
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
4239
github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A=
4340
github.com/containerd/platforms v0.2.1/go.mod h1:XHCb+2/hzowdiut9rkudds9bE5yJ7npe7dG/wG+uFPw=
44-
github.com/containerd/typeurl v1.0.2 h1:Chlt8zIieDbzQFzXzAeBEF92KhExuE4p9p92/QmY7aY=
45-
github.com/containerd/typeurl/v2 v2.2.3 h1:yNA/94zxWdvYACdYO8zofhrTVuQY73fFU1y++dYSw40=
46-
github.com/containerd/typeurl/v2 v2.2.3/go.mod h1:95ljDnPfD3bAbDJRugOiShd/DlAAsxGtUBhJxIn7SCk=
4741
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
4842
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
4943
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
@@ -71,8 +65,8 @@ github.com/docker/docker-credential-helpers v0.9.3 h1:gAm/VtF9wgqJMoxzT3Gj5p4AqI
7165
github.com/docker/docker-credential-helpers v0.9.3/go.mod h1:x+4Gbw9aGmChi3qTLZj8Dfn0TD20M/fuWy0E5+WDeCo=
7266
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
7367
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
74-
github.com/docker/go-events v0.0.0-20250114142523-c867878c5e32 h1:EHZfspsnLAz8Hzccd67D5abwLiqoqym2jz/jOS39mCk=
75-
github.com/docker/go-events v0.0.0-20250114142523-c867878c5e32/go.mod h1:Uw6UezgYA44ePAFQYUehOuCzmy5zmg/+nl2ZfMWGkpA=
68+
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c h1:+pKlWGMw7gf6bQ+oDZB4KHQFypsfjYlq/C4rfL7D3g8=
69+
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c/go.mod h1:Uw6UezgYA44ePAFQYUehOuCzmy5zmg/+nl2ZfMWGkpA=
7670
github.com/docker/go-metrics v0.0.1 h1:AgB/0SvBxihN0X8OR4SjsblXkbMvalQ8cjmtKQ2rQV8=
7771
github.com/docker/go-metrics v0.0.1/go.mod h1:cG1hvH2utMXtqgqqYE9plW6lDxS3/5ayHzueweSI3Vw=
7872
github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1 h1:ZClxb8laGDf5arXfYcAtECDFgAgHklGI8CxgjHnXKJ4=
@@ -126,8 +120,8 @@ github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7Lk
126120
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
127121
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
128122
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
129-
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ=
130-
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw=
123+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
124+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
131125
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
132126
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
133127
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@@ -169,8 +163,8 @@ github.com/ironcore-dev/ironcore-image v0.2.5 h1:ImJD3B1p1/JVs5vx7YB3c8dwH/EHyWO
169163
github.com/ironcore-dev/ironcore-image v0.2.5/go.mod h1:pQLc+7dzgjYORTpEM9ORM757Vm14EQRju9hsvR8VT/U=
170164
github.com/ironcore-dev/ironcore-net v0.2.4 h1:r2SqxwStws86KBvxJcK/myRxb946qAZVpPKd1rJzfsQ=
171165
github.com/ironcore-dev/ironcore-net v0.2.4/go.mod h1:dSn6aWF+bxCIeWJzPjDl5dVTH3Rd7wx1LuTQpYUU4Lg=
172-
github.com/ironcore-dev/provider-utils v0.0.0-20251010114402-394db8015df4 h1:sRQ/gcL5z3CqcqI+9If8XmgVk9pK4WebZOAMNFYXREQ=
173-
github.com/ironcore-dev/provider-utils v0.0.0-20251010114402-394db8015df4/go.mod h1:qxuFuJy31Lfu3go5wsGpFGAZwCw1++1EKGJmHG2HbLw=
166+
github.com/ironcore-dev/provider-utils v0.0.0-20260122120717-e09b622231ba h1:edB5U63/ukgZtLRzOlubl8n49iMBoQTfAwF0kFfDnPs=
167+
github.com/ironcore-dev/provider-utils v0.0.0-20260122120717-e09b622231ba/go.mod h1:xCVgs/2BJ6SLwW5zSkhCA7xOKkq5/DJhCtKZSKje0w8=
174168
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
175169
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
176170
github.com/joshdk/go-junit v1.0.0 h1:S86cUKIdwBHWwA6xCmFlf3RTLfVXYQfvanM5Uh+K6GE=
@@ -209,8 +203,8 @@ github.com/moby/locker v1.0.1 h1:fOXqR41zeveg4fFODix+1Ch4mj/gT0NE1XJbp/epuBg=
209203
github.com/moby/locker v1.0.1/go.mod h1:S7SDdo5zpBK84bzzVlKr2V0hz+7x9hWbYC/kq7oQppc=
210204
github.com/moby/spdystream v0.5.0 h1:7r0J1Si3QO/kjRitvSLVVFUjxMEb/YLj6S9FF62JBCU=
211205
github.com/moby/spdystream v0.5.0/go.mod h1:xBAYlnt/ay+11ShkdFKNAG7LsyK/tmNBVvVOwrfMgdI=
212-
github.com/moby/sys/mountinfo v0.7.2 h1:1shs6aH5s4o5H2zQLn796ADW1wMrIwHsyJ2v9KouLrg=
213-
github.com/moby/sys/mountinfo v0.7.2/go.mod h1:1YOa8w8Ih7uW0wALDUgT1dTTSBrZ+HiBLGws92L2RU4=
206+
github.com/moby/sys/mountinfo v0.6.2 h1:BzJjoreD5BMFNmD9Rus6gdd1pLuecOFPt8wC+Vygl78=
207+
github.com/moby/sys/mountinfo v0.6.2/go.mod h1:IJb6JQeOklcdMU9F5xQ8ZALD+CUr5VlGpwtX+VE0rpI=
214208
github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g=
215209
github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
216210
github.com/moby/term v0.5.2 h1:6qk3FJAFDs6i/q3W/pQ97SX192qKfZgGjCQqfCJkgzQ=
@@ -228,8 +222,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m
228222
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
229223
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus=
230224
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
231-
github.com/onsi/ginkgo/v2 v2.27.4 h1:fcEcQW/A++6aZAZQNUmNjvA9PSOzefMJBerHJ4t8v8Y=
232-
github.com/onsi/ginkgo/v2 v2.27.4/go.mod h1:ArE1D/XhNXBXCBkKOLkbsb2c81dQHCRcF5zwn/ykDRo=
225+
github.com/onsi/ginkgo/v2 v2.27.5 h1:ZeVgZMx2PDMdJm/+w5fE/OyG6ILo1Y3e+QX4zSR0zTE=
226+
github.com/onsi/ginkgo/v2 v2.27.5/go.mod h1:ArE1D/XhNXBXCBkKOLkbsb2c81dQHCRcF5zwn/ykDRo=
233227
github.com/onsi/gomega v1.39.0 h1:y2ROC3hKFmQZJNFeGAMeHZKkjBL65mIZcvrLQBF9k6Q=
234228
github.com/onsi/gomega v1.39.0/go.mod h1:ZCU1pkQcXDO5Sl9/VVEGlDyp+zm0m1cmeG5TOzLgdh4=
235229
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
@@ -262,8 +256,8 @@ github.com/prometheus/common v0.66.1/go.mod h1:gcaUsgf3KfRSwHY4dIMXLPV0K/Wg1oZ8+
262256
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
263257
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
264258
github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ=
265-
github.com/prometheus/procfs v0.16.1 h1:hZ15bTNuirocR6u0JZ6BAHHmwS1p8B4P6MRqxtzMyRg=
266-
github.com/prometheus/procfs v0.16.1/go.mod h1:teAbpZRB1iIAJYREa1LsoWUXykVXA1KlTmWl8x/U+Is=
259+
github.com/prometheus/procfs v0.19.2 h1:zUMhqEW66Ex7OXIiDkll3tl9a1ZdilUOd/F6ZXw4Vws=
260+
github.com/prometheus/procfs v0.19.2/go.mod h1:M0aotyiemPhBCM0z5w87kL22CxfcH05ZpYlu+b4J7mw=
267261
github.com/redis/go-redis/extra/rediscmd/v9 v9.0.5 h1:EaDatTxkdHG+U3Bk4EUr+DZ7fOGwTfezUiUJMaIcaho=
268262
github.com/redis/go-redis/extra/rediscmd/v9 v9.0.5/go.mod h1:fyalQWdtzDBECAQFBJuQe5bzQ02jGd5Qcbgb97Flm7U=
269263
github.com/redis/go-redis/extra/redisotel/v9 v9.0.5 h1:EfpWLLCyXw8PSM2/XNJLjI3Pb27yVE+gIAfeqp8LUCc=
@@ -443,8 +437,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
443437
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
444438
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
445439
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
446-
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
447-
gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
440+
gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o=
441+
gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g=
448442
k8s.io/api v0.34.1 h1:jC+153630BMdlFukegoEL8E/yT7aLyQkIVuwhmwDgJM=
449443
k8s.io/api v0.34.1/go.mod h1:SB80FxFtXn5/gwzCoN6QCtPD7Vbu5w2n1S0J5gFfTYk=
450444
k8s.io/apiextensions-apiserver v0.34.1 h1:NNPBva8FNAPt1iSVwIE0FsdrVriRXMsaWFMqJbII2CI=

internal/server/machine_create.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,41 @@ import (
88
"fmt"
99

1010
"github.com/go-logr/logr"
11+
"github.com/ironcore-dev/ironcore/api/core/v1alpha1"
1112
corev1alpha1 "github.com/ironcore-dev/ironcore/api/core/v1alpha1"
1213
iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1"
1314
"github.com/ironcore-dev/libvirt-provider/api"
1415
apiutils "github.com/ironcore-dev/provider-utils/apiutils/api"
16+
claim "github.com/ironcore-dev/provider-utils/claimutils/claim"
17+
"github.com/ironcore-dev/provider-utils/claimutils/gpu"
18+
"github.com/ironcore-dev/provider-utils/claimutils/pci"
19+
"k8s.io/apimachinery/pkg/api/resource"
1520
)
1621

1722
func calcResources(class *iri.MachineClass) (int64, int64) {
1823
//Todo do some magic
1924
return class.Capabilities.Resources[string(corev1alpha1.ResourceCPU)], class.Capabilities.Resources[string(corev1alpha1.ResourceMemory)]
2025
}
2126

27+
func filterNvidiaGPUResources(capRes map[string]int64) v1alpha1.ResourceList {
28+
nvidiaRes := v1alpha1.ResourceList{}
29+
if _, ok := capRes["nvidia.com/gpu"]; ok {
30+
nvidiaRes["nvidia.com/gpu"] = *resource.NewQuantity(capRes["nvidia.com/gpu"], resource.DecimalSI)
31+
}
32+
return nvidiaRes
33+
}
34+
35+
func getPCIAddresses(claims claim.Claims) []pci.Address {
36+
if gpuClaim, ok := claims["nvidia.com/gpu"]; ok {
37+
gpu := gpuClaim.(gpu.Claim)
38+
return gpu.PCIAddresses()
39+
}
40+
41+
return []pci.Address{}
42+
}
43+
2244
func (s *Server) createMachineFromIRIMachine(ctx context.Context, log logr.Logger, iriMachine *iri.Machine) (*api.Machine, error) {
45+
//TODO cleanup: release GPU claims if other errors occur
2346
log.V(2).Info("Getting libvirt machine config")
2447

2548
switch {
@@ -65,6 +88,11 @@ func (s *Server) createMachineFromIRIMachine(ctx context.Context, log logr.Logge
6588
networkInterfaces = append(networkInterfaces, networkInterfaceSpec)
6689
}
6790

91+
gpus, err := s.resourceClaimer.Claim(filterNvidiaGPUResources(class.Capabilities.Resources))
92+
if err != nil {
93+
return nil, fmt.Errorf("failed to claim GPUs: %w", err)
94+
}
95+
6896
machine := &api.Machine{
6997
Metadata: apiutils.Metadata{
7098
ID: s.idGen.Generate(),
@@ -76,6 +104,7 @@ func (s *Server) createMachineFromIRIMachine(ctx context.Context, log logr.Logge
76104
Volumes: volumes,
77105
Ignition: iriMachine.Spec.IgnitionData,
78106
NetworkInterfaces: networkInterfaces,
107+
Gpu: getPCIAddresses(gpus),
79108
GuestAgent: s.guestAgent,
80109
},
81110
}

internal/server/machine_create_test.go

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@ var _ = Describe("CreateMachine", func() {
5151

5252
By("ensuring the machine gets created in the store")
5353
Eventually(func(g Gomega) *api.Machine {
54-
msList, err := machineStore.List(ctx)
54+
machine, err := machineStore.Get(ctx, createResp.Machine.Metadata.Id)
5555
g.Expect(err).NotTo(HaveOccurred())
56-
g.Expect(msList).NotTo(BeEmpty())
57-
g.Expect(msList).To(HaveLen(1))
58-
return msList[0]
56+
return machine
5957
}).Should(SatisfyAll(
6058
HaveField("Spec.MemoryBytes", int64(8589934592)),
6159
HaveField("Spec.Cpu", int64(4)),
@@ -120,11 +118,9 @@ var _ = Describe("CreateMachine", func() {
120118

121119
By("ensuring the machine gets created in the store")
122120
Eventually(func(g Gomega) *api.Machine {
123-
msList, err := machineStore.List(ctx)
121+
machine, err := machineStore.Get(ctx, createResp.Machine.Metadata.Id)
124122
g.Expect(err).NotTo(HaveOccurred())
125-
g.Expect(msList).NotTo(BeEmpty())
126-
g.Expect(msList).To(HaveLen(1))
127-
return msList[0]
123+
return machine
128124
}).Should(SatisfyAll(
129125
HaveField("Spec.MemoryBytes", int64(8589934592)),
130126
HaveField("Spec.Cpu", int64(4)),
@@ -137,4 +133,60 @@ var _ = Describe("CreateMachine", func() {
137133
))),
138134
))
139135
})
136+
137+
It("should create a machine with GPU support", func(ctx SpecContext) {
138+
By("creating a machine with GPU class")
139+
createResp, err := machineClient.CreateMachine(ctx, &iri.CreateMachineRequest{
140+
Machine: &iri.Machine{
141+
Metadata: &irimeta.ObjectMetadata{
142+
Labels: map[string]string{
143+
"machinepoolletv1alpha1.MachineUIDLabel": "foobar",
144+
},
145+
},
146+
Spec: &iri.MachineSpec{
147+
Power: iri.Power_POWER_ON,
148+
Class: machineClassx2mediumgpu,
149+
},
150+
},
151+
})
152+
Expect(err).NotTo(HaveOccurred())
153+
Expect(createResp).NotTo(BeNil())
154+
DeferCleanup(cleanupMachine(createResp.Machine.Metadata.Id))
155+
156+
By("ensuring the correct creation response")
157+
Expect(createResp).Should(SatisfyAll(
158+
HaveField("Machine.Metadata.Id", Not(BeEmpty())),
159+
HaveField("Machine.Spec.Class", machineClassx2mediumgpu),
160+
))
161+
162+
By("ensuring the machine gets created in the store with GPU")
163+
Eventually(func(g Gomega) *api.Machine {
164+
machine, err := machineStore.Get(ctx, createResp.Machine.Metadata.Id)
165+
g.Expect(err).NotTo(HaveOccurred())
166+
return machine
167+
}).Should(SatisfyAll(
168+
HaveField("Spec.Gpu", Not(BeNil())),
169+
HaveField("Spec.Gpu", HaveLen(2)),
170+
))
171+
})
172+
173+
It("should fail to create a machine when not enough GPUs are available", func(ctx SpecContext) {
174+
By("creating a machine with GPU class requiring more GPUs than available")
175+
createResp, err := machineClient.CreateMachine(ctx, &iri.CreateMachineRequest{
176+
Machine: &iri.Machine{
177+
Metadata: &irimeta.ObjectMetadata{
178+
Labels: map[string]string{
179+
"machinepoolletv1alpha1.MachineUIDLabel": "foobar",
180+
},
181+
},
182+
Spec: &iri.MachineSpec{
183+
Power: iri.Power_POWER_ON,
184+
Class: machineClassx3xlargegpu,
185+
},
186+
},
187+
})
188+
Expect(err).To(HaveOccurred())
189+
Expect(createResp).To(BeNil())
190+
})
191+
140192
})

internal/server/server.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
providernetworkinterface "github.com/ironcore-dev/libvirt-provider/internal/plugins/networkinterface"
2121
"github.com/ironcore-dev/libvirt-provider/internal/plugins/volume"
2222
"github.com/ironcore-dev/libvirt-provider/internal/utils"
23+
claim "github.com/ironcore-dev/provider-utils/claimutils/claim"
2324
"github.com/ironcore-dev/provider-utils/eventutils/recorder"
2425
"github.com/ironcore-dev/provider-utils/storeutils/store"
2526
ctrl "sigs.k8s.io/controller-runtime"
@@ -39,8 +40,9 @@ type Server struct {
3940

4041
networkInterfacePlugin providernetworkinterface.Plugin
4142

42-
volumePlugins *volume.PluginManager
43-
machineClasses MachineClassRegistry
43+
volumePlugins *volume.PluginManager
44+
machineClasses MachineClassRegistry
45+
resourceClaimer claim.Claimer
4446

4547
execRequestCache request.Cache[*iri.ExecRequest]
4648
activeConsoles sync.Map
@@ -66,6 +68,7 @@ type Options struct {
6668

6769
VolumePlugins *volume.PluginManager
6870
NetworkPlugins providernetworkinterface.Plugin
71+
ResourceClaimer claim.Claimer
6972
EnableHugepages bool
7073
GuestAgent api.GuestAgent
7174
}
@@ -90,6 +93,7 @@ func New(opts Options) (*Server, error) {
9093
libvirt: opts.Libvirt,
9194
machineStore: opts.MachineStore,
9295
eventStore: opts.EventStore,
96+
resourceClaimer: opts.ResourceClaimer,
9397
volumePlugins: opts.VolumePlugins,
9498
networkInterfacePlugin: opts.NetworkPlugins,
9599
machineClasses: opts.MachineClasses,

0 commit comments

Comments
 (0)