Skip to content

Commit

Permalink
Add -kube suffix to pillar when building for kubevirt-EVE
Browse files Browse the repository at this point in the history
When pillar is built for kubevirt-EVE (HV=kubevirt), it carries
additional kubernetes-specific code and dependencies.
It is important to distinguish it from pillar built for kvm/xen-EVE.
Otherwise, previously built kvm/xen pillar can be accidentally
taken from the linuxkit cache and used for a kubevirt-EVE image,
missing all those kubernetes dependencies.

Signed-off-by: Milan Lenco <[email protected]>
  • Loading branch information
milan-zededa committed Aug 7, 2024
1 parent eda3632 commit 5e76b8d
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 14 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1014,15 +1014,16 @@ endif

# If DEV=y and file pkg/my_package/build-dev.yml exists, returns the path to that file.
# If RSTATS=y and file pkg/my_package/build-rstats.yml exists, returns the path to that file.
# If HV=kubevirt and file pkg/my_package/build-kubevirt.yml exists, returns the path to that file.
# If HV=kubevirt and DEV=y and file pkg/my_package/build-kubevirt-dev.yml exists, returns the path to that file.
# If HV=kubevirt and DEV!=y and file pkg/my_package/build-kubevirt.yml exists, returns the path to that file.
# Otherwise returns pkg/my_package/build.yml.
get_pkg_build_yml = $(if $(filter kubevirt,$(HV)), $(call get_pkg_build_kubevirt_yml,$1), \
$(if $(filter y,$(RSTATS)), $(call get_pkg_build_rstats_yml,$1), \
$(if $(filter y,$(DEV)), $(call get_pkg_build_dev_yml,$1), build.yml)))
get_pkg_build_dev_yml = $(if $(wildcard pkg/$1/build-dev.yml),build-dev.yml,build.yml)
get_pkg_build_rstats_yml = $(if $(wildcard pkg/$1/build-rstats.yml),build-rstats.yml,build.yml)
get_pkg_build_kubevirt_yml = $(if $($(DEV),y),build-kubevirt-dev.yml, \
$(if $(wildcard pkg/$1/build-kubevirt.yml),build-kubevirt.yml,build.yml))
get_pkg_build_kubevirt_yml = $(if $(and $(filter y,$(DEV)),$(wildcard pkg/$1/build-kubevirt-dev.yml)),build-kubevirt-dev.yml, \
$(if $(wildcard pkg/$1/build-kubevirt.yml),build-kubevirt.yml,build.yml))

eve-%: pkg/%/Dockerfile build-tools $(RESCAN_DEPS)
$(QUIET): "$@: Begin: LINUXKIT_PKG_TARGET=$(LINUXKIT_PKG_TARGET)"
Expand Down
16 changes: 16 additions & 0 deletions docs/BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,22 @@ The package `pillar` contains, unsurprisingly, the `pillar` services that are re

`pillar` depends upon the latest versions of these being available at its compile time in its vendor directory at [pkg/pillar/vendor](../pkg/pillar/vendor). The target `make proto-vendor` will vendor them into [pkg/pillar/vendor](../pkg/pillar/vendor).

##### pillar build variants

The package pillar is built using the Makefile command: `make pkg/pillar [VAR1=value1 VAR2=value2 ...]`

Depending on the values of optional variables, the following pillar build variants are currently available:

* `make pkg/pillar`: Production version of pillar for the KVM or Xen hypervisor. There is no difference
in the pillar build between KVM and Xen hypervisors, and the default `HV=kvm` can be used for both.
* `make pkg/pillar DEV=y`: Development version of pillar for the KVM or Xen hypervisor. Debug symbols
are preserved and seccomp is disabled in the pillar container.
* `make pkg/pillar HV=kubevirt`: Production version of pillar for the KubeVirt hypervisor (EVE using
K3s + KubeVirt to deploy applications as VMs inside Kubernetes Pods). Contains additional
microservices and Go package dependencies specific to Kubernetes.
* `make pkg/pillar HV=kubevirt DEV=y`: Development version of pillar for the KubeVirt hypervisor.
Debug symbols are preserved and seccomp is disabled in the pillar container.

### Building packages

Packages are built within a docker container as defined by the `Dockerfile` within the package directory. The `Dockerfile` also specifies how the package will be built within the container. Some packages have a separate script to built them which is then invoked using the `RUN` clause within the `Dockerfile`. For some others like the `kernel` package, the entire build script is specified within the `Dockerfile`. Finally, the built docker images are published [here](https://hub.docker.com/u/lfedge). Please note that since our organization on DockerHub is managed by Linux Foundation, we have to request that they create a new package namespace for us every time we add a new package. For example, if you're adding `pkg/eve-foo` you will have to request a `New Repository` named `https://hub.docker.com/r/lfedge/eve-foo` via [LF JIRA](https://jira.linuxfoundation.org/plugins/servlet/desk/portal/2). Don't forget to ask for permissions setting to be copied from `https://hub.docker.com/r/lfedge/eve`.
Expand Down
2 changes: 1 addition & 1 deletion pkg/pillar/build-kubevirt-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

---
org: lfedge
image: eve-pillar-dev
image: eve-pillar-kube-dev
config:
binds:
- /lib/modules:/lib/modules
Expand Down
2 changes: 1 addition & 1 deletion pkg/pillar/build-kubevirt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

---
org: lfedge
image: eve-pillar
image: eve-pillar-kube
config:
binds:
- /lib/modules:/lib/modules
Expand Down
24 changes: 20 additions & 4 deletions tools/compose-image-yml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,32 @@ process-image-template() {
flags="$(sed -r 's/-dirty[0-9.\-]{18}//g' <<< "${flags}")"
IFS='-' read -r -a bits <<< "${flags}"

local dev=0
local kubevirt=0
for bit in "${bits[@]}"; do
case "${bit}" in
dev)
# shellcheck disable=SC2094
yq '(.onboot[] | select(.image == "PILLAR_TAG").image) |= "PILLAR_DEV_TAG"' < "${out_templ_path}" | spongefile "${out_templ_path}"
# shellcheck disable=SC2094
yq '(.services[] | select(.image == "PILLAR_TAG").image) |= "PILLAR_DEV_TAG"' < "${out_templ_path}" | spongefile "${out_templ_path}"
dev=1
;;
kubevirt)
kubevirt=1
;;
esac
done

local pillar_tag="PILLAR_TAG"
if [[ $dev -eq 1 && $kubevirt -eq 1 ]]; then
pillar_tag="PILLAR_KUBEVIRT_DEV_TAG"
elif [[ $dev -eq 1 ]]; then
pillar_tag="PILLAR_DEV_TAG"
elif [[ $kubevirt -eq 1 ]]; then
pillar_tag="PILLAR_KUBEVIRT_TAG"
fi

# shellcheck disable=SC2094
yq '(.onboot[] | select(.image == "PILLAR_TAG").image) |= "'"$pillar_tag"'"' < "${out_templ_path}" | spongefile "${out_templ_path}"
# shellcheck disable=SC2094
yq '(.services[] | select(.image == "PILLAR_TAG").image) |= "'"$pillar_tag"'"' < "${out_templ_path}" | spongefile "${out_templ_path}"
}

patch_hv() {
Expand Down
34 changes: 29 additions & 5 deletions tools/parse-pkgs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,41 @@ get_git_tag() {

linuxkit_tag() {
local pkg="$1"
_linuxkit_tag 0 "${pkg}"
_linuxkit_tag 0 0 "${pkg}"
}

linuxkit_dev_tag() {
local pkg="$1"
_linuxkit_tag 1 "${pkg}"
_linuxkit_tag 0 1 "${pkg}"
}

linuxkit_kubevirt_tag() {
local pkg="$1"
_linuxkit_tag 1 0 "${pkg}"
}

linuxkit_kubevirt_dev_tag() {
local pkg="$1"
_linuxkit_tag 1 1 "${pkg}"
}

# Function returns tag generated by linuxkit for a given EVE package.
# Arguments: <is-kubevirt-build> <is-dev-build> <package>
# where <is-kubevirt-build> should be 1 if HV=kubevirt, 0 otherwise;
# <is-dev-build> should be 1 if DEV=y, 0 otherwise;
# <package> should be eve package name in the format "pkg/<name>" (e.g. "pkg/pillar").
_linuxkit_tag() {
local is_dev_build="$1"
local pkg="$2"
local is_kubevirt_build="$1"
local is_dev_build="$2"
local pkg="$3"
local -a build_yml_cmd

if [[ "${is_dev_build}" == 1 ]]; then
if [[ "${is_dev_build}" == 1 && "${is_kubevirt_build}" == 1 ]]; then
build_yml_cmd=(--build-yml build-kubevirt-dev.yml)
elif [[ "${is_dev_build}" == 1 ]]; then
build_yml_cmd=(--build-yml build-dev.yml)
elif [[ "${is_kubevirt_build}" == 1 ]]; then
build_yml_cmd=(--build-yml build-kubevirt.yml)
fi

echo "$(linuxkit pkg show-tag "${build_yml_cmd[@]}" ${EVE_HASH:+--hash $EVE_HASH} "${EVE}/${pkg}")${ARCH}"
Expand Down Expand Up @@ -97,6 +117,8 @@ DNSMASQ_TAG=${DNSMASQ_TAG}
TESTMSVCS_TAG=${TESTMSVCS_TAG}
PILLAR_TAG=${PILLAR_TAG}
PILLAR_DEV_TAG=${PILLAR_DEV_TAG}
PILLAR_KUBEVIRT_TAG=${PILLAR_KUBEVIRT_TAG}
PILLAR_KUBEVIRT_DEV_TAG=${PILLAR_KUBEVIRT_DEV_TAG}
STORAGE_INIT_TAG=${STORAGE_INIT_TAG}
WWAN_TAG=${WWAN_TAG}
WLAN_TAG=${WLAN_TAG}
Expand Down Expand Up @@ -157,6 +179,8 @@ WLAN_TAG=$(linuxkit_tag pkg/wlan)
GUACD_TAG=$(linuxkit_tag pkg/guacd)
PILLAR_TAG=$(linuxkit_tag pkg/pillar)
PILLAR_DEV_TAG=$(linuxkit_dev_tag pkg/pillar)
PILLAR_KUBEVIRT_TAG=$(linuxkit_kubevirt_tag pkg/pillar)
PILLAR_KUBEVIRT_DEV_TAG=$(linuxkit_kubevirt_dev_tag pkg/pillar)
STORAGE_INIT_TAG=$(linuxkit_tag pkg/storage-init)
GPTTOOLS_TAG=$(linuxkit_tag pkg/gpt-tools)
WATCHDOG_TAG=$(linuxkit_tag pkg/watchdog)
Expand Down

0 comments on commit 5e76b8d

Please sign in to comment.