Skip to content

Commit

Permalink
Update tests for embedded images:
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Weinstock <[email protected]>
  • Loading branch information
jacobweinstock committed Sep 5, 2024
1 parent caee2ad commit b0a782a
Show file tree
Hide file tree
Showing 30 changed files with 466 additions and 203 deletions.
2 changes: 1 addition & 1 deletion pkg/api/v1alpha1/tinkerbelltemplateconfig_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ warnings:
`

// HookOS embeds container images from the bundle.
// The container images are tagged as follows:
// The container images are tagged as below.
actionImage2Disk = "127.0.0.1/embedded/image2disk"
actionWriteFile = "127.0.0.1/embedded/writefile"
actionReboot = "127.0.0.1/embedded/reboot"
Expand Down
102 changes: 100 additions & 2 deletions pkg/providers/tinkerbell/controlplane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestControlPlaneSpecUpdateMachineTemplates(t *testing.T) {
expectedKCP.Spec.MachineTemplate.InfrastructureRef.Name = "test-control-plane-1"

expectedCPTemplate.Name = "test-control-plane-1"
expectedCPTemplate.Spec.Template.Spec.TemplateOverride = "global_timeout: 6000\nid: \"\"\nname: tink-test\ntasks:\n- actions:\n - environment:\n COMPRESSED: \"true\"\n DEST_DISK: /dev/sda\n IMG_URL: \"\"\n image: image2disk:v1.0.0\n name: stream-image\n timeout: 360\n - environment:\n BLOCK_DEVICE: /dev/sda2\n CHROOT: \"y\"\n CMD_LINE: apt -y update && apt -y install openssl\n DEFAULT_INTERPRETER: /bin/sh -c\n FS_TYPE: ext4\n image: cexec:v1.0.0\n name: install-openssl\n timeout: 90\n - environment:\n CONTENTS: |\n network:\n version: 2\n renderer: networkd\n ethernets:\n eno1:\n dhcp4: true\n eno2:\n dhcp4: true\n eno3:\n dhcp4: true\n eno4:\n dhcp4: true\n DEST_DISK: /dev/sda2\n DEST_PATH: /etc/netplan/config.yaml\n DIRMODE: \"0755\"\n FS_TYPE: ext4\n GID: \"0\"\n MODE: \"0644\"\n UID: \"0\"\n image: writefile:v1.0.0\n name: write-netplan\n timeout: 90\n - environment:\n CONTENTS: |\n datasource:\n Ec2:\n metadata_urls: []\n strict_id: false\n system_info:\n default_user:\n name: tink\n groups: [wheel, adm]\n sudo: [\"ALL=(ALL) NOPASSWD:ALL\"]\n shell: /bin/bash\n manage_etc_hosts: localhost\n warnings:\n dsid_missing_source: off\n DEST_DISK: /dev/sda2\n DEST_PATH: /etc/cloud/cloud.cfg.d/10_tinkerbell.cfg\n DIRMODE: \"0700\"\n FS_TYPE: ext4\n GID: \"0\"\n MODE: \"0600\"\n image: writefile:v1.0.0\n name: add-tink-cloud-init-config\n timeout: 90\n - environment:\n CONTENTS: |\n datasource: Ec2\n DEST_DISK: /dev/sda2\n DEST_PATH: /etc/cloud/ds-identify.cfg\n DIRMODE: \"0700\"\n FS_TYPE: ext4\n GID: \"0\"\n MODE: \"0600\"\n UID: \"0\"\n image: writefile:v1.0.0\n name: add-tink-cloud-init-ds-config\n timeout: 90\n - environment:\n BLOCK_DEVICE: /dev/sda2\n FS_TYPE: ext4\n image: kexec:v1.0.0\n name: kexec-image\n pid: host\n timeout: 90\n name: tink-test\n volumes:\n - /dev:/dev\n - /dev/console:/dev/console\n - /lib/firmware:/lib/firmware:ro\n worker: '{{.device_1}}'\nversion: \"0.1\"\n"
expectedCPTemplate.Spec.Template.Spec.TemplateOverride = testTemplateOverride
expectedCPTemplate.Spec.Template.Spec.HardwareAffinity = &tinkerbellv1.HardwareAffinity{
Required: []tinkerbellv1.HardwareAffinityTerm{
{
Expand Down Expand Up @@ -924,6 +924,104 @@ status:
return kcp
}

var testTemplateOverride = `global_timeout: 6000
id: ""
name: tink-test
tasks:
- actions:
- environment:
COMPRESSED: "true"
DEST_DISK: /dev/sda
IMG_URL: ""
image: image2disk:v1.0.0
name: stream-image
timeout: 360
- environment:
BLOCK_DEVICE: /dev/sda2
CHROOT: "y"
CMD_LINE: apt -y update && apt -y install openssl
DEFAULT_INTERPRETER: /bin/sh -c
FS_TYPE: ext4
image: cexec:v1.0.0
name: install-openssl
timeout: 90
- environment:
CONTENTS: |
network:
version: 2
renderer: networkd
ethernets:
eno1:
dhcp4: true
eno2:
dhcp4: true
eno3:
dhcp4: true
eno4:
dhcp4: true
DEST_DISK: /dev/sda2
DEST_PATH: /etc/netplan/config.yaml
DIRMODE: "0755"
FS_TYPE: ext4
GID: "0"
MODE: "0644"
UID: "0"
image: writefile:v1.0.0
name: write-netplan
timeout: 90
- environment:
CONTENTS: |
datasource:
Ec2:
metadata_urls: []
strict_id: false
system_info:
default_user:
name: tink
groups: [wheel, adm]
sudo: ["ALL=(ALL) NOPASSWD:ALL"]
shell: /bin/bash
manage_etc_hosts: localhost
warnings:
dsid_missing_source: off
DEST_DISK: /dev/sda2
DEST_PATH: /etc/cloud/cloud.cfg.d/10_tinkerbell.cfg
DIRMODE: "0700"
FS_TYPE: ext4
GID: "0"
MODE: "0600"
image: writefile:v1.0.0
name: add-tink-cloud-init-config
timeout: 90
- environment:
CONTENTS: |
datasource: Ec2
DEST_DISK: /dev/sda2
DEST_PATH: /etc/cloud/ds-identify.cfg
DIRMODE: "0700"
FS_TYPE: ext4
GID: "0"
MODE: "0600"
UID: "0"
image: writefile:v1.0.0
name: add-tink-cloud-init-ds-config
timeout: 90
- environment:
BLOCK_DEVICE: /dev/sda2
FS_TYPE: ext4
image: kexec:v1.0.0
name: kexec-image
pid: host
timeout: 90
name: tink-test
volumes:
- /dev:/dev
- /dev/console:/dev/console
- /lib/firmware:/lib/firmware:ro
worker: '{{.device_1}}'
version: "0.1"
`

func tinkerbellMachineTemplate(name string) *tinkerbellv1.TinkerbellMachineTemplate {
return &tinkerbellv1.TinkerbellMachineTemplate{
TypeMeta: metav1.TypeMeta{
Expand All @@ -937,7 +1035,7 @@ func tinkerbellMachineTemplate(name string) *tinkerbellv1.TinkerbellMachineTempl
Spec: tinkerbellv1.TinkerbellMachineTemplateSpec{
Template: tinkerbellv1.TinkerbellMachineTemplateResource{
Spec: tinkerbellv1.TinkerbellMachineSpec{
TemplateOverride: "global_timeout: 6000\nid: \"\"\nname: tink-test\ntasks:\n- actions:\n - environment:\n COMPRESSED: \"true\"\n DEST_DISK: /dev/sda\n IMG_URL: \"\"\n image: image2disk:v1.0.0\n name: stream-image\n timeout: 360\n - environment:\n BLOCK_DEVICE: /dev/sda2\n CHROOT: \"y\"\n CMD_LINE: apt -y update && apt -y install openssl\n DEFAULT_INTERPRETER: /bin/sh -c\n FS_TYPE: ext4\n image: cexec:v1.0.0\n name: install-openssl\n timeout: 90\n - environment:\n CONTENTS: |\n network:\n version: 2\n renderer: networkd\n ethernets:\n eno1:\n dhcp4: true\n eno2:\n dhcp4: true\n eno3:\n dhcp4: true\n eno4:\n dhcp4: true\n DEST_DISK: /dev/sda2\n DEST_PATH: /etc/netplan/config.yaml\n DIRMODE: \"0755\"\n FS_TYPE: ext4\n GID: \"0\"\n MODE: \"0644\"\n UID: \"0\"\n image: writefile:v1.0.0\n name: write-netplan\n timeout: 90\n - environment:\n CONTENTS: |\n datasource:\n Ec2:\n metadata_urls: []\n strict_id: false\n system_info:\n default_user:\n name: tink\n groups: [wheel, adm]\n sudo: [\"ALL=(ALL) NOPASSWD:ALL\"]\n shell: /bin/bash\n manage_etc_hosts: localhost\n warnings:\n dsid_missing_source: off\n DEST_DISK: /dev/sda2\n DEST_PATH: /etc/cloud/cloud.cfg.d/10_tinkerbell.cfg\n DIRMODE: \"0700\"\n FS_TYPE: ext4\n GID: \"0\"\n MODE: \"0600\"\n image: writefile:v1.0.0\n name: add-tink-cloud-init-config\n timeout: 90\n - environment:\n CONTENTS: |\n datasource: Ec2\n DEST_DISK: /dev/sda2\n DEST_PATH: /etc/cloud/ds-identify.cfg\n DIRMODE: \"0700\"\n FS_TYPE: ext4\n GID: \"0\"\n MODE: \"0600\"\n UID: \"0\"\n image: writefile:v1.0.0\n name: add-tink-cloud-init-ds-config\n timeout: 90\n - environment:\n BLOCK_DEVICE: /dev/sda2\n FS_TYPE: ext4\n image: kexec:v1.0.0\n name: kexec-image\n pid: host\n timeout: 90\n name: tink-test\n volumes:\n - /dev:/dev\n - /dev/console:/dev/console\n - /lib/firmware:/lib/firmware:ro\n worker: '{{.device_1}}'\nversion: \"0.1\"\n",
TemplateOverride: testTemplateOverride,
HardwareAffinity: &tinkerbellv1.HardwareAffinity{
Required: []tinkerbellv1.HardwareAffinityTerm{
{
Expand Down
71 changes: 69 additions & 2 deletions pkg/providers/tinkerbell/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,73 @@ func tinkHardware(hardwareName, labelType string) *tinkv1alpha1.Hardware {

type cpOpt func(plane *tinkerbell.ControlPlane)

var testTemplateOverride = `global_timeout: 6000
id: ""
name: workload-cluster
tasks:
- actions:
- environment:
COMPRESSED: "true"
DEST_DISK: '{{ index .Hardware.Disks 0 }}'
IMG_URL: ""
image: 127.0.0.1/embedded/image2disk
name: stream image to disk
timeout: 600
- environment:
BOOTCONFIG_CONTENTS: kernel {}
DEST_DISK: '{{ formatPartition ( index .Hardware.Disks 0 ) 12 }}'
DEST_PATH: /bootconfig.data
DIRMODE: "0700"
FS_TYPE: ext4
GID: "0"
MODE: "0644"
UID: "0"
image: 127.0.0.1/embedded/writefile
name: write Bottlerocket bootconfig
pid: host
timeout: 90
- environment:
DEST_DISK: '{{ formatPartition ( index .Hardware.Disks 0 ) 12 }}'
DEST_PATH: /user-data.toml
DIRMODE: "0700"
FS_TYPE: ext4
GID: "0"
HEGEL_URLS: http://2.2.2.2:50061,http://2.2.2.2:50061
MODE: "0644"
UID: "0"
image: 127.0.0.1/embedded/writefile
name: write Bottlerocket user data
pid: host
timeout: 90
- environment:
DEST_DISK: '{{ formatPartition ( index .Hardware.Disks 0 ) 12 }}'
DEST_PATH: /net.toml
DIRMODE: "0755"
FS_TYPE: ext4
GID: "0"
IFNAME: eno1
MODE: "0644"
STATIC_BOTTLEROCKET: "true"
UID: "0"
image: 127.0.0.1/embedded/writefile
name: write netplan config
pid: host
timeout: 90
- image: 127.0.0.1/embedded/reboot
name: reboot
pid: host
timeout: 90
volumes:
- /worker:/worker
name: workload-cluster
volumes:
- /dev:/dev
- /dev/console:/dev/console
- /lib/firmware:/lib/firmware:ro
worker: '{{.device_1}}'
version: "0.1"
`

func tinkerbellCP(clusterName string, opts ...cpOpt) *tinkerbell.ControlPlane {
cp := &tinkerbell.ControlPlane{
BaseControlPlane: tinkerbell.BaseControlPlane{
Expand Down Expand Up @@ -1433,7 +1500,7 @@ rules:
Spec: tinkerbellv1.TinkerbellMachineTemplateSpec{
Template: tinkerbellv1.TinkerbellMachineTemplateResource{
Spec: tinkerbellv1.TinkerbellMachineSpec{
TemplateOverride: "global_timeout: 6000\nid: \"\"\nname: workload-cluster\ntasks:\n- actions:\n - environment:\n COMPRESSED: \"true\"\n DEST_DISK: '{{ index .Hardware.Disks 0 }}'\n IMG_URL: \"\"\n image: \"\"\n name: stream-image\n timeout: 600\n - environment:\n BOOTCONFIG_CONTENTS: kernel {}\n DEST_DISK: '{{ formatPartition ( index .Hardware.Disks 0 ) 12 }}'\n DEST_PATH: /bootconfig.data\n DIRMODE: \"0700\"\n FS_TYPE: ext4\n GID: \"0\"\n MODE: \"0644\"\n UID: \"0\"\n image: \"\"\n name: write-bootconfig\n pid: host\n timeout: 90\n - environment:\n DEST_DISK: '{{ formatPartition ( index .Hardware.Disks 0 ) 12 }}'\n DEST_PATH: /user-data.toml\n DIRMODE: \"0700\"\n FS_TYPE: ext4\n GID: \"0\"\n HEGEL_URLS: http://2.2.2.2:50061,http://2.2.2.2:50061\n MODE: \"0644\"\n UID: \"0\"\n image: \"\"\n name: write-user-data\n pid: host\n timeout: 90\n - environment:\n DEST_DISK: '{{ formatPartition ( index .Hardware.Disks 0 ) 12 }}'\n DEST_PATH: /net.toml\n DIRMODE: \"0755\"\n FS_TYPE: ext4\n GID: \"0\"\n IFNAME: eno1\n MODE: \"0644\"\n STATIC_BOTTLEROCKET: \"true\"\n UID: \"0\"\n image: \"\"\n name: write-netplan\n pid: host\n timeout: 90\n - image: \"\"\n name: reboot-image\n pid: host\n timeout: 90\n volumes:\n - /worker:/worker\n name: workload-cluster\n volumes:\n - /dev:/dev\n - /dev/console:/dev/console\n - /lib/firmware:/lib/firmware:ro\n worker: '{{.device_1}}'\nversion: \"0.1\"\n",
TemplateOverride: testTemplateOverride,
HardwareAffinity: &tinkerbellv1.HardwareAffinity{
Required: []tinkerbellv1.HardwareAffinityTerm{
{LabelSelector: metav1.LabelSelector{
Expand Down Expand Up @@ -1573,7 +1640,7 @@ func tinkWorker(clusterName string, opts ...workerOpt) *tinkerbell.Workers {
},
Spec: tinkerbellv1.TinkerbellMachineTemplateSpec{
Template: tinkerbellv1.TinkerbellMachineTemplateResource{Spec: tinkerbellv1.TinkerbellMachineSpec{
TemplateOverride: "global_timeout: 6000\nid: \"\"\nname: " + clusterName + "\ntasks:\n- actions:\n - environment:\n COMPRESSED: \"true\"\n DEST_DISK: '{{ index .Hardware.Disks 0 }}'\n IMG_URL: \"\"\n image: \"\"\n name: stream-image\n timeout: 600\n - environment:\n BOOTCONFIG_CONTENTS: kernel {}\n DEST_DISK: '{{ formatPartition ( index .Hardware.Disks 0 ) 12 }}'\n DEST_PATH: /bootconfig.data\n DIRMODE: \"0700\"\n FS_TYPE: ext4\n GID: \"0\"\n MODE: \"0644\"\n UID: \"0\"\n image: \"\"\n name: write-bootconfig\n pid: host\n timeout: 90\n - environment:\n DEST_DISK: '{{ formatPartition ( index .Hardware.Disks 0 ) 12 }}'\n DEST_PATH: /user-data.toml\n DIRMODE: \"0700\"\n FS_TYPE: ext4\n GID: \"0\"\n HEGEL_URLS: http://2.2.2.2:50061,http://2.2.2.2:50061\n MODE: \"0644\"\n UID: \"0\"\n image: \"\"\n name: write-user-data\n pid: host\n timeout: 90\n - environment:\n DEST_DISK: '{{ formatPartition ( index .Hardware.Disks 0 ) 12 }}'\n DEST_PATH: /net.toml\n DIRMODE: \"0755\"\n FS_TYPE: ext4\n GID: \"0\"\n IFNAME: eno1\n MODE: \"0644\"\n STATIC_BOTTLEROCKET: \"true\"\n UID: \"0\"\n image: \"\"\n name: write-netplan\n pid: host\n timeout: 90\n - image: \"\"\n name: reboot-image\n pid: host\n timeout: 90\n volumes:\n - /worker:/worker\n name: workload-cluster\n volumes:\n - /dev:/dev\n - /dev/console:/dev/console\n - /lib/firmware:/lib/firmware:ro\n worker: '{{.device_1}}'\nversion: \"0.1\"\n",
TemplateOverride: testTemplateOverride,
HardwareAffinity: &tinkerbellv1.HardwareAffinity{
Required: []tinkerbellv1.HardwareAffinityTerm{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ spec:
timeout: 90
- environment:
image: reboot:v1.0.0
name: reboot-image
name: reboot
pid: host
timeout: 90
volumes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ spec:
timeout: 90
- environment:
image: reboot:v1.0.0
name: reboot-image
name: reboot
pid: host
timeout: 90
volumes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ spec:
timeout: 90
- environment:
image: reboot:v1.0.0
name: reboot-image
name: reboot
pid: host
timeout: 90
volumes:
Expand Down
24 changes: 12 additions & 12 deletions pkg/providers/tinkerbell/testdata/expected_kct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ spec:
COMPRESSED: "true"
DEST_DISK: '{{ index .Hardware.Disks 0 }}'
IMG_URL: https://ubuntu-1-21.gz
image: ""
name: stream-image
image: 127.0.0.1/embedded/image2disk
name: stream image to disk
timeout: 600
- environment:
DEST_DISK: '{{ formatPartition ( index .Hardware.Disks 0 ) 2 }}'
Expand All @@ -63,8 +63,8 @@ spec:
MODE: "0644"
STATIC_NETPLAN: "true"
UID: "0"
image: ""
name: write-netplan
image: 127.0.0.1/embedded/writefile
name: write netplan config
pid: host
timeout: 90
- environment:
Expand All @@ -76,8 +76,8 @@ spec:
GID: "0"
MODE: "0600"
UID: "0"
image: ""
name: disable-cloud-init-network-capabilities
image: 127.0.0.1/embedded/writefile
name: disable cloud-init network capabilities
timeout: 90
- environment:
CONTENTS: |
Expand All @@ -95,8 +95,8 @@ spec:
GID: "0"
MODE: "0600"
UID: "0"
image: ""
name: add-tink-cloud-init-config
image: 127.0.0.1/embedded/writefile
name: add cloud-init config
timeout: 90
- environment:
CONTENTS: |
Expand All @@ -108,11 +108,11 @@ spec:
GID: "0"
MODE: "0600"
UID: "0"
image: ""
name: add-tink-cloud-init-ds-config
image: 127.0.0.1/embedded/writefile
name: add cloud-init ds config
timeout: 90
- image: ""
name: reboot-image
- image: 127.0.0.1/embedded/reboot
name: reboot
pid: host
timeout: 90
volumes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ spec:
COMPRESSED: "true"
DEST_DISK: '{{ index .Hardware.Disks 0 }}'
IMG_URL: https://bottlerocket-1-21.gz
image: ""
name: stream-image
image: 127.0.0.1/embedded/image2disk
name: stream image to disk
timeout: 600
- environment:
BOOTCONFIG_CONTENTS: kernel {}
Expand All @@ -425,8 +425,8 @@ spec:
GID: "0"
MODE: "0644"
UID: "0"
image: ""
name: write-bootconfig
image: 127.0.0.1/embedded/writefile
name: write Bottlerocket bootconfig
pid: host
timeout: 90
- environment:
Expand All @@ -438,8 +438,8 @@ spec:
HEGEL_URLS: http://5.6.7.8:50061,http://5.6.7.8:50061
MODE: "0644"
UID: "0"
image: ""
name: write-user-data
image: 127.0.0.1/embedded/writefile
name: write Bottlerocket user data
pid: host
timeout: 90
- environment:
Expand All @@ -452,12 +452,12 @@ spec:
MODE: "0644"
STATIC_BOTTLEROCKET: "true"
UID: "0"
image: ""
name: write-netplan
image: 127.0.0.1/embedded/writefile
name: write netplan config
pid: host
timeout: 90
- image: ""
name: reboot-image
- image: 127.0.0.1/embedded/reboot
name: reboot
pid: host
timeout: 90
volumes:
Expand Down
Loading

0 comments on commit b0a782a

Please sign in to comment.