Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Generate image list files for distro and version #2177

Merged
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
1 change: 1 addition & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ before:
- just clean-release
- just copy-assets
- just generate-vcluster-images {{ .Version }}
- just generate-matrix-specific-images {{ .Version }}

source:
format: tar.gz
Expand Down
14 changes: 14 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion hack/assets/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
86 changes: 86 additions & 0 deletions hack/assets/separate/main.go
Original file line number Diff line number Diff line change
@@ -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, ", ")))
}
}
3 changes: 3 additions & 0 deletions pkg/constants/coredns.go
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Loading