diff --git a/internal/controller/server_controller_test.go b/internal/controller/server_controller_test.go index cf75a25..4fa13da 100644 --- a/internal/controller/server_controller_test.go +++ b/internal/controller/server_controller_test.go @@ -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" @@ -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", @@ -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") diff --git a/internal/controller/testdata/ignition.go b/internal/controller/testdata/ignition.go index a195a0e..fb15b33 100644 --- a/internal/controller/testdata/ignition.go +++ b/internal/controller/testdata/ignition.go @@ -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: {} +` ) diff --git a/internal/ignition/default.go b/internal/ignition/default.go index ec0fa65..682974f 100644 --- a/internal/ignition/default.go +++ b/internal/ignition/default.go @@ -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: {} `