From 70295e35115f8f66c77c59f503232a5b13f48c23 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Tue, 24 Sep 2024 17:35:55 +0200 Subject: [PATCH] build: Generate image list files for distro and version --- .goreleaser.yaml | 1 + Justfile | 14 ++++++ hack/assets/main.go | 3 +- hack/assets/separate/main.go | 86 ++++++++++++++++++++++++++++++++++++ pkg/constants/coredns.go | 3 ++ 5 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 hack/assets/separate/main.go diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 579dab95f4..35680a277a 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -9,6 +9,7 @@ before: - just clean-release - just copy-assets - just generate-vcluster-images {{ .Version }} + - just generate-matrix-specific-images source: format: tar.gz diff --git a/Justfile b/Justfile index 423c30d2f0..74129cbebd 100644 --- a/Justfile +++ b/Justfile @@ -70,6 +70,20 @@ copy-assets: generate-vcluster-images version="0.0.0": go run -mod vendor ./hack/assets/main.go {{ version }} > ./release/vcluster-images.txt +# Generate versioned vCluster image files for multiple versions and distros +[private] +generate-matrix-specific-images version="0.0.0": + #!/usr/bin/env bash + + distros=("k8s" "k3s" "k0s") + versions=("1.30" "1.29" "1.28") + + for distro in "${distros[@]}"; do + for version in "${versions[@]}"; do + go run -mod vendor ./hack/assets/separate/main.go -kubernetes-distro=$distro -kubernetes-version=$version -vcluster-version={{ version }} > ./release/vcluster-images-$distro-$version.txt + done + done + # Generate the CLI docs generate-cli-docs: go run -mod vendor -tags pro ./hack/docs/main.go diff --git a/hack/assets/main.go b/hack/assets/main.go index 653f783ceb..c3e81cf9ea 100644 --- a/hack/assets/main.go +++ b/hack/assets/main.go @@ -14,8 +14,9 @@ import ( func main() { images := []string{} - // loft + // vCluster images = append(images, "ghcr.io/loft-sh/vcluster:"+cleanTag(os.Args[1])) + images = append(images, "ghcr.io/loft-sh/vcluster-pro:"+cleanTag(os.Args[1])) images = append(images, config.DefaultHostsRewriteImage) // loop over k3s versions diff --git a/hack/assets/separate/main.go b/hack/assets/separate/main.go new file mode 100644 index 0000000000..02e1b031ee --- /dev/null +++ b/hack/assets/separate/main.go @@ -0,0 +1,86 @@ +package main + +import ( + "flag" + "fmt" + "slices" + "strings" + + vclusterconfig "github.com/loft-sh/vcluster/config" + "github.com/loft-sh/vcluster/pkg/config" + "github.com/loft-sh/vcluster/pkg/constants" + "github.com/loft-sh/vcluster/pkg/coredns" +) + +var ( + kubernetesDistro = flag.String("kubernetes-distro", "", "The Kubernetes distro to include in the list") + kubernetesVersion = flag.String("kubernetes-version", "", "The Kubernetes version to include in the image list") + vClusterVersion = flag.String("vcluster-version", "", "The vCluster version to include in the image list") +) + +func main() { + flag.Parse() + + assert(*kubernetesDistro != "", "-kubernetes-distro flag has to be set") + assert(*kubernetesVersion != "", "-kubernetes-version flag has to be set") + assert(*vClusterVersion != "", "-vcluster-version flag has to be set") + + images := []string{} + + // vCluster + assert(cleanTag(*vClusterVersion) != "", "vCluster version does not contain a numnber") + images = append(images, "ghcr.io/loft-sh/vcluster-pro:"+cleanTag(*vClusterVersion)) + images = append(images, "ghcr.io/loft-sh/vcluster-pro-fips:"+cleanTag(*vClusterVersion)) + images = append(images, config.DefaultHostsRewriteImage) + + var versionMap map[string]string + switch *kubernetesDistro { + case "k8s": + versionMap = vclusterconfig.K8SAPIVersionMap + case "k3s": + versionMap = vclusterconfig.K3SVersionMap + case "k0s": + versionMap = vclusterconfig.K0SVersionMap + } + assert(versionMap != nil, "no version map found for kubernetes distro", *kubernetesDistro) + + // loop over version map + kubernetesImage := versionMap[*kubernetesVersion] + assert(len(kubernetesImage) > 0, "could not find kubernetes version for distro", *kubernetesDistro, *kubernetesVersion) + images = append(images, kubernetesImage) + + if *kubernetesDistro == "k8s" { + controllerManagerImage := vclusterconfig.K8SControllerVersionMap[*kubernetesVersion] + assert(len(controllerManagerImage) > 0, "could not find controller manager image", *kubernetesVersion) + images = append(images, controllerManagerImage) + + etcdImage := vclusterconfig.K8SEtcdVersionMap[*kubernetesVersion] + assert(len(etcdImage) > 0, "could not find etcd image", *kubernetesVersion) + images = append(images, etcdImage) + } + + // loop over core-dns versions + coreDNSImage := constants.CoreDNSVersionMap[*kubernetesVersion] + assert(len(coreDNSImage) > 0, "could not find CoreDNS image", *kubernetesVersion) + images = append(images, coreDNSImage) + + if !slices.Contains(images, coredns.DefaultImage) { + images = append(images, coredns.DefaultImage) + } + + fmt.Print(strings.Join(images, "\n") + "\n") +} + +func cleanTag(tag string) string { + if len(tag) > 0 && tag[0] == 'v' { + return tag[1:] + } + + return tag +} + +func assert(condition bool, message ...string) { + if !condition { + panic(fmt.Sprintf("assert failed: %v", strings.Join(message, ", "))) + } +} diff --git a/pkg/constants/coredns.go b/pkg/constants/coredns.go index 610ef53ce1..9341772fa6 100644 --- a/pkg/constants/coredns.go +++ b/pkg/constants/coredns.go @@ -1,6 +1,9 @@ package constants var CoreDNSVersionMap = map[string]string{ + "1.30": "coredns/coredns:1.11.3", + "1.29": "coredns/coredns:1.11.1", + "1.28": "coredns/coredns:1.10.1", "1.27": "coredns/coredns:1.10.1", "1.26": "coredns/coredns:1.9.3", "1.25": "coredns/coredns:1.9.3",