From eac293a2638a9d95e94215874b15b9661d446ef3 Mon Sep 17 00:00:00 2001 From: iwilltry42 Date: Thu, 18 Jun 2020 09:01:04 +0200 Subject: [PATCH] Overall: helper container images should always use same tag as CLI or fallback to latest --- pkg/cluster/cluster.go | 3 ++- pkg/tools/tools.go | 3 ++- pkg/types/types.go | 8 ++++---- tools/Makefile | 2 +- version/version.go | 12 ++++++++++-- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index 8d9003e9..ed587271 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -35,6 +35,7 @@ import ( "github.com/rancher/k3d/v3/pkg/types" k3d "github.com/rancher/k3d/v3/pkg/types" "github.com/rancher/k3d/v3/pkg/util" + "github.com/rancher/k3d/v3/version" log "github.com/sirupsen/logrus" "golang.org/x/sync/errgroup" ) @@ -290,7 +291,7 @@ func CreateCluster(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clus // Create LB as a modified node with loadbalancerRole lbNode := &k3d.Node{ Name: fmt.Sprintf("%s-%s-masterlb", k3d.DefaultObjectNamePrefix, cluster.Name), - Image: k3d.DefaultLBImageRepo, + Image: fmt.Sprintf("%s:%s", k3d.DefaultLBImageRepo, version.GetHelperImageVersion()), Ports: append(cluster.MasterLoadBalancer.Ports, fmt.Sprintf("%s:%s:%s/tcp", cluster.ExposeAPI.Host, cluster.ExposeAPI.Port, k3d.DefaultAPIPort)), Env: []string{ fmt.Sprintf("SERVERS=%s", servers), diff --git a/pkg/tools/tools.go b/pkg/tools/tools.go index e9774f91..dd6185af 100644 --- a/pkg/tools/tools.go +++ b/pkg/tools/tools.go @@ -33,6 +33,7 @@ import ( k3dc "github.com/rancher/k3d/v3/pkg/cluster" "github.com/rancher/k3d/v3/pkg/runtimes" k3d "github.com/rancher/k3d/v3/pkg/types" + "github.com/rancher/k3d/v3/version" log "github.com/sirupsen/logrus" ) @@ -202,7 +203,7 @@ func LoadImagesIntoCluster(ctx context.Context, runtime runtimes.Runtime, images func startToolsNode(ctx context.Context, runtime runtimes.Runtime, cluster *k3d.Cluster, network string, volumes []string) (*k3d.Node, error) { node := &k3d.Node{ Name: fmt.Sprintf("%s-%s-tools", k3d.DefaultObjectNamePrefix, cluster.Name), - Image: k3d.DefaultToolsContainerImage, + Image: fmt.Sprintf("%s:%s", k3d.DefaultToolsImageRepo, version.GetHelperImageVersion()), Role: k3d.NoRole, Volumes: volumes, Network: network, diff --git a/pkg/types/types.go b/pkg/types/types.go index 984e4e1c..871190d4 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -39,7 +39,10 @@ const DefaultClusterNameMaxLength = 32 const DefaultK3sImageRepo = "docker.io/rancher/k3s" // DefaultLBImageRepo defines the default cluster load balancer image -const DefaultLBImageRepo = "docker.io/iwilltry42/k3d-proxy:v0.0.3" +const DefaultLBImageRepo = "docker.io/rancher/k3d-proxy" + +// DefaultToolsImageRepo defines the default image used for the tools container +const DefaultToolsImageRepo = "docker.io/rancher/k3d-tools" // DefaultObjectNamePrefix defines the name prefix for every object created by k3d const DefaultObjectNamePrefix = "k3d" @@ -105,9 +108,6 @@ var DefaultNodeEnv = []string{ "K3S_KUBECONFIG_OUTPUT=/output/kubeconfig.yaml", } -// DefaultToolsContainerImage defines the default image used for the tools container -const DefaultToolsContainerImage = "docker.io/iwilltry42/k3d-tools:v0.0.3" // TODO: get version dynamically or at build time - // DefaultImageVolumeMountPath defines the mount path inside k3d nodes where we will mount the shared image volume by default const DefaultImageVolumeMountPath = "/k3d/images" diff --git a/tools/Makefile b/tools/Makefile index ada3efda..013f09d8 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -12,7 +12,7 @@ PKG := $(shell go mod vendor) TAGS := TESTS := . TESTFLAGS := -LDFLAGS := -w -s -X github.com/iwilltry42/k3d-tools/version.Version=${GIT_TAG} +LDFLAGS := -w -s -X github.com/rancher/k3d/tools/version.Version=${GIT_TAG} GOFLAGS := BINDIR := $(CURDIR)/bin BINARIES := k3d-tools diff --git a/version/version.go b/version/version.go index be1d913e..79e31643 100644 --- a/version/version.go +++ b/version/version.go @@ -30,8 +30,8 @@ import ( var Version string // K3sVersion should contain the latest version tag of k3s (hardcoded at build time) -// we're setting a default version v1.0.0, because it's stable and because the 'latest' tag is not actively maintained -var K3sVersion = "v1.0.0" // TODO: can we try to dynamically fetch the latest version at runtime and only fallback to this if it fails? +// we're setting a default version for edge cases, because the 'latest' tag is not actively maintained +var K3sVersion = "v1.18.4+k3s1" // TODO: can we try to dynamically fetch the latest version at runtime and only fallback to this if it fails? // GetVersion returns the version for cli, it gets it from "git describe --tags" or returns "dev" when doing simple go build func GetVersion() string { @@ -41,6 +41,14 @@ func GetVersion() string { return Version } +// GetHelperImageVersion returns the CLI version or 'latest' +func GetHelperImageVersion() string { + if len(Version) == 0 { + return "latest" + } + return Version +} + // GetK3sVersion returns the version string for K3s func GetK3sVersion(latest bool) string { if latest {