Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ignition generation for initial boot #3

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hack/validate-kustomize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ red="$(tput setaf 1)"
green="$(tput setaf 2)"
normal="$(tput sgr0)"

for kustomization in "$BASEDIR"/../config/*/**/kustomization.yaml; do
for kustomization in "$BASEDIR"/../config/**/kustomization.yaml; do
path="$(dirname "$kustomization")"
dir="$(realpath --relative-to "$BASEDIR"/.. "$path")"
echo "${bold}Validating $dir${normal}"
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/server_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (r *ServerReconciler) applyDefaultIgnitionForServer(
bootConfig *metalv1alpha1.ServerBootConfiguration,
registryURL string,
) error {
probeFlags := fmt.Sprintf("--registry-url=%s,--server-uuid=%s", registryURL, server.Spec.UUID)
probeFlags := fmt.Sprintf("--registry-url=%s --server-uuid=%s", registryURL, server.Spec.UUID)
ignitionData, err := r.generateDefaultIgnitionDataForServer(probeFlags)
if err != nil {
return fmt.Errorf("failed to generate default ignitionSecret data: %w", err)
Expand Down
24 changes: 23 additions & 1 deletion internal/controller/server_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ 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/probe"
. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -77,7 +80,26 @@ var _ = Describe("Server Controller", func() {
HaveField("Status.State", metalv1alpha1.ServerBootConfigurationStatePending),
))

// TODO: test ignition secret content
By("Ensuring that the default ignition configuration has been created")
ignitionSecret := &v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns.Name,
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",
Kind: "ServerBootConfiguration",
Name: bootConfig.Name,
UID: bootConfig.UID,
Controller: ptr.To(true),
BlockOwnerDeletion: ptr.To(true),
})),
HaveField("Data", HaveKeyWithValue("ignition", MatchYAML(ignitionData))),
))

By("Ensuring that the Server resource has been created")
Eventually(Object(server)).Should(SatisfyAll(
Expand Down
54 changes: 54 additions & 0 deletions internal/controller/testdata/ignition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Copyright 2024.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package testdata

var (
DefaultIgnition = map[string]interface{}{
"ignition": map[string]interface{}{
"version": "3.4.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 --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{}{},
},
}
)
46 changes: 22 additions & 24 deletions internal/ignition/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,30 @@ type ContainerConfig struct {

// defaultIgnitionTemplate is a Go template for the default Ignition configuration.
var defaultIgnitionTemplate = `
ignition_version: "3.0.0"
ignition:
version: "3.4.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 --name metalprobe {{.Flags}} {{.Image}}
ExecStop=/usr/bin/docker stop metalprobe

[Install]
WantedBy=multi-user.target
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 --name metalprobe {{.Image}} {{.Flags}}
ExecStop=/usr/bin/docker stop metalprobe
[Install]
WantedBy=multi-user.target
storage:
files: []

files: []
passwd: {}
`

Expand Down
Loading