Skip to content

Commit

Permalink
Fix metalprobe ignition (#28)
Browse files Browse the repository at this point in the history
Install Docker prior to run the `metalprobe` system unit.
  • Loading branch information
afritzler authored Apr 26, 2024
1 parent 1fb9b0f commit ee1f257
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 61 deletions.
8 changes: 2 additions & 6 deletions internal/controller/server_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ package controller
import (
"fmt"

"github.com/afritzler/metal-operator/internal/controller/testdata"
"sigs.k8s.io/yaml"

metalv1alpha1 "github.com/afritzler/metal-operator/api/v1alpha1"
"github.com/afritzler/metal-operator/internal/controller/testdata"
"github.com/afritzler/metal-operator/internal/probe"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -87,8 +85,6 @@ var _ = Describe("Server Controller", func() {
Name: bootConfig.Name,
},
}
ignitionData, err := yaml.Marshal(testdata.DefaultIgnition)
Expect(err).NotTo(HaveOccurred())
Eventually(Object(ignitionSecret)).Should(SatisfyAll(
HaveField("OwnerReferences", ContainElement(metav1.OwnerReference{
APIVersion: "metal.ironcore.dev/v1alpha1",
Expand All @@ -98,7 +94,7 @@ var _ = Describe("Server Controller", func() {
Controller: ptr.To(true),
BlockOwnerDeletion: ptr.To(true),
})),
HaveField("Data", HaveKeyWithValue("ignition", MatchYAML(ignitionData))),
HaveField("Data", HaveKeyWithValue("ignition", MatchYAML(testdata.DefaultIgnition))),
))

By("Ensuring that the Server resource has been created")
Expand Down
72 changes: 39 additions & 33 deletions internal/controller/testdata/ignition.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,43 @@ limitations under the License.
package testdata

var (
DefaultIgnition = map[string]interface{}{
"variant": "fcos",
"version": "1.3.0",
"systemd": map[string]interface{}{
"units": []interface{}{
map[string]interface{}{
"name": "docker.service",
"enabled": true,
},
map[string]interface{}{
"name": "metalprobe.service",
"enabled": true,
"contents": `[Unit]
Description=Run My Docker Container
Requires=docker.service
After=docker.service
[Service]
Restart=always
ExecStartPre=-/usr/bin/docker stop metalprobe
ExecStartPre=-/usr/bin/docker rm metalprobe
ExecStartPre=/usr/bin/docker pull foo:latest
ExecStart=/usr/bin/docker run --network host --privileged --name metalprobe foo:latest --registry-url=http://localhost:12345 --server-uuid=38947555-7742-3448-3784-823347823834
ExecStop=/usr/bin/docker stop metalprobe
[Install]
WantedBy=multi-user.target`,
},
},
},
"passwd": map[string]interface{}{},
"storage": map[string]interface{}{
"files": []interface{}{},
},
}
DefaultIgnition = `variant: fcos
version: "1.3.0"
systemd:
units:
- name: docker-install.service
enabled: true
contents: |-
[Unit]
Description=Install Docker
Before=metalprobe.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/apt-get update
ExecStart=/usr/bin/apt-get install docker.io -y
[Install]
WantedBy=multi-user.target
- name: docker.service
enabled: true
- name: metalprobe.service
enabled: true
contents: |-
[Unit]
Description=Run My Docker Container
Requires=docker.service docker-install.service
After=docker.service docker-install.service
[Service]
Restart=always
ExecStartPre=-/usr/bin/docker stop metalprobe
ExecStartPre=-/usr/bin/docker rm metalprobe
ExecStartPre=/usr/bin/docker pull foo:latest
ExecStart=/usr/bin/docker run --network host --privileged --name metalprobe foo:latest --registry-url=http://localhost:12345 --server-uuid=38947555-7742-3448-3784-823347823834
ExecStop=/usr/bin/docker stop metalprobe
[Install]
WantedBy=multi-user.target
storage:
files: []
passwd: {}
`
)
56 changes: 34 additions & 22 deletions internal/ignition/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,43 @@ type ContainerConfig struct {
}

// defaultIgnitionTemplate is a Go template for the default Ignition configuration.
var defaultIgnitionTemplate = `
variant: fcos
var defaultIgnitionTemplate = `variant: fcos
version: "1.3.0"
systemd:
units:
- name: docker.service
enabled: true
- name: metalprobe.service
enabled: true
contents: |-
[Unit]
Description=Run My Docker Container
Requires=docker.service
After=docker.service
[Service]
Restart=always
ExecStartPre=-/usr/bin/docker stop metalprobe
ExecStartPre=-/usr/bin/docker rm metalprobe
ExecStartPre=/usr/bin/docker pull {{.Image}}
ExecStart=/usr/bin/docker run --network host --privileged --name metalprobe {{.Image}} {{.Flags}}
ExecStop=/usr/bin/docker stop metalprobe
[Install]
WantedBy=multi-user.target
units:
- name: docker-install.service
enabled: true
contents: |-
[Unit]
Description=Install Docker
Before=metalprobe.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/apt-get update
ExecStart=/usr/bin/apt-get install docker.io -y
[Install]
WantedBy=multi-user.target
- name: docker.service
enabled: true
- name: metalprobe.service
enabled: true
contents: |-
[Unit]
Description=Run My Docker Container
Requires=docker.service docker-install.service
After=docker.service docker-install.service
[Service]
Restart=always
ExecStartPre=-/usr/bin/docker stop metalprobe
ExecStartPre=-/usr/bin/docker rm metalprobe
ExecStartPre=/usr/bin/docker pull {{.Image}}
ExecStart=/usr/bin/docker run --network host --privileged --name metalprobe {{.Image}} {{.Flags}}
ExecStop=/usr/bin/docker stop metalprobe
[Install]
WantedBy=multi-user.target
storage:
files: []
files: []
passwd: {}
`

Expand Down

0 comments on commit ee1f257

Please sign in to comment.