Overall: helper container images should always use same tag as CLI or fallback to latest

pull/287/head
iwilltry42 4 years ago
parent 724b7746ee
commit eac293a263
No known key found for this signature in database
GPG Key ID: 7BA57AD1CFF16110
  1. 3
      pkg/cluster/cluster.go
  2. 3
      pkg/tools/tools.go
  3. 8
      pkg/types/types.go
  4. 2
      tools/Makefile
  5. 12
      version/version.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),

@ -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,

@ -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"

@ -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

@ -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 {

Loading…
Cancel
Save