Skip to content
Open
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
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ endif
# Image URL to use all building/pushing image targets
IMAGE_NAME := cluster-api-provider-maas-controller
REGISTRY ?= "us-east1-docker.pkg.dev/spectro-images/dev/${USER}/cluster-api"
SPECTRO_VERSION ?= 4.0.0-dev-29082025
SPECTRO_VERSION ?= 4.0.0-dev-18102025-01
IMG_TAG ?= v0.6.1-spectro-${SPECTRO_VERSION}
CONTROLLER_IMG ?= ${REGISTRY}/${IMAGE_NAME}


LXD_IMAGE_NAME ?= "lxd-initializer"
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name should not have quotes around the string value. In Makefiles, quotes are literal and will be included in the variable value, which could cause issues when the variable is used in commands.

Suggested change
LXD_IMAGE_NAME ?= "lxd-initializer"
LXD_IMAGE_NAME ?= lxd-initializer

Copilot uses AI. Check for mistakes.
LXD_CONTROLLER_IMG ?= ${REGISTRY}/${LXD_IMAGE_NAME}

# Set --output-base for conversion-gen if we are not within GOPATH
ifneq ($(abspath $(REPO_ROOT)),$(shell go env GOPATH)/src/github.com/spectrocloud/cluster-api-provider-maas)
GEN_OUTPUT_BASE := --output-base=$(REPO_ROOT)
Expand Down Expand Up @@ -213,17 +217,14 @@ version: ## Prints version of current make
# --------------------------------------------------------------------
# LXD-initializer image (privileged DaemonSet)
# --------------------------------------------------------------------
INIT_IMAGE_NAME ?= "lxd-initializer"
INIT_IMG_TAG ?= $(IMG_TAG) # reuse the same tag as controller
INIT_DRI_IMG ?= us-east1-docker.pkg.dev/spectro-images/dev/$(USER)/cluster-api/$(INIT_IMAGE_NAME):$(INIT_IMG_TAG)

.PHONY: lxd-initializer-docker-build
lxd-initializer-docker-build: ## Build LXD initializer image
docker buildx build --load --platform linux/$(ARCH) \
-f lxd-initializer/Dockerfile \
${BUILD_ARGS} \
lxd-initializer -t $(INIT_DRI_IMG)
lxd-initializer -t $(LXD_CONTROLLER_IMG):$(IMG_TAG)

.PHONY: lxd-initializer-docker-push
lxd-initializer-docker-push: ## Push LXD initializer image
docker push $(INIT_DRI_IMG)
docker push $(LXD_CONTROLLER_IMG):$(IMG_TAG)
47 changes: 26 additions & 21 deletions controllers/templates/lxd_initializer_ds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,29 @@ spec:
effect: "NoSchedule"
initContainers:
- name: ensure-lxd
image: ubuntu:22.04
image: us-east1-docker.pkg.dev/spectro-images/cluster-api/lxd-initializer:v0.6.1-spectro-4.7.13
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The image tag is hardcoded with a specific version. Consider using a variable or template substitution to make this configurable and consistent with the build system.

Suggested change
image: us-east1-docker.pkg.dev/spectro-images/cluster-api/lxd-initializer:v0.6.1-spectro-4.7.13
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}

Copilot uses AI. Check for mistakes.
imagePullPolicy: IfNotPresent
command:
- /bin/bash
- /bin/sh
- -c
- |
set -ex
if ! command -v lxd >/dev/null 2>&1; then
echo "LXD not present, installing via snap";
apt-get update;
apt-get install -y snapd systemd;
systemctl enable --now snapd.socket;
snap install lxd --channel=5.0/stable;
fi
echo "Ensuring LXD daemon is running on host";
if nsenter -t 1 -m -p -- systemctl is-active --quiet snap.lxd.daemon; then
echo "LXD daemon already active";
# Install LXD on host if missing (operate only via nsenter on the host)
if nsenter -t 1 -m -p -- test -x /snap/bin/lxd; then
echo "LXD present on host"
else
echo "Starting LXD daemon via host systemd";
nsenter -t 1 -m -p -- systemctl start snap.lxd.daemon || snap start --enable lxd.daemon;
echo "Installing LXD via snap on host"
nsenter -t 1 -m -p -- sh -c 'command -v apt-get >/dev/null 2>&1 && apt-get update || true'
nsenter -t 1 -m -p -- sh -c 'command -v apt-get >/dev/null 2>&1 && apt-get install -y snapd systemd || true'
Comment on lines +44 to +45
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repeated nsenter -t 1 -m -p -- sh -c 'command -v apt-get >/dev/null 2>&1 && pattern creates code duplication. Consider extracting this into a shell function or combining the commands into a single nsenter call.

Suggested change
nsenter -t 1 -m -p -- sh -c 'command -v apt-get >/dev/null 2>&1 && apt-get update || true'
nsenter -t 1 -m -p -- sh -c 'command -v apt-get >/dev/null 2>&1 && apt-get install -y snapd systemd || true'
nsenter -t 1 -m -p -- sh -c 'if command -v apt-get >/dev/null 2>&1; then apt-get update && apt-get install -y snapd systemd; fi || true'

Copilot uses AI. Check for mistakes.
nsenter -t 1 -m -p -- systemctl enable --now snapd.socket || true
nsenter -t 1 -m -p -- snap install lxd --channel=5.0/stable
fi
# Ensure daemon running
nsenter -t 1 -m -p -- sh -c 'systemctl is-active --quiet snap.lxd.daemon || systemctl start snap.lxd.daemon || snap start --enable lxd.daemon'
# Wait for LXD to report readiness (up to 5 minutes)
echo "Waiting for LXD to become ready on host (timeout 5 min)…"
if ! nsenter -t 1 -m -p -- /snap/bin/lxd waitready --timeout 300 ; then
echo "LXD did not become ready after 5 minutes"; exit 1;
fi
echo "Host LXD is ready";
nsenter -t 1 -m -p -- /snap/bin/lxd waitready --timeout 300
echo "Host LXD is ready"

securityContext:
privileged: true
Expand All @@ -73,8 +70,8 @@ spec:
mountPropagation: HostToContainer
containers:
- name: lxd-initializer
image: us-east1-docker.pkg.dev/spectro-images/dev/amit/cluster-api/lxd-initializer:v0.6.1-spectro-4.0.0-dev-17102025-01
imagePullPolicy: Always
image: us-east1-docker.pkg.dev/spectro-images/cluster-api/lxd-initializer:v0.6.1-spectro-4.7.13
imagePullPolicy: IfNotPresent
securityContext:
privileged: true
env:
Expand All @@ -93,7 +90,7 @@ spec:
- name: NIC_PARENT
value: "${NIC_PARENT}"
- name: STORAGE_SIZE
value: "${STORAGE_SIZE}"
value: "${STORAGE_SIZE}"
- name: NETWORK_BRIDGE
value: "${NETWORK_BRIDGE}"
- name: SKIP_NETWORK_UPDATE
Expand Down Expand Up @@ -138,3 +135,11 @@ spec:
serviceAccount: lxd-initializer
serviceAccountName: lxd-initializer
restartPolicy: Always
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: lxdhost.cluster.com/initialized
operator: NotIn
values: ["true"]
6 changes: 3 additions & 3 deletions lxd-initializer/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ make build
make docker-push REGISTRY=<your-registry> TAG=<your-tag>

# Update the DaemonSet manifest with your registry and tag
sed -i 's/${REGISTRY}/<your-registry>/g' lxd-initializer-daemonset.yaml
sed -i 's/${TAG}/<your-tag>/g' lxd-initializer-daemonset.yaml
sed -i 's/${REGISTRY}/<your-registry>/g' ../controllers/templates/lxd_initializer_ds.yaml
sed -i 's/${TAG}/<your-tag>/g' ../controllers/templates/lxd_initializer_ds.yaml

# Apply the DaemonSet manifest
kubectl apply -f lxd-initializer-daemonset.yaml
kubectl apply -f ../controllers/templates/lxd_initializer_ds.yaml
```

### 2. Configure CAPMaaS to Use the DaemonSet
Expand Down
71 changes: 0 additions & 71 deletions lxd-initializer/lxd-initializer-daemonset.yaml

This file was deleted.