diff --git a/OWNERS_ALIASES b/OWNERS_ALIASES index 97bf19921a..e1b60ae495 100644 --- a/OWNERS_ALIASES +++ b/OWNERS_ALIASES @@ -74,3 +74,7 @@ aliases: - tuxtof cluster-api-nutanix-reviewers: - tuxtof + cluster-api-maas-maintainers: + - vasartori + cluster-api-maas-reviewers: + - vasartori diff --git a/docs/book/src/SUMMARY.md b/docs/book/src/SUMMARY.md index c26e0386af..bc073ec0a2 100644 --- a/docs/book/src/SUMMARY.md +++ b/docs/book/src/SUMMARY.md @@ -19,6 +19,7 @@ - [vSphere](./capi/providers/vsphere.md) - [Proxmox](./capi/providers/proxmox.md) - [Windows](./capi/windows/windows.md) + - [MaaS](./capi/providers/maas.md) - [Including ECR Credential Provider](./capi/ecr-credential-provider.md) - [Testing the Images](./capi/goss/goss.md) - [Using Container Images](./capi/container-image.md) diff --git a/docs/book/src/capi/capi.md b/docs/book/src/capi/capi.md index d1d7104176..d6dc0c0e6d 100644 --- a/docs/book/src/capi/capi.md +++ b/docs/book/src/capi/capi.md @@ -30,6 +30,7 @@ If any needed binaries are not present, they can be installed to `images/capi/.b * [VirtualBox](./providers/virtualbox.md) * [vSphere](./providers/vsphere.md) * [Proxmox](./providers/proxmox.md) +* [MaaS](./providers/maas.md) ## Make targets diff --git a/docs/book/src/capi/providers/maas.md b/docs/book/src/capi/providers/maas.md new file mode 100644 index 0000000000..178dbf5751 --- /dev/null +++ b/docs/book/src/capi/providers/maas.md @@ -0,0 +1,76 @@ +# Building Images for MaaS + +The image is built using the KVM hypervisor (QEMU). + +## Building Images + +The build [prerequisites](../capi.md#prerequisites) for using `image-builder` to create QEMU images are installed with: + +```bash +cd image-builder +make deps-qemu +``` + +## Building a MaaS Image + +From the `image-builder` directory, run: + +```bash +make build-maas-ubuntu-xxxx-efi +``` + +The image will be located in `images/capi/output/BUILD_NAME+kube-KUBERNETES_VERSION`. Replace `xxxx` with `2204` or `2404`, depending on the Ubuntu version. + +To build a Ubuntu 22.04-based CAPI image: + +```bash +git clone https://github.com/kubernetes-sigs/image-builder.git +cd image-builder +make build-qemu-ubuntu-2204-efi +``` + +## Uploading to MaaS + +### Prerequisites + +- Ubuntu 22.04 (required for the MaaS client) +- Command-line MaaS client installed + +### Installing the MaaS Client + +```bash +apt update && apt install -y tzdata software-properties-common +apt-add-repository -y ppa:maas/3.5 +apt install -y maas-cli python3-openssl +``` + +### Logging into MaaS + +```bash +maas login admin /MAAS/ '' +``` + +#### Creating a Token + +Log into the MaaS interface, go to your preferences (your username), click "API Keys," and copy an existing key or generate a new one. + +### Uploading the Image + +Navigate to `images/capi/output/`, find the generated image, and enter its directory. Inside, you will see two files: + +```bash +cd images/capi/output/ubuntu-2204-efi-kube-v1.30.5/ + +ls -l +total 7165084 +-rw-r--r-- 1 vasartori vasartori 5132255232 Feb 25 08:33 ubuntu-2204-efi-kube-v1.30.5 +-rw-r--r-- 1 root root 2203701699 Feb 25 08:33 ubuntu-2204-efi-kube-v1.30.5.tar.gz +``` + +Use the **.tar.gz** file for the upload: + +```bash +maas admin boot-resources create name=custom/your-image architecture=amd64/generic title=your-image subarches=generic base_image=ubuntu/jammy content@=./ubuntu-2204-efi-kube-v1.30.5.tar.gz +``` + +**Note:** Set `base_image=ubuntu/jammy` for Ubuntu 22.04 or `ubuntu/noble` for 24.04. diff --git a/docs/book/src/glossary.md b/docs/book/src/glossary.md index 3277afbaf5..d9f7b14320 100644 --- a/docs/book/src/glossary.md +++ b/docs/book/src/glossary.md @@ -1,6 +1,6 @@ # Table of Contents -[A](#a) | [C](#c) | [E](#e) | [G](#g) | [K](#k) | [O](#o) | [V](#v) +[A](#a) | [C](#c) | [E](#e) | [G](#g) | [K](#k) | [M](#m) | [O](#o) | [V](#v) # A --- @@ -76,6 +76,16 @@ Kubernetes (K8s) is an open-source system for automating deployment, scaling, an [source](https://github.com/kubernetes/kubernetes) [docs](https://kubernetes.io) +# M +--- + +## MaaS + +Metal As A Service (a.k.a MaaS) is an open-source tool developed by Canonical that automates the provisioning and management of bare-metal servers. + +[docs](https://maas.io/docs) + + # O --- diff --git a/images/capi/Makefile b/images/capi/Makefile index a676f6bffd..929dfc9a3d 100644 --- a/images/capi/Makefile +++ b/images/capi/Makefile @@ -400,6 +400,8 @@ PROXMOX_BUILD_NAMES ?= proxmox-ubuntu-2204 proxmox-ubuntu-2404 proxmox-ubuntu- VULTR_BUILD_NAMES ?= vultr-ubuntu-2204 +MAAS_BUILD_NAMES ?= maas-ubuntu-2204-efi maas-ubuntu-2404-efi + ## -------------------------------------- ## Dynamic build targets ## -------------------------------------- @@ -448,6 +450,8 @@ PROXMOX_BUILD_TARGETS := $(addprefix build-,$(PROXMOX_BUILD_NAMES)) PROXMOX_VALIDATE_TARGETS := $(addprefix validate-,$(PROXMOX_BUILD_NAMES)) VULTR_BUILD_TARGETS := $(addprefix build-,$(VULTR_BUILD_NAMES)) VULTR_VALIDATE_TARGETS := $(addprefix validate-,$(VULTR_BUILD_NAMES)) +MAAS_BUILD_TARGETS := $(addprefix build-,$(MAAS_BUILD_NAMES)) +MAAS_VALIDATE_TARGETS := $(addprefix validate-,$(MAAS_BUILD_NAMES)) .PHONY: $(NODE_OVA_LOCAL_BUILD_TARGETS) $(NODE_OVA_LOCAL_BUILD_TARGETS): deps-ova set-ssh-password @@ -640,6 +644,15 @@ $(VULTR_BUILD_TARGETS): deps-vultr $(VULTR_VALIDATE_TARGETS): deps-vultr $(PACKER) validate $(PACKER_NODE_FLAGS) -var-file="$(abspath packer/vultr/$(subst validate-vultr-,,$@).json)" $(ABSOLUTE_PACKER_VAR_FILES) packer/vultr/packer.json +.PHONY: $(MAAS_BUILD_TARGETS) +$(MAAS_BUILD_TARGETS): deps-qemu set-ssh-password + $(PACKER) build $(PACKER_NODE_FLAGS) -var-file="$(abspath packer/maas/$(subst build-,,$@).json)" --var="ansible_user_vars=provider=maas" $(ABSOLUTE_PACKER_VAR_FILES) packer/maas/packer.json + +.PHONY: $(MAAS_VALIDATE_TARGETS) +$(MAAS_VALIDATE_TARGETS): deps-qemu set-ssh-password + $(PACKER) validate $(PACKER_NODE_FLAGS) -var-file="$(abspath packer/maas/$(subst validate-,,$@).json)" --var="ansible_user_vars=provider=maas" $(ABSOLUTE_PACKER_VAR_FILES) packer/maas/packer.json + + ## -------------------------------------- ## Dynamic clean targets ## -------------------------------------- @@ -847,6 +860,9 @@ build-qemu-rockylinux-9: ## Builds Rocky 9 QEMU image build-qemu-rockylinux-9-cloudimg: ## Builds Rocky 9 QEMU image using cloud image build-qemu-all: $(QEMU_BUILD_TARGETS) ## Builds all Qemu images +build-maas-ubuntu-2204-efi: ## Builds Ubuntu 22.04 MaaS image that EFI boots +build-maas-ubuntu-2404-efi: ## Builds Ubuntu 24.04 MaaS image that EFI boots + build-raw-flatcar: ## Builds Flatcar RAW image build-raw-ubuntu-2004: ## Builds Ubuntu 20.04 RAW image build-raw-ubuntu-2004-efi: ## Builds Ubuntu 20.04 RAW image that EFI boots diff --git a/images/capi/ansible/roles/providers/files/maas/curtin/NOTICE.md b/images/capi/ansible/roles/providers/files/maas/curtin/NOTICE.md new file mode 100644 index 0000000000..21e4b4f83f --- /dev/null +++ b/images/capi/ansible/roles/providers/files/maas/curtin/NOTICE.md @@ -0,0 +1,3 @@ +# Attribution +All the script in this folder is derived from the original work by Alexsander de Souza (Canonical), +available at https://github.com/canonical/packer-maas. \ No newline at end of file diff --git a/images/capi/ansible/roles/providers/files/maas/curtin/curtin-hooks b/images/capi/ansible/roles/providers/files/maas/curtin/curtin-hooks new file mode 100644 index 0000000000..a17b8d6277 --- /dev/null +++ b/images/capi/ansible/roles/providers/files/maas/curtin/curtin-hooks @@ -0,0 +1,105 @@ +#!/usr/bin/env python3 +# +# This script was copied as-is from: +# Source: https://github.com/canonical/packer-maas +# Original Author: Alexsander de Souza +# + + +import os +import platform +import shutil +import sys + +from curtin import distro, util +from curtin.commands import apt_config, curthooks +from curtin.config import load_command_config +from curtin.log import DEBUG, LOG, basicConfig +from curtin.paths import target_path +from curtin.util import ChrootableTarget, load_command_environment + + +def run_hook_in_target(target, hook): + """Look for "hook" in "target" and run in a chroot""" + target_hook = target_path(target, "/curtin/" + hook) + if os.path.isfile(target_hook): + LOG.debug("running %s" % target_hook) + with ChrootableTarget(target=target) as in_chroot: + in_chroot.subp(["/curtin/" + hook]) + return True + return False + + +def curthook(cfg, target, state): + """Configure network and bootloader""" + LOG.info("Running curtin builtin curthooks") + state_etcd = os.path.split(state["fstab"])[0] + machine = platform.machine() + + distro_info = distro.get_distroinfo(target=target) + if not distro_info: + raise RuntimeError("Failed to determine target distro") + osfamily = distro_info.family + LOG.info( + "Configuring target system for distro: %s osfamily: %s", + distro_info.variant, + osfamily, + ) + + sources = cfg.get("sources", {}) + dd_image = len(util.get_dd_images(sources)) > 0 + + curthooks.disable_overlayroot(cfg, target) + curthooks.disable_update_initramfs(cfg, target, machine) + curthooks.install_missing_packages(cfg, target, osfamily=osfamily) + + if not dd_image: + curthooks.configure_iscsi(cfg, state_etcd, target, osfamily=osfamily) + curthooks.configure_mdadm(cfg, state_etcd, target, osfamily=osfamily) + curthooks.copy_fstab(state.get("fstab"), target) + curthooks.add_swap(cfg, target, state.get("fstab")) + + run_hook_in_target(target, "install-custom-packages") + + if not dd_image: + curthooks.setup_kernel_img_conf(target) + + crypttab_location = os.path.join(os.path.split(state["fstab"])[0], "crypttab") + if os.path.exists(crypttab_location): + curthooks.copy_crypttab(crypttab_location, target) + + udev_rules_d = os.path.join(state["scratch"], "rules.d") + if os.path.isdir(udev_rules_d): + curthooks.copy_dname_rules(udev_rules_d, target) + + apt_config.apply_debconf_selections(cfg, target) + + curthooks.apply_networking(target, state) + curthooks.handle_pollinate_user_agent(cfg, target) + + # re-enable update_initramfs + curthooks.enable_update_initramfs(cfg, target, machine) + curthooks.update_initramfs(target, all_kernels=True) + + run_hook_in_target(target, "setup-bootloader") + + +def cleanup(): + """Remove curtin-hooks so its as if we were never here.""" + curtin_dir = os.path.dirname(__file__) + shutil.rmtree(curtin_dir) + + +def main(): + state = load_command_environment() + config = load_command_config(None, state) + target = state["target"] + + basicConfig(stream=sys.stderr, verbosity=DEBUG) + + curthook(config, target, state) + cleanup() + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/images/capi/ansible/roles/providers/files/maas/curtin/install-custom-packages b/images/capi/ansible/roles/providers/files/maas/curtin/install-custom-packages new file mode 100644 index 0000000000..b8262897ce --- /dev/null +++ b/images/capi/ansible/roles/providers/files/maas/curtin/install-custom-packages @@ -0,0 +1,3 @@ +#!/bin/bash -ex +# +exit 0 \ No newline at end of file diff --git a/images/capi/ansible/roles/providers/files/maas/curtin/setup-bootloader b/images/capi/ansible/roles/providers/files/maas/curtin/setup-bootloader new file mode 100644 index 0000000000..a29cbf0658 --- /dev/null +++ b/images/capi/ansible/roles/providers/files/maas/curtin/setup-bootloader @@ -0,0 +1,30 @@ +#!/bin/bash -ex +# +# This script was copied as-is from: +# Source: https://github.com/canonical/packer-maas +# Original Author: Alexsander de Souza + +export DEBIAN_FRONTEND=noninteractive + +# Clean up remnants from packer-maas vm install +rm /var/cache/debconf/config.dat +dpkg --configure -a + +# Update the package lists before attempting to install the kernel +apt-get update +# Ensure the existence of linux-image-generic for non-cloudimg images. +#apt-get -y install linux-image-generic + +dpkg-reconfigure grub-efi-amd64 +update-grub + +grub-install \ + --target=x86_64-efi \ + --efi-directory=/boot/efi \ + --bootloader-id=ubuntu \ + --recheck + +update-initramfs -uk all + +efibootmgr -v + diff --git a/images/capi/ansible/roles/providers/tasks/maas-ubuntu.yml b/images/capi/ansible/roles/providers/tasks/maas-ubuntu.yml new file mode 100644 index 0000000000..7f67a0fa3c --- /dev/null +++ b/images/capi/ansible/roles/providers/tasks/maas-ubuntu.yml @@ -0,0 +1,15 @@ +- name: Create /curtin directory + ansible.builtin.file: + path: /curtin + state: directory + mode: "0775" + +- name: Copy curtin scripts to /curtin + ansible.builtin.copy: + src: "files/maas/curtin/{{ item }}" + dest: "/curtin/{{ item }}" + mode: "0750" + loop: + - curtin-hooks + - install-custom-packages + - setup-bootloader diff --git a/images/capi/ansible/roles/providers/tasks/maas.yml b/images/capi/ansible/roles/providers/tasks/maas.yml new file mode 100644 index 0000000000..6b74724792 --- /dev/null +++ b/images/capi/ansible/roles/providers/tasks/maas.yml @@ -0,0 +1,6 @@ +- name: Include QEMU tasks + ansible.builtin.include_tasks: qemu.yml + +- name: Include MaaS Specific configs for Ubuntu Distro + ansible.builtin.include_tasks: maas-ubuntu.yml + when: ansible_os_family == "Debian" diff --git a/images/capi/ansible/roles/providers/tasks/main.yml b/images/capi/ansible/roles/providers/tasks/main.yml index 6872f6d41c..1e566e0eb6 100644 --- a/images/capi/ansible/roles/providers/tasks/main.yml +++ b/images/capi/ansible/roles/providers/tasks/main.yml @@ -54,6 +54,9 @@ - ansible.builtin.include_tasks: huaweicloud.yml when: packer_builder_type.startswith('huaweicloud') +- ansible.builtin.include_tasks: maas.yml + when: packer_builder_type is search('qemu') and provider is defined and provider is search('maas') + # Create a boot order configuration # b/w containerd and cloud final, cloud config services diff --git a/images/capi/packer/maas/.gitignore b/images/capi/packer/maas/.gitignore new file mode 100644 index 0000000000..ed3058d85d --- /dev/null +++ b/images/capi/packer/maas/.gitignore @@ -0,0 +1,5 @@ +packer.json +ks.cfg +preseed.cfg +preseed-efi.cfg +user-data diff --git a/images/capi/packer/maas/OWNERS b/images/capi/packer/maas/OWNERS new file mode 100644 index 0000000000..ceebd5d3a4 --- /dev/null +++ b/images/capi/packer/maas/OWNERS @@ -0,0 +1,7 @@ +# See the OWNERS docs at https://go.k8s.io/owners + +approvers: + - cluster-api-maas-maintainers + +reviewers: + - cluster-api-maas-reviewers diff --git a/images/capi/packer/maas/README.md b/images/capi/packer/maas/README.md new file mode 100644 index 0000000000..24252e380b --- /dev/null +++ b/images/capi/packer/maas/README.md @@ -0,0 +1,18 @@ +To build an image using a specific version of Kubernetes use the "PACKER_FLAGS" env var like in the example below: + +PACKER_FLAGS="--var 'kubernetes_rpm_version=1.30.5' --var 'kubernetes_semver=v1.30.5' --var 'kubernetes_series=v1.30' --var 'kubernetes_deb_version=1.30.5-1.1'" make build-maas-ubuntu-2204-efi + +P.S: In order to change disk size(defaults to 20GB as of 31.10.22) you can update PACKER_FLAGS with: +--var 'disk_size=' + + +Upload images to MaaS + +``` +maas boot-resources create name=custom/ architecture=amd64/generic title= subarches=generic base_image=ubuntu/ content@=./.tar.gz +``` + +Notes / Things you need to known: + +- If you are using ubuntu **22.04**, set the `base_image` field to: `ubuntu/jammy`. For 24.04, use: `ubuntu/noble` +- Use **UEFI** to boot the machines, if you use BIOS, your MaaS deployment will **probably** fail. \ No newline at end of file diff --git a/images/capi/packer/maas/cloud-init/meta-data b/images/capi/packer/maas/cloud-init/meta-data new file mode 100644 index 0000000000..e69de29bb2 diff --git a/images/capi/packer/maas/cloud-init/user-data.tmpl b/images/capi/packer/maas/cloud-init/user-data.tmpl new file mode 100644 index 0000000000..ac64a549b8 --- /dev/null +++ b/images/capi/packer/maas/cloud-init/user-data.tmpl @@ -0,0 +1,9 @@ +#cloud-config +ssh_pwauth: true +users: + - name: builder + passwd: $ENCRYPTED_SSH_PASSWORD + groups: [adm, cdrom, dip, plugdev, lxd, sudo] + lock-passwd: false + sudo: ALL=(ALL) NOPASSWD:ALL + shell: /bin/bash diff --git a/images/capi/packer/maas/config.pkr.hcl b/images/capi/packer/maas/config.pkr.hcl new file mode 100644 index 0000000000..5fd19dfba2 --- /dev/null +++ b/images/capi/packer/maas/config.pkr.hcl @@ -0,0 +1,8 @@ +packer { + required_plugins { + qemu = { + source = "github.com/hashicorp/qemu" + version = "~> 1.1.0" + } + } +} diff --git a/images/capi/packer/maas/linux/ubuntu/http/22.04.efi.qemu/meta-data b/images/capi/packer/maas/linux/ubuntu/http/22.04.efi.qemu/meta-data new file mode 100644 index 0000000000..e69de29bb2 diff --git a/images/capi/packer/maas/linux/ubuntu/http/22.04.efi.qemu/user-data.tmpl b/images/capi/packer/maas/linux/ubuntu/http/22.04.efi.qemu/user-data.tmpl new file mode 100644 index 0000000000..9969ff5116 --- /dev/null +++ b/images/capi/packer/maas/linux/ubuntu/http/22.04.efi.qemu/user-data.tmpl @@ -0,0 +1,108 @@ +#cloud-config +# Copyright 2022 The Kubernetes Authors. +# +# 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. + +# For more information on how autoinstall is configured, please refer to +# https://ubuntu.com/server/docs/install/autoinstall-reference +autoinstall: + version: 1 + # Disable ssh server during installation, otherwise packer tries to connect and exceeds the max attempts allowed + early-commands: + - systemctl stop ssh + # Configure the locale + locale: en_US.UTF-8 + keyboard: + layout: us + # Create a single-partition with no swap space. Kubernetes + # really dislikes the idea of anyone else managing memory. + # For more information on how partitioning is configured, + # please refer to https://curtin.readthedocs.io/en/latest/topics/storage.html. + storage: + config: + - ptable: gpt + path: /dev/sda + wipe: superblock-recursive + preserve: false + grub_device: false + type: disk + id: disk-sda + - device: disk-sda + size: 564133888 + wipe: superblock + flag: boot + number: 1 + preserve: false + grub_device: true + type: partition + id: partition-0 + - fstype: fat32 + volume: partition-0 + preserve: false + type: format + id: format-0 + - device: disk-sda + size: -1 + wipe: superblock + number: 2 + preserve: false + grub_device: false + type: partition + id: partition-1 + - fstype: ext4 + volume: partition-1 + preserve: false + type: format + id: format-1 + - path: / + device: format-1 + type: mount + id: mount-1 + - path: /boot/efi + device: format-0 + type: mount + id: mount-O + ssh: + install-server: true + allow-pw: true + # Customize the list of packages installed. + packages: + - open-vm-tools + # Create the default user. + # Ensures the "builder" user doesn't require a password to use sudo. + user-data: + users: + - name: builder + # openssl passwd -6 -salt -stdin <<< + passwd: $ENCRYPTED_SSH_PASSWORD + groups: [adm, cdrom, dip, plugdev, lxd, sudo] + lock-passwd: false + sudo: ALL=(ALL) NOPASSWD:ALL + shell: /bin/bash + + # This command runs after all other steps; it: + # 1. Installs efibootmgr tool + # 2. Sets disk device as first boot device instead of cd-rom + # 3. Disables swapfiles + # 4. Removes the existing swapfile + # 5. Removes the swapfile entry from /etc/fstab + # 6. Cleans up any packages that are no longer required + # 7. Removes the cached list of packages + late-commands: + - apt install -y efibootmgr + - efibootmgr -o $(efibootmgr | grep -oP 'Boot[0-9]+[*]\s+ubuntu' | grep -oP '000[0-9]+' | head -n 1) + - swapoff -a + - rm -f /swapfile + - sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab + - apt-get purge --auto-remove -y + - rm -rf /var/lib/apt/lists/* diff --git a/images/capi/packer/maas/linux/ubuntu/http/22.04.efi/meta-data b/images/capi/packer/maas/linux/ubuntu/http/22.04.efi/meta-data new file mode 100644 index 0000000000..e69de29bb2 diff --git a/images/capi/packer/maas/linux/ubuntu/http/22.04.efi/user-data.tmpl b/images/capi/packer/maas/linux/ubuntu/http/22.04.efi/user-data.tmpl new file mode 100644 index 0000000000..39472f51ff --- /dev/null +++ b/images/capi/packer/maas/linux/ubuntu/http/22.04.efi/user-data.tmpl @@ -0,0 +1,106 @@ +#cloud-config +# Copyright 2022 The Kubernetes Authors. +# +# 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. + +# For more information on how autoinstall is configured, please refer to +# https://ubuntu.com/server/docs/install/autoinstall-reference +autoinstall: + version: 1 + # Disable ssh server during installation, otherwise packer tries to connect and exceed max attempts + early-commands: + - systemctl stop ssh + # Configure the locale + locale: en_US.UTF-8 + keyboard: + layout: us + # For more information on how partitioning is configured, + # please refer to https://curtin.readthedocs.io/en/latest/topics/storage.html. + storage: + grub: + reorder_uefi: false + replace_linux_default: false + config: + - ptable: gpt + path: /dev/sda + wipe: superblock-recursive + preserve: false + name: '' + grub_device: false + type: disk + id: disk-sda + - device: disk-sda + # Create EFI partition of 512MB same as in Ubuntu 20.04 + size: 536870912 + wipe: superblock + flag: boot + number: 1 + preserve: false + grub_device: true + type: partition + id: partition-0 + - fstype: fat32 + volume: partition-0 + preserve: false + type: format + id: format-0 + - device: disk-sda + size: -1 + wipe: superblock + flag: '' + number: 2 + preserve: false + grub_device: false + type: partition + id: partition-1 + - fstype: ext4 + volume: partition-1 + preserve: false + type: format + id: format-1 + - path: / + device: format-1 + type: mount + id: mount-1 + - path: /boot/efi + device: format-0 + type: mount + id: mount-0 + updates: "all" + ssh: + install-server: true + allow-pw: true + # Create the default user. + # Ensures the "builder" user doesn't require a password to use sudo. + user-data: + users: + - name: builder + # openssl passwd -6 -salt -stdin <<< + passwd: $ENCRYPTED_SSH_PASSWORD + groups: [adm, cdrom, dip, plugdev, lxd, sudo] + lock-passwd: false + sudo: ALL=(ALL) NOPASSWD:ALL + shell: /bin/bash + + # This command runs after all other steps; it: + # 1. Disables swapfiles + # 2. Removes the existing swapfile + # 3. Removes the swapfile entry from /etc/fstab + # 4. Cleans up any packages that are no longer required + # 5. Removes the cached list of packages + late-commands: + - swapoff -a + - rm -f /swapfile + - sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab + - apt-get purge --auto-remove -y + - rm -rf /var/lib/apt/lists/* diff --git a/images/capi/packer/maas/linux/ubuntu/http/22.04/meta-data b/images/capi/packer/maas/linux/ubuntu/http/22.04/meta-data new file mode 100644 index 0000000000..e69de29bb2 diff --git a/images/capi/packer/maas/linux/ubuntu/http/22.04/user-data.tmpl b/images/capi/packer/maas/linux/ubuntu/http/22.04/user-data.tmpl new file mode 100644 index 0000000000..8e49bd6d01 --- /dev/null +++ b/images/capi/packer/maas/linux/ubuntu/http/22.04/user-data.tmpl @@ -0,0 +1,86 @@ +#cloud-config +# Copyright 2022 The Kubernetes Authors. +# +# 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. + + +# For more information on how autoinstall is configured, please refer to +# https://ubuntu.com/server/docs/install/autoinstall-reference +autoinstall: + version: 1 + # Disable ssh server during installation, otherwise packer tries to connect and exceed max attempts + early-commands: + - systemctl stop ssh + # Configure the locale + locale: en_US.UTF-8 + keyboard: + layout: us + # Create a single-partition with no swap space. Kubernetes + # really dislikes the idea of anyone else managing memory. + # For more information on how partitioning is configured, + # please refer to https://curtin.readthedocs.io/en/latest/topics/storage.html. + storage: + grub: + replace_linux_default: false + config: + - type: disk + id: disk-0 + size: largest + grub_device: true + preserve: false + ptable: msdos + wipe: superblock + - type: partition + id: partition-0 + device: disk-0 + size: -1 + number: 1 + preserve: false + flag: boot + - type: format + id: format-0 + volume: partition-0 + fstype: ext4 + preserve: false + - type: mount + id: mount-0 + device: format-0 + path: / + updates: 'all' + ssh: + install-server: true + allow-pw: true + # Create the default user. + # Ensures the "builder" user doesn't require a password to use sudo. + user-data: + users: + - name: builder + # openssl passwd -6 -salt -stdin <<< + passwd: $ENCRYPTED_SSH_PASSWORD + groups: [adm, cdrom, dip, plugdev, lxd, sudo] + lock-passwd: false + sudo: ALL=(ALL) NOPASSWD:ALL + shell: /bin/bash + + # This command runs after all other steps; it: + # 1. Disables swapfiles + # 2. Removes the existing swapfile + # 3. Removes the swapfile entry from /etc/fstab + # 4. Cleans up any packages that are no longer required + # 5. Removes the cached list of packages + late-commands: + - swapoff -a + - rm -f /swapfile + - sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab + - apt-get purge --auto-remove -y + - rm -rf /var/lib/apt/lists/* diff --git a/images/capi/packer/maas/linux/ubuntu/http/23.04/meta-data b/images/capi/packer/maas/linux/ubuntu/http/23.04/meta-data new file mode 100644 index 0000000000..e69de29bb2 diff --git a/images/capi/packer/maas/linux/ubuntu/http/23.04/user-data.tmpl b/images/capi/packer/maas/linux/ubuntu/http/23.04/user-data.tmpl new file mode 100644 index 0000000000..30edc45b19 --- /dev/null +++ b/images/capi/packer/maas/linux/ubuntu/http/23.04/user-data.tmpl @@ -0,0 +1,93 @@ +#cloud-config +# Copyright 2022 The Kubernetes Authors. +# +# 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. + + +# For more information on how autoinstall is configured, please refer to +# https://ubuntu.com/server/docs/install/autoinstall-reference +autoinstall: + version: 1 + # Disable ssh server during installation, otherwise packer tries to connect and exceed max attempts + early-commands: + - systemctl stop ssh + # Configure the locale + locale: en_US.UTF-8 + keyboard: + layout: us + apt: + mirror-selection: + primary: + - uri: http://archive.ubuntu.com/ubuntu + # Create a single-partition with no swap space. Kubernetes + # really dislikes the idea of anyone else managing memory. + # For more information on how partitioning is configured, + # please refer to https://curtin.readthedocs.io/en/latest/topics/storage.html. + storage: + grub: + replace_linux_default: false + config: + - type: disk + id: disk-0 + size: largest + grub_device: true + preserve: false + ptable: msdos + wipe: superblock + - type: partition + id: partition-0 + device: disk-0 + size: -1 + number: 1 + preserve: false + flag: boot + - type: format + id: format-0 + volume: partition-0 + fstype: ext4 + preserve: false + - type: mount + id: mount-0 + device: format-0 + path: / + updates: 'all' + ssh: + install-server: true + allow-pw: true + # Customize the list of packages installed. + packages: + - open-vm-tools + # Create the default user. + # Ensures the "builder" user doesn't require a password to use sudo. + user-data: + users: + - name: builder + # openssl passwd -6 -salt -stdin <<< + passwd: $ENCRYPTED_SSH_PASSWORD + groups: [adm, cdrom, dip, plugdev, lxd, sudo] + lock-passwd: false + sudo: ALL=(ALL) NOPASSWD:ALL + shell: /bin/bash + + # This command runs after all other steps; it: + # 1. Disables swapfiles + # 2. Removes the existing swapfile + # 3. Removes the swapfile entry from /etc/fstab + # 4. Cleans up any packages that are no longer required + # 5. Removes the cached list of packages + late-commands: + - swapoff -a + - rm -f /swapfile + - sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab + - apt-get purge --auto-remove -y + - rm -rf /var/lib/apt/lists/* diff --git a/images/capi/packer/maas/linux/ubuntu/http/24.04.efi/meta-data b/images/capi/packer/maas/linux/ubuntu/http/24.04.efi/meta-data new file mode 100644 index 0000000000..e69de29bb2 diff --git a/images/capi/packer/maas/linux/ubuntu/http/24.04.efi/user-data.tmpl b/images/capi/packer/maas/linux/ubuntu/http/24.04.efi/user-data.tmpl new file mode 100644 index 0000000000..0d43ca5e1b --- /dev/null +++ b/images/capi/packer/maas/linux/ubuntu/http/24.04.efi/user-data.tmpl @@ -0,0 +1,116 @@ +#cloud-config +# Copyright 2022 The Kubernetes Authors. +# +# 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. + + +# For more information on how autoinstall is configured, please refer to +# https://ubuntu.com/server/docs/install/autoinstall-reference +autoinstall: + version: 1 + # Disable ssh server during installation, otherwise packer tries to connect and exceed max attempts + early-commands: + - systemctl stop ssh + # Configure the locale + locale: en_US.UTF-8 + keyboard: + layout: us + apt: + mirror-selection: + primary: + - uri: http://archive.ubuntu.com/ubuntu + # Create a single-partition with no swap space. Kubernetes + # really dislikes the idea of anyone else managing memory. + # For more information on how partitioning is configured, + # please refer to https://curtin.readthedocs.io/en/latest/topics/storage.html. + storage: + grub: + reorder_uefi: false + replace_linux_default: false + config: + - ptable: gpt + path: /dev/sda + wipe: superblock-recursive + preserve: false + name: '' + grub_device: false + type: disk + id: disk-sda + - device: disk-sda + # Create EFI partition of 512MB same as in Ubuntu 20.04 + size: 536870912 + wipe: superblock + flag: boot + number: 1 + preserve: false + grub_device: true + type: partition + id: partition-0 + - fstype: fat32 + volume: partition-0 + preserve: false + type: format + id: format-0 + - device: disk-sda + size: -1 + wipe: superblock + flag: '' + number: 2 + preserve: false + grub_device: false + type: partition + id: partition-1 + - fstype: ext4 + volume: partition-1 + preserve: false + type: format + id: format-1 + - path: / + device: format-1 + type: mount + id: mount-1 + - path: /boot/efi + device: format-0 + type: mount + id: mount-0 + updates: 'all' + ssh: + install-server: true + allow-pw: true + # Customize the list of packages installed. + packages: + - open-vm-tools + # Create the default user. + # Ensures the "builder" user doesn't require a password to use sudo. + user-data: + users: + - name: builder + # openssl passwd -6 -salt -stdin <<< + passwd: $ENCRYPTED_SSH_PASSWORD + groups: [adm, cdrom, dip, plugdev, lxd, sudo] + lock-passwd: false + sudo: ALL=(ALL) NOPASSWD:ALL + shell: /bin/bash + + # This command runs after all other steps; it: + # 1. Disables swapfiles + # 2. Removes the existing swapfile + # 3. Removes the swapfile entry from /etc/fstab + # 4. Cleans up any packages that are no longer required + # 5. Removes the cached list of packages + late-commands: + - swapoff -a + - rm -f /swapfile + - sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab + - apt-get purge --auto-remove -y + - rm -rf /var/lib/apt/lists/* diff --git a/images/capi/packer/maas/linux/ubuntu/http/24.04/meta-data b/images/capi/packer/maas/linux/ubuntu/http/24.04/meta-data new file mode 100644 index 0000000000..e69de29bb2 diff --git a/images/capi/packer/maas/linux/ubuntu/http/24.04/user-data.tmpl b/images/capi/packer/maas/linux/ubuntu/http/24.04/user-data.tmpl new file mode 100644 index 0000000000..30edc45b19 --- /dev/null +++ b/images/capi/packer/maas/linux/ubuntu/http/24.04/user-data.tmpl @@ -0,0 +1,93 @@ +#cloud-config +# Copyright 2022 The Kubernetes Authors. +# +# 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. + + +# For more information on how autoinstall is configured, please refer to +# https://ubuntu.com/server/docs/install/autoinstall-reference +autoinstall: + version: 1 + # Disable ssh server during installation, otherwise packer tries to connect and exceed max attempts + early-commands: + - systemctl stop ssh + # Configure the locale + locale: en_US.UTF-8 + keyboard: + layout: us + apt: + mirror-selection: + primary: + - uri: http://archive.ubuntu.com/ubuntu + # Create a single-partition with no swap space. Kubernetes + # really dislikes the idea of anyone else managing memory. + # For more information on how partitioning is configured, + # please refer to https://curtin.readthedocs.io/en/latest/topics/storage.html. + storage: + grub: + replace_linux_default: false + config: + - type: disk + id: disk-0 + size: largest + grub_device: true + preserve: false + ptable: msdos + wipe: superblock + - type: partition + id: partition-0 + device: disk-0 + size: -1 + number: 1 + preserve: false + flag: boot + - type: format + id: format-0 + volume: partition-0 + fstype: ext4 + preserve: false + - type: mount + id: mount-0 + device: format-0 + path: / + updates: 'all' + ssh: + install-server: true + allow-pw: true + # Customize the list of packages installed. + packages: + - open-vm-tools + # Create the default user. + # Ensures the "builder" user doesn't require a password to use sudo. + user-data: + users: + - name: builder + # openssl passwd -6 -salt -stdin <<< + passwd: $ENCRYPTED_SSH_PASSWORD + groups: [adm, cdrom, dip, plugdev, lxd, sudo] + lock-passwd: false + sudo: ALL=(ALL) NOPASSWD:ALL + shell: /bin/bash + + # This command runs after all other steps; it: + # 1. Disables swapfiles + # 2. Removes the existing swapfile + # 3. Removes the swapfile entry from /etc/fstab + # 4. Cleans up any packages that are no longer required + # 5. Removes the cached list of packages + late-commands: + - swapoff -a + - rm -f /swapfile + - sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab + - apt-get purge --auto-remove -y + - rm -rf /var/lib/apt/lists/* diff --git a/images/capi/packer/maas/linux/ubuntu/http/base/preseed-efi.cfg.tmpl b/images/capi/packer/maas/linux/ubuntu/http/base/preseed-efi.cfg.tmpl new file mode 100644 index 0000000000..3d6597ca74 --- /dev/null +++ b/images/capi/packer/maas/linux/ubuntu/http/base/preseed-efi.cfg.tmpl @@ -0,0 +1,128 @@ +# Copyright 2019 The Kubernetes Authors. +# +# 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. + +# Configure the locale +d-i debian-installer/locale string en_US.utf8 +d-i console-setup/ask_detect boolean false +d-i console-setup/layout string us + +# Configure the clock +d-i time/zone string UTC +d-i clock-setup/utc-auto boolean true +d-i clock-setup/utc boolean true + +# Configure the keyboard +d-i kbd-chooser/method select American English + +# Configure networking +d-i netcfg/wireless_wep string + +# Select the kernel +d-i base-installer/kernel/override-image string linux-virtual + +# Configure a non-interactive install +debconf debconf/frontend select Noninteractive + +# Configure the base installation +d-i pkgsel/install-language-support boolean false +d-i pkgsel/language-packs multiselect +tasksel tasksel/first multiselect # standard, ubuntu-server + + +### Simple GPT configuration w/o LVM +d-i partman-auto/disk string /dev/sda + +d-i partman/alignment string cylinder +d-i partman/confirm_write_new_label boolean true +d-i partman-basicfilesystems/choose_label string gpt +d-i partman-basicfilesystems/default_label string gpt +d-i partman-partitioning/choose_label string gpt +d-i partman-partitioning/default_label string gpt +d-i partman/choose_label string gpt +d-i partman/default_label string gpt + +d-i partman-auto/method string regular +d-i partman-auto/choose_recipe select gpt-boot-root-swap +d-i partman-auto/expert_recipe string \ + gpt-boot-root-swap :: \ + 1 1 1 free \ + $bios_boot{ } \ + method{ biosgrub } . \ + 200 200 200 fat32 \ + $primary{ } \ + method{ efi } format{ } . \ + 512 512 512 ext3 \ + $primary{ } $bootable{ } \ + method{ format } format{ } \ + use_filesystem{ } filesystem{ ext3 } \ + mountpoint{ /boot } . \ + 1000 20000 -1 ext4 \ + $primary{ } \ + method{ format } format{ } \ + use_filesystem{ } filesystem{ ext4 } \ + mountpoint{ / } . + +d-i partman-partitioning/confirm_write_new_label boolean true +d-i partman/choose_partition select finish +d-i partman/confirm boolean true +d-i partman/confirm_nooverwrite boolean true + +# Create the default user. +d-i passwd/user-fullname string builder +d-i passwd/username string builder +d-i passwd/user-password password $SSH_PASSWORD +d-i passwd/user-password-again password $SSH_PASSWORD +d-i user-setup/encrypt-home boolean false +d-i user-setup/allow-password-weak boolean true + +# Disable upgrading packages upon installation. +d-i pkgsel/upgrade select none +d-i grub-installer/only_debian boolean true +d-i grub-installer/with_other_os boolean true +d-i finish-install/reboot_in_progress note +d-i pkgsel/update-policy select none + +# Disable use of the apt mirror during base install +# This means only packages available in the ISO can be installed +d-i apt-setup/use_mirror boolean false + +# Disable the security repo as well (it's on by default) +d-i apt-setup/services-select multiselect none + +# Customize the list of packages installed. +d-i pkgsel/include string openssh-server + + +# Ensure questions about these packages do not bother the installer. +libssl1.1 libssl1.1/restart-without-asking boolean true +libssl1.1:amd64 libssl1.1/restart-without-asking boolean true +libssl1.1 libssl1.1/restart-services string +libssl1.1:amd64 libssl1.1/restart-services string + + +# This command runs after all other steps; it: +# 1. Ensures the "builder" user doesn't require a password to use sudo +# 2. Cleans up any packages that are no longer required +# 3. Cleans the package cache +# 4. Removes the cached list of packages +# 5. Disables swapfiles +# 6. Removes the existing swapfile +# 7. Removes the swapfile entry from /etc/fstab +d-i preseed/late_command string \ + echo 'builder ALL=(ALL) NOPASSWD: ALL' >/target/etc/sudoers.d/builder ; \ + in-target chmod 440 /etc/sudoers.d/builder ; \ + in-target swapoff -a ; \ + in-target rm -f /swapfile ; \ + in-target sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab ; \ + in-target rm -f /etc/udev/rules.d/70-persistent-net.rules diff --git a/images/capi/packer/maas/linux/ubuntu/http/base/preseed.cfg.tmpl b/images/capi/packer/maas/linux/ubuntu/http/base/preseed.cfg.tmpl new file mode 100644 index 0000000000..8f90e1fe04 --- /dev/null +++ b/images/capi/packer/maas/linux/ubuntu/http/base/preseed.cfg.tmpl @@ -0,0 +1,128 @@ +# Copyright 2019 The Kubernetes Authors. +# +# 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. + +# Configure the locale +d-i debian-installer/locale string en_US.utf8 +d-i debian-installer/add-kernel-opts console=ttyS0 +d-i console-setup/ask_detect boolean false +d-i console-setup/layout string us + +# Configure the clock +d-i time/zone string UTC +d-i clock-setup/utc-auto boolean true +d-i clock-setup/utc boolean true + +# Configure the keyboard +d-i kbd-chooser/method select American English + +# Configure networking +d-i netcfg/wireless_wep string + +# Select the kernel +d-i base-installer/kernel/override-image string linux-virtual + +# Configure a non-interactive install +debconf debconf/frontend select Noninteractive + +# Configure the base installation +d-i pkgsel/install-language-support boolean false +d-i pkgsel/language-packs multiselect +tasksel tasksel/first multiselect # standard, ubuntu-server + +# Create a single-partition with no swap space. For more information +# on how partitioning is configured, please refer to +# https://github.com/xobs/debian-installer/blob/master/doc/devel/partman-auto-recipe.txt. +d-i partman-auto/method string regular +d-i partman-lvm/device_remove_lvm boolean true +d-i partman-md/device_remove_md boolean true +d-i partman-lvm/confirm boolean true +d-i partman-auto-lvm/guided_size string max + +# Again, this creates a single-partition with no swap. Kubernetes +# really dislikes the idea of anyone else managing memory. +d-i partman-auto/expert_recipe string \ + slash :: \ + 0 0 -1 ext4 \ + $primary{ } $bootable{ } \ + method{ format } format{ } \ + use_filesystem{ } filesystem{ ext4 } \ + mountpoint{ / } \ + . + +d-i partman-partitioning/confirm_write_new_label boolean true +d-i partman/choose_partition select finish +d-i partman/confirm boolean true +d-i partman/confirm_nooverwrite boolean true +d-i partman-basicfilesystems/no_swap boolean false +d-i partman-md/confirm boolean true +d-i partman-partitioning/confirm_write_new_label boolean true +d-i partman/choose_partition select finish +d-i partman/confirm boolean true +d-i partman/confirm_nooverwrite boolean true +d-i partman-md/confirm_nooverwrite boolean true +d-i partman-lvm/confirm_nooverwrite boolean true +d-i partman-partitioning/no_bootable_gpt_biosgrub boolean true +d-i partman-partitioning/no_bootable_gpt_efi boolean false +d-i partman-efi/non_efi_system boolean false + +# Create the default user. +d-i passwd/user-fullname string builder +d-i passwd/username string builder +d-i passwd/user-password password $SSH_PASSWORD +d-i passwd/user-password-again password $SSH_PASSWORD +d-i user-setup/encrypt-home boolean false +d-i user-setup/allow-password-weak boolean true + +# Disable upgrading packages upon installation. +d-i pkgsel/upgrade select none +d-i grub-installer/only_debian boolean true +d-i grub-installer/with_other_os boolean true +d-i finish-install/reboot_in_progress note +d-i pkgsel/update-policy select none + +# Disable use of the apt mirror during base install +# This means only packages available in the ISO can be installed +d-i apt-setup/use_mirror boolean false + +# Disable the security repo as well (it's on by default) +d-i apt-setup/services-select multiselect none + +# Customize the list of packages installed. +d-i pkgsel/include string openssh-server + + +# Ensure questions about these packages do not bother the installer. +libssl1.1 libssl1.1/restart-without-asking boolean true +libssl1.1:amd64 libssl1.1/restart-without-asking boolean true +libssl1.1 libssl1.1/restart-services string +libssl1.1:amd64 libssl1.1/restart-services string + + +# This command runs after all other steps; it: +# 1. Ensures the "builder" user doesn't require a password to use sudo +# 2. Cleans up any packages that are no longer required +# 3. Cleans the package cache +# 4. Removes the cached list of packages +# 5. Disables swapfiles +# 6. Removes the existing swapfile +# 7. Removes the swapfile entry from /etc/fstab +d-i preseed/late_command string \ + echo 'builder ALL=(ALL) NOPASSWD: ALL' >/target/etc/sudoers.d/builder ; \ + in-target chmod 440 /etc/sudoers.d/builder ; \ + in-target swapoff -a ; \ + in-target rm -f /swapfile ; \ + in-target sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab ; \ + in-target rm -f /etc/udev/rules.d/70-persistent-net.rules ; \ + in-target apt-get purge --auto-remove -y ; \ + in-target rm -rf /var/lib/apt/lists/* diff --git a/images/capi/packer/maas/maas-ubuntu-2204-efi.json b/images/capi/packer/maas/maas-ubuntu-2204-efi.json new file mode 100644 index 0000000000..fb03d88ad4 --- /dev/null +++ b/images/capi/packer/maas/maas-ubuntu-2204-efi.json @@ -0,0 +1,14 @@ +{ + "boot_command_prefix": "clinux /casper/vmlinuz autoinstall ds='nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/' --- initrd /casper/initrdboot", + "build_name": "ubuntu-2204-efi", + "distro_name": "ubuntu", + "firmware": "OVMF.fd", + "guest_os_type": "ubuntu-64", + "http_directory": "./packer/maas/linux/ubuntu/http/22.04.efi.qemu", + "iso_checksum": "9bc6028870aef3f74f4e16b900008179e78b130e6b0b9a140635434a46aa98b0", + "iso_checksum_type": "sha256", + "iso_url": "https://releases.ubuntu.com/22.04.5/ubuntu-22.04.5-live-server-amd64.iso", + "os_display_name": "Ubuntu 22.04", + "shutdown_command": "shutdown -P now", + "unmount_iso": "true" +} diff --git a/images/capi/packer/maas/maas-ubuntu-2404-efi.json b/images/capi/packer/maas/maas-ubuntu-2404-efi.json new file mode 100644 index 0000000000..94d7df2382 --- /dev/null +++ b/images/capi/packer/maas/maas-ubuntu-2404-efi.json @@ -0,0 +1,14 @@ +{ + "boot_command_prefix": "clinux /casper/vmlinuz --- autoinstall ds='nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/24.04.efi/'initrd /casper/initrdboot", + "build_name": "ubuntu-2404-efi", + "distribution_version": "2404", + "distro_name": "ubuntu", + "firmware": "OVMF.fd", + "guest_os_type": "ubuntu-64", + "iso_checksum": "e240e4b801f7bb68c20d1356b60968ad0c33a41d00d828e74ceb3364a0317be9", + "iso_checksum_type": "sha256", + "iso_url": "https://releases.ubuntu.com/releases/24.04/ubuntu-24.04.1-live-server-amd64.iso", + "os_display_name": "Ubuntu 24.04", + "shutdown_command": "shutdown -P now", + "unmount_iso": "true" +} diff --git a/images/capi/packer/maas/packer.json.tmpl b/images/capi/packer/maas/packer.json.tmpl new file mode 100644 index 0000000000..4784309503 --- /dev/null +++ b/images/capi/packer/maas/packer.json.tmpl @@ -0,0 +1,200 @@ +{ + "builders": [ + { + "accelerator": "{{user `accelerator`}}", + "boot_command": [ + "{{user `boot_command_prefix`}}", + "{{user `boot_media_path`}}", + "{{user `boot_command_suffix`}}" + ], + "boot_wait": "{{user `boot_wait`}}", + "cd_files": [ + "{{user `cd_files`}}" + ], + "cd_label": "cidata", + "cpu_model": "host", + "cpus": "{{user `cpus`}}", + "disk_compression": "{{ user `disk_compression`}}", + "disk_discard": "{{user `disk_discard`}}", + "disk_image": "{{ user `disk_image` }}", + "disk_interface": "virtio-scsi", + "disk_size": "{{user `disk_size`}}", + "firmware": "{{user `firmware`}}", + "format": "{{user `format`}}", + "headless": "{{user `headless`}}", + "http_directory": "{{user `http_directory`}}", + "iso_checksum": "{{user `iso_checksum_type`}}:{{user `iso_checksum`}}", + "iso_url": "{{user `iso_url`}}", + "memory": "{{user `memory`}}", + "net_device": "virtio-net", + "output_directory": "{{user `output_directory`}}", + "qemu_binary": "{{user `qemu_binary`}}", + "shutdown_command": "echo '{{user `ssh_password`}}' | sudo -S -E sh -c 'usermod -L {{user `ssh_username`}} && {{user `shutdown_command`}}'", + "ssh_password": "{{user `ssh_password`}}", + "ssh_timeout": "2h", + "ssh_username": "{{user `ssh_username`}}", + "type": "qemu", + "vm_name": "{{user `vm_name`}}", + "vnc_bind_address": "{{user `vnc_bind_address`}}" + } + ], + "post-processors": [ + { + "environment_vars": [ + "CUSTOM_POST_PROCESSOR={{user `custom_post_processor`}}" + ], + "inline": [ + "if [ \"$CUSTOM_POST_PROCESSOR\" != \"true\" ]; then exit 0; fi", + "{{user `custom_post_processor_command`}}" + ], + "name": "custom-post-processor", + "type": "shell-local" + }, + { + "inline": [ + "sudo bash ./packer/maas/scripts/generate-maas-image.sh {{user `output_directory`}}/{{user `artifact_name`}}" + ], + "name": "convert-to-maas", + "type": "shell-local" + } + ], + "provisioners": [ + { + "environment_vars": [ + "PYPY_HTTP_SOURCE={{user `pypy_http_source`}}" + ], + "execute_command": "BUILD_NAME={{user `build_name`}}; if [[ \"${BUILD_NAME}\" == *\"flatcar\"* ]]; then sudo {{.Vars}} -S -E bash '{{.Path}}'; fi", + "script": "./packer/files/flatcar/scripts/bootstrap-flatcar.sh", + "type": "shell" + }, + { + "ansible_env_vars": [ + "ANSIBLE_SSH_ARGS='{{user `existing_ansible_ssh_args`}} {{user `ansible_common_ssh_args`}}'", + "KUBEVIRT={{user `kubevirt`}}" + ], + "extra_arguments": [ + "--extra-vars", + "{{user `ansible_common_vars`}}", + "--extra-vars", + "{{user `ansible_extra_vars`}}", + "--extra-vars", + "{{user `ansible_user_vars`}}", + "--scp-extra-args", + "{{user `ansible_scp_extra_args`}}" + ], + "playbook_file": "./ansible/firstboot.yml", + "type": "ansible", + "user": "builder" + }, + { + "expect_disconnect": true, + "inline": [ + "sudo reboot now" + ], + "inline_shebang": "/bin/bash -e", + "type": "shell" + }, + { + "ansible_env_vars": [ + "ANSIBLE_SSH_ARGS='{{user `existing_ansible_ssh_args`}} {{user `ansible_common_ssh_args`}}'", + "KUBEVIRT={{user `kubevirt`}}" + ], + "extra_arguments": [ + "--extra-vars", + "{{user `ansible_common_vars`}}", + "--extra-vars", + "{{user `ansible_extra_vars`}}", + "--extra-vars", + "{{user `ansible_user_vars`}}", + "--scp-extra-args", + "{{user `ansible_scp_extra_args`}}" + ], + "playbook_file": "./ansible/node.yml", + "type": "ansible", + "user": "builder" + }, + { + "arch": "{{user `goss_arch`}}", + "format": "{{user `goss_format`}}", + "format_options": "{{user `goss_format_options`}}", + "goss_file": "{{user `goss_entry_file`}}", + "inspect": "{{user `goss_inspect_mode`}}", + "tests": [ + "{{user `goss_tests_dir`}}" + ], + "type": "goss", + "url": "{{user `goss_url`}}", + "use_sudo": true, + "vars_file": "{{user `goss_vars_file`}}", + "vars_inline": { + "ARCH": "amd64", + "OS": "{{user `distro_name` | lower}}", + "OS_VERSION": "{{user `distribution_version` | lower}}", + "PROVIDER": "qemu", + "containerd_version": "{{user `containerd_version`}}", + "kubernetes_cni_deb_version": "{{ user `kubernetes_cni_deb_version` }}", + "kubernetes_cni_rpm_version": "{{ split (user `kubernetes_cni_rpm_version`) \"-\" 0 }}", + "kubernetes_cni_source_type": "{{user `kubernetes_cni_source_type`}}", + "kubernetes_cni_version": "{{user `kubernetes_cni_semver` | replace \"v\" \"\" 1}}", + "kubernetes_deb_version": "{{ user `kubernetes_deb_version` }}", + "kubernetes_rpm_version": "{{ split (user `kubernetes_rpm_version`) \"-\" 0 }}", + "kubernetes_source_type": "{{user `kubernetes_source_type`}}", + "kubernetes_version": "{{user `kubernetes_semver` | replace \"v\" \"\" 1}}" + }, + "version": "{{user `goss_version`}}" + } + ], + "variables": { + "accelerator": "kvm", + "ansible_common_vars": "", + "ansible_extra_vars": "ansible_python_interpreter=/usr/bin/python3", + "ansible_user_vars": "", + "artifact_name": "{{user `build_name`}}-kube-{{user `kubernetes_semver`}}", + "boot_media_path": "http://{{ .HTTPIP }}:{{ .HTTPPort }}", + "boot_wait": "10s", + "build_timestamp": "{{timestamp}}", + "cd_files": "linux/base/*.nothing", + "containerd_sha256": null, + "containerd_url": "https://github.com/containerd/containerd/releases/download/v{{user `containerd_version`}}/cri-containerd-cni-{{user `containerd_version`}}-linux-amd64.tar.gz", + "containerd_version": null, + "cpus": "1", + "crictl_url": "https://github.com/kubernetes-sigs/cri-tools/releases/download/v{{user `crictl_version`}}/crictl-v{{user `crictl_version`}}-linux-amd64.tar.gz", + "crictl_version": null, + "disk_compression": "false", + "disk_discard": "unmap", + "disk_image": "false", + "disk_size": "20480", + "existing_ansible_ssh_args": "{{env `ANSIBLE_SSH_ARGS`}}", + "firmware": "", + "format": "qcow2", + "headless": "true", + "http_directory": "./packer/qemu/linux/{{user `distro_name`}}/http/", + "kubernetes_cni_deb_version": null, + "kubernetes_cni_http_source": null, + "kubernetes_cni_semver": null, + "kubernetes_cni_source_type": null, + "kubernetes_container_registry": null, + "kubernetes_deb_gpg_key": null, + "kubernetes_deb_repo": null, + "kubernetes_deb_version": null, + "kubernetes_http_source": null, + "kubernetes_load_additional_imgs": null, + "kubernetes_rpm_gpg_check": null, + "kubernetes_rpm_gpg_key": null, + "kubernetes_rpm_repo": null, + "kubernetes_rpm_version": null, + "kubernetes_semver": null, + "kubernetes_series": null, + "kubernetes_source_type": null, + "machine_id_mode": "444", + "memory": "2048", + "oem_id": "", + "output_directory": "./output/{{user `build_name`}}-kube-{{user `kubernetes_semver`}}", + "python_path": "", + "qemu_binary": "qemu-system-x86_64", + "ssh_password": "$SSH_PASSWORD", + "ssh_username": "builder", + "vm_name": "{{user `build_name`}}-kube-{{user `kubernetes_semver`}}", + "vnc_bind_address": "127.0.0.1" + } +} diff --git a/images/capi/packer/maas/scripts/generate-maas-image.sh b/images/capi/packer/maas/scripts/generate-maas-image.sh new file mode 100644 index 0000000000..eb67948592 --- /dev/null +++ b/images/capi/packer/maas/scripts/generate-maas-image.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +QEMU_IMAGE_FILE=$1 +IMAGE_NAME=$(basename $QEMU_IMAGE_FILE) +BASE_PATH=$(dirname $QEMU_IMAGE_FILE) + +echo "Qemu qcow2 file: $QEMU_IMAGE_FILE" +echo "Image name: $IMAGE_NAME" + +TMP_DIR=$(mktemp -d /tmp/packer-maas-XXXX) +echo 'Binding packer qcow2 image output to nbd ...' +modprobe nbd +qemu-nbd -d /dev/nbd4 +qemu-nbd -c /dev/nbd4 -n $QEMU_IMAGE_FILE +echo 'Waiting for partitions to be created...' +tries=0 +while [ ! -e /dev/nbd4p2 -a $tries -lt 60 ]; do + sleep 1 + let tries++ +done + +if [[ $tries -gt 60 ]]; then + echo "partition /dev/nbd4p2 cannot be mounted. Stopping here!!" + exit 2 +fi + +echo "mounting image..." +mount /dev/nbd4p2 $TMP_DIR +mount "/dev/nbd4p1" "$TMP_DIR/boot/efi" +echo 'Tarring up image...' +tar -Sczpf $BASE_PATH/$IMAGE_NAME.tar.gz --acls --selinux --xattrs -C $TMP_DIR . +echo 'Unmounting image...' +umount "$TMP_DIR/boot/efi" +umount $TMP_DIR +qemu-nbd -d /dev/nbd4 +rmdir $TMP_DIR +