diff options
Diffstat (limited to 'recipes-containers/k3s/k3s_git.bb')
| -rw-r--r-- | recipes-containers/k3s/k3s_git.bb | 85 |
1 files changed, 77 insertions, 8 deletions
diff --git a/recipes-containers/k3s/k3s_git.bb b/recipes-containers/k3s/k3s_git.bb index a1e3ec8c..b3c53df6 100644 --- a/recipes-containers/k3s/k3s_git.bb +++ b/recipes-containers/k3s/k3s_git.bb | |||
| @@ -4,23 +4,47 @@ HOMEPAGE = "https://k3s.io/" | |||
| 4 | LICENSE = "Apache-2.0" | 4 | LICENSE = "Apache-2.0" |
| 5 | LIC_FILES_CHKSUM = "file://${S}/src/import/LICENSE;md5=2ee41112a44fe7014dce33e26468ba93" | 5 | LIC_FILES_CHKSUM = "file://${S}/src/import/LICENSE;md5=2ee41112a44fe7014dce33e26468ba93" |
| 6 | 6 | ||
| 7 | SRC_URI = "git://github.com/rancher/k3s.git;branch=release-1.34;name=k3s;protocol=https;destsuffix=${GO_SRCURI_DESTSUFFIX} \ | 7 | SRC_URI = "git://github.com/rancher/k3s.git;branch=release-1.36;name=k3s;protocol=https;destsuffix=${GO_SRCURI_DESTSUFFIX} \ |
| 8 | file://k3s.service \ | 8 | file://k3s.service \ |
| 9 | file://k3s-agent.service \ | 9 | file://k3s-agent.service \ |
| 10 | file://k3s-agent \ | 10 | file://k3s-agent \ |
| 11 | file://k3s-clean \ | 11 | file://k3s-clean \ |
| 12 | file://cni-containerd-net.conf \ | 12 | file://cni-flannel.conflist \ |
| 13 | file://0001-Finding-host-local-in-usr-libexec.patch;patchdir=src/import \ | ||
| 14 | file://k3s-killall.sh \ | 13 | file://k3s-killall.sh \ |
| 14 | file://k3s-role-setup.sh \ | ||
| 15 | file://k3s-role-setup.service \ | ||
| 16 | file://k3s-get-token.sh \ | ||
| 17 | file://10-k3s-cluster.network \ | ||
| 15 | " | 18 | " |
| 16 | 19 | ||
| 20 | # Traefik Helm charts — downloaded and embedded into the k3s binary | ||
| 21 | # so they can be served via the k3s static chart endpoint at runtime. | ||
| 22 | # Opt-in via PACKAGECONFIG since traefik is not needed for basic k3s | ||
| 23 | # operation and the chart images must be pullable at runtime. | ||
| 24 | TRAEFIK_CHART_VERSION = "39.0.501+up39.0.5" | ||
| 25 | SRC_URI += "${@bb.utils.contains('PACKAGECONFIG', 'traefik', \ | ||
| 26 | 'https://k3s.io/k3s-charts/assets/traefik-crd/traefik-crd-${TRAEFIK_CHART_VERSION}.tgz;name=traefik-crd;unpack=0;subdir=charts \ | ||
| 27 | https://k3s.io/k3s-charts/assets/traefik/traefik-${TRAEFIK_CHART_VERSION}.tgz;name=traefik;unpack=0;subdir=charts', \ | ||
| 28 | '', d)}" | ||
| 29 | SRC_URI[traefik-crd.sha256sum] = "c6245bdcfd193d10ec956d90c50e0d1a3fa1bde541df80744e72eee91b054640" | ||
| 30 | SRC_URI[traefik.sha256sum] = "888de9d098769b9199238076bee225d1b10dba1e889b0e28127eddc38cdb435b" | ||
| 31 | |||
| 17 | SRC_URI[k3s.md5sum] = "363d3a08dc0b72ba6e6577964f6e94a5" | 32 | SRC_URI[k3s.md5sum] = "363d3a08dc0b72ba6e6577964f6e94a5" |
| 18 | SRCREV_k3s = "54f28d21a6208b1f8f9c33e14cf1fc65c2030107" | 33 | SRCREV_k3s = "a9663261a7ff40522542485a6b2f81916b6d72f9" |
| 19 | 34 | ||
| 20 | SRCREV_FORMAT = "k3s_fuse" | 35 | SRCREV_FORMAT = "k3s_fuse" |
| 21 | PV = "v1.34.1+k3s1+git" | 36 | PV = "v1.36.1+k3s1+git" |
| 37 | |||
| 38 | # K3s uses flannel for CNI networking, not the containerd bridge config | ||
| 39 | CNI_NETWORKING_FILES ?= "${UNPACKDIR}/cni-flannel.conflist" | ||
| 22 | 40 | ||
| 23 | CNI_NETWORKING_FILES ?= "${UNPACKDIR}/cni-containerd-net.conf" | 41 | # Claim the cluster network interface (eth1) so systemd-networkd's |
| 42 | # default catch-all doesn't configure it with DHCP. The static IP | ||
| 43 | # is set at boot by k3s-role-setup.service via a networkd drop-in. | ||
| 44 | VIRT_NETWORKING_FILES ?= "${UNPACKDIR}/10-k3s-cluster.network" | ||
| 45 | |||
| 46 | PACKAGECONFIG ??= "traefik" | ||
| 47 | PACKAGECONFIG[traefik] = ",,," | ||
| 24 | 48 | ||
| 25 | # Build tags - used by both do_compile and do_discover_modules | 49 | # Build tags - used by both do_compile and do_discover_modules |
| 26 | TAGS = "static_build netcgo osusergo providerless" | 50 | TAGS = "static_build netcgo osusergo providerless" |
| @@ -32,6 +56,12 @@ GO_MOD_DISCOVERY_LDFLAGS = "-X github.com/k3s-io/k3s/pkg/version.Version=${PV} - | |||
| 32 | GO_MOD_DISCOVERY_GIT_REPO = "https://github.com/rancher/k3s.git" | 56 | GO_MOD_DISCOVERY_GIT_REPO = "https://github.com/rancher/k3s.git" |
| 33 | GO_MOD_DISCOVERY_GIT_REF = "${SRCREV_k3s}" | 57 | GO_MOD_DISCOVERY_GIT_REF = "${SRCREV_k3s}" |
| 34 | 58 | ||
| 59 | # License-scan filter targets — do_compile builds exactly the one binary | ||
| 60 | # from ./cmd/server/main.go, which transitively imports the other ./cmd/* | ||
| 61 | # subcommands. `go list -deps` on this entry point gives the full set of | ||
| 62 | # modules whose code lands in the binary. | ||
| 63 | GO_MOD_DISCOVERY_LICENSE_TARGETS = "./cmd/server/main.go" | ||
| 64 | |||
| 35 | # GO_MOD_FETCH_MODE: "vcs" (all git://) or "hybrid" (gomod:// + git://) | 65 | # GO_MOD_FETCH_MODE: "vcs" (all git://) or "hybrid" (gomod:// + git://) |
| 36 | GO_MOD_FETCH_MODE ?= "hybrid" | 66 | GO_MOD_FETCH_MODE ?= "hybrid" |
| 37 | 67 | ||
| @@ -44,10 +74,16 @@ include ${@ "go-mod-hybrid-gomod.inc" if d.getVar("GO_MOD_FETCH_MODE") == "hybri | |||
| 44 | include ${@ "go-mod-hybrid-git.inc" if d.getVar("GO_MOD_FETCH_MODE") == "hybrid" else ""} | 74 | include ${@ "go-mod-hybrid-git.inc" if d.getVar("GO_MOD_FETCH_MODE") == "hybrid" else ""} |
| 45 | include ${@ "go-mod-hybrid-cache.inc" if d.getVar("GO_MOD_FETCH_MODE") == "hybrid" else ""} | 75 | include ${@ "go-mod-hybrid-cache.inc" if d.getVar("GO_MOD_FETCH_MODE") == "hybrid" else ""} |
| 46 | 76 | ||
| 77 | # Dependency license tracking (generated by oe-go-mod-fetcher --scan-licenses). | ||
| 78 | # Use `include` (not `require`) so the recipe parses on first-time enablement | ||
| 79 | # before discover_and_generate has been run to create the file. | ||
| 80 | include go-mod-licenses.inc | ||
| 81 | |||
| 47 | inherit go | 82 | inherit go |
| 48 | inherit goarch | 83 | inherit goarch |
| 49 | inherit systemd | 84 | inherit systemd |
| 50 | inherit cni_networking | 85 | inherit cni_networking |
| 86 | inherit virt_networking | ||
| 51 | inherit go-mod-discovery | 87 | inherit go-mod-discovery |
| 52 | 88 | ||
| 53 | BB_GIT_SHALLOW = "1" | 89 | BB_GIT_SHALLOW = "1" |
| @@ -89,6 +125,20 @@ do_compile() { | |||
| 89 | # go.mod and go.sum are synchronized by do_sync_go_files task | 125 | # go.mod and go.sum are synchronized by do_sync_go_files task |
| 90 | # No manual fixes needed - discovery and recipe generation handle version matching | 126 | # No manual fixes needed - discovery and recipe generation handle version matching |
| 91 | 127 | ||
| 128 | # Populate embed directories before build — upstream scripts/build | ||
| 129 | # does this to embed manifests and static content into the binary | ||
| 130 | # via go:embed. Without this, k3s's deploy.Stage() has no manifests | ||
| 131 | # to process and system components (coredns, metrics-server, etc.) | ||
| 132 | # are not deployed on first server start. | ||
| 133 | cp -a manifests/* pkg/deploy/embed/ | ||
| 134 | |||
| 135 | # Embed traefik Helm charts if enabled via PACKAGECONFIG | ||
| 136 | if ${@bb.utils.contains('PACKAGECONFIG', 'traefik', 'true', 'false', d)}; then | ||
| 137 | mkdir -p pkg/static/embed/charts | ||
| 138 | cp -a ${WORKDIR}/sources/charts/traefik-crd-${TRAEFIK_CHART_VERSION}.tgz pkg/static/embed/charts/ | ||
| 139 | cp -a ${WORKDIR}/sources/charts/traefik-${TRAEFIK_CHART_VERSION}.tgz pkg/static/embed/charts/ | ||
| 140 | fi | ||
| 141 | |||
| 92 | VERSION_GOLANG="$(go version | cut -d" " -f3)" | 142 | VERSION_GOLANG="$(go version | cut -d" " -f3)" |
| 93 | ${GO} build -trimpath -tags "${TAGS}" -ldflags "-X github.com/k3s-io/k3s/pkg/version.UpstreamGolang=$VERSION_GOLANG ${GO_BUILD_LDFLAGS} -w -s" -o ./dist/artifacts/k3s ./cmd/server/main.go | 143 | ${GO} build -trimpath -tags "${TAGS}" -ldflags "-X github.com/k3s-io/k3s/pkg/version.UpstreamGolang=$VERSION_GOLANG ${GO_BUILD_LDFLAGS} -w -s" -o ./dist/artifacts/k3s ./cmd/server/main.go |
| 94 | 144 | ||
| @@ -111,23 +161,42 @@ do_install() { | |||
| 111 | if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then | 161 | if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then |
| 112 | install -D -m 0644 "${UNPACKDIR}/k3s.service" "${D}${systemd_system_unitdir}/k3s.service" | 162 | install -D -m 0644 "${UNPACKDIR}/k3s.service" "${D}${systemd_system_unitdir}/k3s.service" |
| 113 | install -D -m 0644 "${UNPACKDIR}/k3s-agent.service" "${D}${systemd_system_unitdir}/k3s-agent.service" | 163 | install -D -m 0644 "${UNPACKDIR}/k3s-agent.service" "${D}${systemd_system_unitdir}/k3s-agent.service" |
| 164 | install -D -m 0644 "${UNPACKDIR}/k3s-role-setup.service" "${D}${systemd_system_unitdir}/k3s-role-setup.service" | ||
| 114 | sed -i "s#\(Exec\)\(.*\)=\(.*\)\(k3s\)#\1\2=${BIN_PREFIX}/bin/\4#g" "${D}${systemd_system_unitdir}/k3s.service" "${D}${systemd_system_unitdir}/k3s-agent.service" | 165 | sed -i "s#\(Exec\)\(.*\)=\(.*\)\(k3s\)#\1\2=${BIN_PREFIX}/bin/\4#g" "${D}${systemd_system_unitdir}/k3s.service" "${D}${systemd_system_unitdir}/k3s-agent.service" |
| 115 | install -m 755 "${UNPACKDIR}/k3s-agent" "${D}${BIN_PREFIX}/bin" | 166 | install -m 755 "${UNPACKDIR}/k3s-agent" "${D}${BIN_PREFIX}/bin" |
| 167 | install -m 755 "${UNPACKDIR}/k3s-role-setup.sh" "${D}${BIN_PREFIX}/bin/k3s-role-setup.sh" | ||
| 168 | install -m 755 "${UNPACKDIR}/k3s-get-token.sh" "${D}${BIN_PREFIX}/bin/k3s-get-token" | ||
| 116 | fi | 169 | fi |
| 117 | 170 | ||
| 118 | mkdir -p ${D}${datadir}/k3s/ | 171 | mkdir -p ${D}${datadir}/k3s/ |
| 119 | install -m 0755 ${S}/src/import/contrib/util/check-config.sh ${D}${datadir}/k3s/ | 172 | install -m 0755 ${S}/src/import/contrib/util/check-config.sh ${D}${datadir}/k3s/ |
| 173 | |||
| 174 | # Create server manifests directory — k3s's deploy.Stage() writes | ||
| 175 | # processed manifests here at runtime (template variables substituted) | ||
| 176 | install -d "${D}/var/lib/rancher/k3s/server/manifests" | ||
| 177 | |||
| 178 | # Install default k3s config — disable traefik if not in PACKAGECONFIG | ||
| 179 | install -d "${D}${sysconfdir}/rancher/k3s" | ||
| 180 | echo "# k3s server configuration (generated by recipe)" \ | ||
| 181 | > "${D}${sysconfdir}/rancher/k3s/config.yaml" | ||
| 182 | echo "disable-cloud-controller: true" \ | ||
| 183 | >> "${D}${sysconfdir}/rancher/k3s/config.yaml" | ||
| 184 | if ! ${@bb.utils.contains('PACKAGECONFIG', 'traefik', 'true', 'false', d)}; then | ||
| 185 | echo "disable:" >> "${D}${sysconfdir}/rancher/k3s/config.yaml" | ||
| 186 | echo " - traefik" >> "${D}${sysconfdir}/rancher/k3s/config.yaml" | ||
| 187 | fi | ||
| 120 | } | 188 | } |
| 121 | 189 | ||
| 122 | PACKAGES =+ "${PN}-server ${PN}-agent" | 190 | PACKAGES =+ "${PN}-server ${PN}-agent" |
| 123 | 191 | ||
| 124 | SYSTEMD_PACKAGES = "${@bb.utils.contains('DISTRO_FEATURES','systemd','${PN}-server ${PN}-agent','',d)}" | 192 | SYSTEMD_PACKAGES = "${@bb.utils.contains('DISTRO_FEATURES','systemd','${PN}-server ${PN}-agent ${PN}','',d)}" |
| 125 | SYSTEMD_SERVICE:${PN}-server = "${@bb.utils.contains('DISTRO_FEATURES','systemd','k3s.service','',d)}" | 193 | SYSTEMD_SERVICE:${PN}-server = "${@bb.utils.contains('DISTRO_FEATURES','systemd','k3s.service','',d)}" |
| 126 | SYSTEMD_SERVICE:${PN}-agent = "${@bb.utils.contains('DISTRO_FEATURES','systemd','k3s-agent.service','',d)}" | 194 | SYSTEMD_SERVICE:${PN}-agent = "${@bb.utils.contains('DISTRO_FEATURES','systemd','k3s-agent.service','',d)}" |
| 195 | SYSTEMD_SERVICE:${PN} = "${@bb.utils.contains('DISTRO_FEATURES','systemd','k3s-role-setup.service','',d)}" | ||
| 127 | SYSTEMD_AUTO_ENABLE:${PN}-agent = "disable" | 196 | SYSTEMD_AUTO_ENABLE:${PN}-agent = "disable" |
| 128 | 197 | ||
| 129 | FILES:${PN}-agent = "${BIN_PREFIX}/bin/k3s-agent" | 198 | FILES:${PN}-agent = "${BIN_PREFIX}/bin/k3s-agent" |
| 130 | FILES:${PN} += "${BIN_PREFIX}/bin/*" | 199 | FILES:${PN} += "${BIN_PREFIX}/bin/* /var/lib/rancher/k3s/server/manifests ${sysconfdir}/rancher/k3s" |
| 131 | 200 | ||
| 132 | RDEPENDS:${PN} = "k3s-cni conntrack-tools coreutils findutils iptables iproute2 ipset virtual-containerd" | 201 | RDEPENDS:${PN} = "k3s-cni conntrack-tools coreutils findutils iptables iproute2 ipset virtual-containerd" |
| 133 | RDEPENDS:${PN}-server = "${PN}" | 202 | RDEPENDS:${PN}-server = "${PN}" |
