Skip to content

Commit 4c4030b

Browse files
committed
Add image server management commands to vbmctl
Add `create image-server` and `delete image-server` subcommands, plus image server status in the `status` command. Uses github.com/moby/moby to manage a container serving provisioning images. - New `ImageServerConfig` type; optional `spec.imageServer` in config - `create`: reuses a stopped container or creates a new one with port binding and bind-mount; errors if already running - `delete`: force-removes the container by name - `create bml` / `delete bml`: manage image server alongside VMs - Config defaults, validation, and tests included - Added a new helper pkg: containers Signed-off-by: Tero Kauppinen <tero.kauppinen@est.tech>
1 parent 88dd929 commit 4c4030b

12 files changed

Lines changed: 733 additions & 28 deletions

File tree

hack/ci-e2e.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ if [[ ! -f "${IMAGE_DIR}/${IPA_FILE}" ]]; then
172172
fi
173173

174174
## Start the image server
175-
docker start image-server-e2e || docker run --name image-server-e2e -d \
176-
-p 80:8080 \
177-
-v "${IMAGE_DIR}:/usr/share/nginx/html" nginxinc/nginx-unprivileged
175+
./bin/vbmctl create image-server --host-port 80 --image-dir "${IMAGE_DIR}" --name "vbmctl-image-server-e2e"
178176

179177
# Generate ssh key pair for verifying provisioned BMHs
180178
if [[ ! -f "${IMAGE_DIR}/ssh_testkey" ]]; then

hack/clean-e2e.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
44
cd "${REPO_ROOT}" || exit 1
55

66
docker rm -f vbmc
7-
docker rm -f image-server-e2e
7+
docker rm -f vbmctl-image-server-e2e
88
docker rm -f sushy-tools
99

1010
"${REPO_ROOT}/tools/bmh_test/clean_local_bmh_test_setup.sh" "^bmo-e2e-"

test/go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ require (
77
github.com/metal3-io/baremetal-operator/apis v0.5.1
88
github.com/metal3-io/baremetal-operator/pkg/hardwareutils v0.5.1
99
github.com/metal3-io/ironic-standalone-operator/api v0.8.1
10+
github.com/moby/moby/api v1.54.0
11+
github.com/moby/moby/client v0.3.0
1012
github.com/onsi/ginkgo/v2 v2.28.1
1113
github.com/onsi/gomega v1.39.1
1214
github.com/spf13/cobra v1.10.2
@@ -31,7 +33,7 @@ require (
3133
github.com/BurntSushi/toml v1.4.0 // indirect
3234
github.com/MakeNowJust/heredoc v1.0.0 // indirect
3335
github.com/Masterminds/semver/v3 v3.4.0 // indirect
34-
github.com/Microsoft/go-winio v0.6.0 // indirect
36+
github.com/Microsoft/go-winio v0.6.2 // indirect
3537
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
3638
github.com/adrg/xdg v0.5.3 // indirect
3739
github.com/beorn7/perks v1.0.1 // indirect
@@ -87,7 +89,7 @@ require (
8789
github.com/olekukonko/ll v0.1.1 // indirect
8890
github.com/olekukonko/tablewriter v1.0.9 // indirect
8991
github.com/opencontainers/go-digest v1.0.0 // indirect
90-
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect
92+
github.com/opencontainers/image-spec v1.1.1 // indirect
9193
github.com/pelletier/go-toml v1.9.5 // indirect
9294
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
9395
github.com/pkg/errors v0.9.1 // indirect
@@ -127,7 +129,6 @@ require (
127129
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
128130
gopkg.in/inf.v0 v0.9.1 // indirect
129131
gopkg.in/yaml.v3 v3.0.1 // indirect
130-
gotest.tools/v3 v3.5.0 // indirect
131132
k8s.io/apiserver v0.35.3 // indirect
132133
k8s.io/client-go v0.35.3 // indirect
133134
k8s.io/cluster-bootstrap v0.34.2 // indirect

test/go.sum

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ cel.dev/expr v0.25.1 h1:1KrZg61W6TWSxuNZ37Xy49ps13NUovb66QLprthtwi4=
44
cel.dev/expr v0.25.1/go.mod h1:hrXvqGP6G6gyx8UAHSHJ5RGk//1Oj5nXQ2NI02Nrsg4=
55
dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
66
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
7-
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
8-
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
7+
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c h1:udKWzYgxTojEKWjV8V+WSxDXJ4NFATAsZjh8iIbsQIg=
8+
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
99
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
1010
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
1111
github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ=
@@ -16,8 +16,8 @@ github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1
1616
github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
1717
github.com/Masterminds/sprig/v3 v3.3.0 h1:mQh0Yrg1XPo6vjYXgtf5OtijNAKJRNcTdOOGZe3tPhs=
1818
github.com/Masterminds/sprig/v3 v3.3.0/go.mod h1:Zy1iXRYNqNLUolqCpL4uhk6SHUMAOSCzdgBfDb35Lz0=
19-
github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=
20-
github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE=
19+
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
20+
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
2121
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA=
2222
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g=
2323
github.com/adrg/xdg v0.5.3 h1:xRnxJXne7+oWDatRhR1JLnvuccuIeCoBu2rtuLqQB78=
@@ -175,12 +175,16 @@ github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zx
175175
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
176176
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
177177
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
178+
github.com/moby/moby/api v1.54.0 h1:7kbUgyiKcoBhm0UrWbdrMs7RX8dnwzURKVbZGy2GnL0=
179+
github.com/moby/moby/api v1.54.0/go.mod h1:8mb+ReTlisw4pS6BRzCMts5M49W5M7bKt1cJy/YbAqc=
180+
github.com/moby/moby/client v0.3.0 h1:UUGL5okry+Aomj3WhGt9Aigl3ZOxZGqR7XPo+RLPlKs=
181+
github.com/moby/moby/client v0.3.0/go.mod h1:HJgFbJRvogDQjbM8fqc1MCEm4mIAGMLjXbgwoZp6jCQ=
178182
github.com/moby/sys/atomicwriter v0.1.0 h1:kw5D/EqkBwsBFi0ss9v1VG3wIkVhzGvLklJ+w3A14Sw=
179183
github.com/moby/sys/atomicwriter v0.1.0/go.mod h1:Ul8oqv2ZMNHOceF643P6FKPXeCmYtlQMvpizfsSoaWs=
180184
github.com/moby/sys/sequential v0.6.0 h1:qrx7XFUd/5DxtqcoH1h438hF5TmOvzC/lspjy7zgvCU=
181185
github.com/moby/sys/sequential v0.6.0/go.mod h1:uyv8EUTrca5PnDsdMGXhZe6CCe8U/UiTWd+lL+7b/Ko=
182-
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
183-
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
186+
github.com/moby/term v0.5.2 h1:6qk3FJAFDs6i/q3W/pQ97SX192qKfZgGjCQqfCJkgzQ=
187+
github.com/moby/term v0.5.2/go.mod h1:d3djjFCrjnB+fl8NJux+EJzu0msscUP+f8it8hPkFLc=
184188
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
185189
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
186190
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -207,8 +211,8 @@ github.com/onsi/gomega v1.39.1 h1:1IJLAad4zjPn2PsnhH70V4DKRFlrCzGBNrNaru+Vf28=
207211
github.com/onsi/gomega v1.39.1/go.mod h1:hL6yVALoTOxeWudERyfppUcZXjMwIMLnuSfruD2lcfg=
208212
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
209213
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
210-
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 h1:rc3tiVYb5z54aKaDfakKn0dDjIyPpTtszkjuMzyt7ec=
211-
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
214+
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
215+
github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M=
212216
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
213217
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
214218
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
@@ -367,8 +371,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
367371
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
368372
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
369373
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
370-
gotest.tools/v3 v3.5.0 h1:Ljk6PdHdOhAb5aDMWXjDLMMhph+BpztA4v1QdqEW2eY=
371-
gotest.tools/v3 v3.5.0/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
374+
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
375+
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
372376
k8s.io/api v0.35.3 h1:pA2fiBc6+N9PDf7SAiluKGEBuScsTzd2uYBkA5RzNWQ=
373377
k8s.io/api v0.35.3/go.mod h1:9Y9tkBcFwKNq2sxwZTQh1Njh9qHl81D0As56tu42GA4=
374378
k8s.io/apiextensions-apiserver v0.35.3 h1:2fQUhEO7P17sijylbdwt0nBdXP0TvHrHj0KeqHD8FiU=
@@ -391,6 +395,8 @@ k8s.io/utils v0.0.0-20260210185600-b8788abfbbc2 h1:AZYQSJemyQB5eRxqcPky+/7EdBj0x
391395
k8s.io/utils v0.0.0-20260210185600-b8788abfbbc2/go.mod h1:xDxuJ0whA3d0I4mf/C4ppKHxXynQ+fxnkmQH0vTHnuk=
392396
libvirt.org/go/libvirt v1.12002.0 h1:MpPdFYvM1hpM/UVRrCW6EO1lk4evOvsbh81Pq4ojGs4=
393397
libvirt.org/go/libvirt v1.12002.0/go.mod h1:1WiFE8EjZfq+FCVog+rvr1yatKbKZ9FaFMZgEqxEJqQ=
398+
pgregory.net/rapid v1.2.0 h1:keKAYRcjm+e1F0oAuU5F5+YPAWcyxNNRK2wud503Gnk=
399+
pgregory.net/rapid v1.2.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=
394400
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.33.0 h1:qPrZsv1cwQiFeieFlRqT627fVZ+tyfou/+S5S0H5ua0=
395401
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.33.0/go.mod h1:Ve9uj1L+deCXFrPOk1LpFXqTg7LCFzFso6PA48q/XZw=
396402
sigs.k8s.io/cluster-api v1.12.4 h1:usvoZ+Nblfu//l31hm1B1WUdigb6OnGAJqwt8qWq/iA=

test/vbmctl/README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ This tool is under active development.
1616
| VM management (create/delete/list) | ✅ Implemented |
1717
| `vbmctl create bml` / `vbmctl delete bml` | ✅ Implemented |
1818
| `vbmctl status` | ✅ Implemented (basic) |
19-
| Configurable volumes | ❌ TODO (hard-coded to two per VM) |
19+
| Configurable volumes | ✅ Implemented |
2020
| Network management | ❌ TODO (uses existing libvirt networks) |
2121
| BMC emulator support | ❌ TODO |
22-
| Image server | ❌ TODO |
22+
| Image server | ✅ Implemented (basic) |
2323
| State management (persistent state) | ❌ TODO |
2424

2525
## Features
@@ -29,6 +29,7 @@ This tool is under active development.
2929
- **DHCP Reservation**: Reserve IP addresses for VMs via DHCP on existing
3030
libvirt networks
3131
- **Library Support**: Can be imported as a Go module for programmatic use
32+
- **Image Server Management**: Create, delete, list image server
3233

3334
## Build Tags
3435

@@ -73,6 +74,10 @@ vbmctl create vm \
7374
# Create a bare metal lab (all VMs defined in spec.vms of the config file)
7475
vbmctl create bml
7576

77+
# Create an image server with default settings. Please note that if
78+
# a name is specified, vbmctl will automatically add the prefix `vbmctl-`.
79+
vbmctl create image-server
80+
7681
# Check status
7782
vbmctl status
7883

@@ -82,6 +87,9 @@ vbmctl delete vm test-vm
8287
# Delete the bare metal lab (all VMs defined in spec.vms of the config file)
8388
vbmctl delete bml
8489

90+
# Delete the image server
91+
vbmctl delete image-server
92+
8593
# Show help
8694
vbmctl --help
8795
```
@@ -145,6 +153,9 @@ spec:
145153
- network: "baremetal-e2e"
146154
macAddress: "00:60:2f:31:81:02"
147155
ipAddress: "192.168.222.101"
156+
imageServer:
157+
dataDir: "/tmp"
158+
port: 80
148159
```
149160
150161
The `spec.vms` section defines the VMs that will be created when you run `vbmctl
@@ -163,6 +174,7 @@ import (
163174
164175
"github.com/metal3-io/baremetal-operator/test/vbmctl/pkg/api"
165176
"github.com/metal3-io/baremetal-operator/test/vbmctl/pkg/libvirt"
177+
"github.com/metal3-io/baremetal-operator/test/vbmctl/pkg/containers"
166178
libvirtgo "libvirt.org/go/libvirt"
167179
)
168180
@@ -204,6 +216,19 @@ func main() {
204216
log.Fatal(err)
205217
}
206218
219+
// Create an Image Server
220+
err = containers.CreateImageServerInstance(ctx, &api.ImageServerConfig{
221+
Image: "nginx:latest",
222+
ContainerName: "image-server",
223+
DataDir: "/var/lib/vbmctl/images",
224+
ContainerDataDir: "/usr/share/nginx/html",
225+
Port: 8080,
226+
ContainerPort: 80,
227+
})
228+
if err != nil {
229+
log.Fatal(err)
230+
}
231+
207232
fmt.Printf("Created VM: %s (UUID: %s)\n", vm.Config.Name, vm.UUID)
208233
}
209234
```

0 commit comments

Comments
 (0)