Skip to content

Commit

Permalink
Always use latest kubectl version (#862)
Browse files Browse the repository at this point in the history
* Always use latest kubectl version
  • Loading branch information
sgalsaleh authored Jul 26, 2024
1 parent 8519733 commit 380cf43
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 68 deletions.
34 changes: 29 additions & 5 deletions cmd/buildtools/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,48 @@ import (
)

type addonComponent struct {
getWolfiPackageName func(k0sVersion *semver.Version, upstreamVersion *semver.Version) string
getWolfiPackageVersionComparison func(k0sVersion *semver.Version, upstreamVersion *semver.Version) string
getWolfiPackageName func(opts addonComponentOptions) string
getWolfiPackageVersionComparison func(opts addonComponentOptions) string
upstreamVersionInputOverride string
}

func (c *addonComponent) getPackageNameAndVersion(wolfiAPKIndex []byte, k0sVersion *semver.Version, upstreamVersion string) (string, string, error) {
type addonComponentOptions struct {
k0sVersion *semver.Version
upstreamVersion *semver.Version
latestK8sVersion *semver.Version
}

func (c *addonComponent) getPackageNameAndVersion(wolfiAPKIndex []byte, upstreamVersion string) (string, string, error) {
packageName := ""
if c.getWolfiPackageName == nil {
return packageName, upstreamVersion, nil
}

k0sVersion, err := getK0sVersion()
if err != nil {
return "", "", fmt.Errorf("get k0s version: %w", err)
}

latestK8sVersion, err := GetLatestKubernetesVersion()
if err != nil {
return "", "", fmt.Errorf("get latest k8s version: %w", err)
}

if c.getWolfiPackageName != nil {
packageName = c.getWolfiPackageName(k0sVersion, semver.MustParse(upstreamVersion))
packageName = c.getWolfiPackageName(addonComponentOptions{
k0sVersion: k0sVersion,
upstreamVersion: semver.MustParse(upstreamVersion),
latestK8sVersion: latestK8sVersion,
})
}

comparison := latestPatchComparison(semver.MustParse(upstreamVersion))
if c.getWolfiPackageVersionComparison != nil {
comparison = c.getWolfiPackageVersionComparison(k0sVersion, semver.MustParse(upstreamVersion))
comparison = c.getWolfiPackageVersionComparison(addonComponentOptions{
k0sVersion: k0sVersion,
upstreamVersion: semver.MustParse(upstreamVersion),
latestK8sVersion: latestK8sVersion,
})
}
constraints, err := semver.NewConstraint(comparison)
if err != nil {
Expand Down
33 changes: 14 additions & 19 deletions cmd/buildtools/k0s.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,46 +26,46 @@ var k0sImageComponents = map[string]string{

var k0sComponents = map[string]addonComponent{
"coredns": {
getWolfiPackageName: func(k0sVersion *semver.Version, upstreamVersion *semver.Version) string {
getWolfiPackageName: func(opts addonComponentOptions) string {
return "coredns"
},
},
"calico-node": {
getWolfiPackageName: func(k0sVersion *semver.Version, upstreamVersion *semver.Version) string {
getWolfiPackageName: func(opts addonComponentOptions) string {
return "calico-node"
},
},
"calico-cni": {
getWolfiPackageName: func(k0sVersion *semver.Version, upstreamVersion *semver.Version) string {
getWolfiPackageName: func(opts addonComponentOptions) string {
return "calico-cni"
},
},
"calico-kube-controllers": {
getWolfiPackageName: func(k0sVersion *semver.Version, upstreamVersion *semver.Version) string {
getWolfiPackageName: func(opts addonComponentOptions) string {
return "calico-kube-controllers"
},
},
"metrics-server": {
getWolfiPackageName: func(k0sVersion *semver.Version, upstreamVersion *semver.Version) string {
getWolfiPackageName: func(opts addonComponentOptions) string {
return "metrics-server"
},
},
"kube-proxy": {
getWolfiPackageName: func(k0sVersion *semver.Version, upstreamVersion *semver.Version) string {
return fmt.Sprintf("kube-proxy-%d.%d-default", upstreamVersion.Major(), upstreamVersion.Minor())
getWolfiPackageName: func(opts addonComponentOptions) string {
return fmt.Sprintf("kube-proxy-%d.%d-default", opts.upstreamVersion.Major(), opts.upstreamVersion.Minor())
},
},
"envoy-distroless": {
getWolfiPackageName: func(k0sVersion *semver.Version, upstreamVersion *semver.Version) string {
return fmt.Sprintf("envoy-%d.%d", upstreamVersion.Major(), upstreamVersion.Minor())
getWolfiPackageName: func(opts addonComponentOptions) string {
return fmt.Sprintf("envoy-%d.%d", opts.upstreamVersion.Major(), opts.upstreamVersion.Minor())
},
},
"pause": {
getWolfiPackageName: func(k0sVersion *semver.Version, upstreamVersion *semver.Version) string {
return fmt.Sprintf("kubernetes-pause-%d.%d", upstreamVersion.Major(), upstreamVersion.Minor())
getWolfiPackageName: func(opts addonComponentOptions) string {
return fmt.Sprintf("kubernetes-pause-%d.%d", opts.upstreamVersion.Major(), opts.upstreamVersion.Minor())
},
getWolfiPackageVersionComparison: func(k0sVersion *semver.Version, upstreamVersion *semver.Version) string {
return latestPatchComparison(k0sVersion) // pause package version follows the k8s version
getWolfiPackageVersionComparison: func(opts addonComponentOptions) string {
return latestPatchComparison(opts.k0sVersion) // pause package version follows the k8s version
},
},
}
Expand All @@ -83,11 +83,6 @@ var updateK0sImagesCommand = &cli.Command{

k0sImages := config.ListK0sImages(k0sconfig.DefaultClusterConfig())

k0sVersion, err := getK0sVersion()
if err != nil {
return fmt.Errorf("failed to get k0s version: %w", err)
}

if err := ApkoLogin(); err != nil {
return fmt.Errorf("failed to apko login: %w", err)
}
Expand Down Expand Up @@ -116,7 +111,7 @@ var updateK0sImagesCommand = &cli.Command{
return fmt.Errorf("no component found for component name %s", componentName)
}

packageName, packageVersion, err := component.getPackageNameAndVersion(wolfiAPKIndex, k0sVersion, upstreamVersion)
packageName, packageVersion, err := component.getPackageNameAndVersion(wolfiAPKIndex, upstreamVersion)
if err != nil {
return fmt.Errorf("failed to get package name and version for %s: %w", componentName, err)
}
Expand Down
19 changes: 7 additions & 12 deletions cmd/buildtools/openebs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"
"strings"

"github.com/Masterminds/semver/v3"
"github.com/replicatedhq/embedded-cluster/pkg/addons/openebs"
"github.com/replicatedhq/embedded-cluster/pkg/release"
"github.com/sirupsen/logrus"
Expand All @@ -27,7 +26,7 @@ var openebsRepo = &repo.Entry{

var openebsComponents = map[string]addonComponent{
"openebs-provisioner-localpv": {
getWolfiPackageName: func(k0sVersion *semver.Version, upstreamVersion *semver.Version) string {
getWolfiPackageName: func(opts addonComponentOptions) string {
// package name is not the same as the component name
return "dynamic-localpv-provisioner"
},
Expand All @@ -37,11 +36,12 @@ var openebsComponents = map[string]addonComponent{
upstreamVersionInputOverride: "INPUT_OPENEBS_VERSION",
},
"kubectl": {
getWolfiPackageName: func(k0sVersion *semver.Version, upstreamVersion *semver.Version) string {
return fmt.Sprintf("kubectl-%d.%d-default", k0sVersion.Major(), k0sVersion.Minor())
getWolfiPackageName: func(opts addonComponentOptions) string {
return fmt.Sprintf("kubectl-%d.%d-default", opts.latestK8sVersion.Major(), opts.latestK8sVersion.Minor())
},
getWolfiPackageVersionComparison: func(k0sVersion *semver.Version, upstreamVersion *semver.Version) string {
return latestPatchComparison(k0sVersion) // since we're using the k0s version to identify the package
getWolfiPackageVersionComparison: func(opts addonComponentOptions) string {
// use latest available patch in wolfi as latest upstream might not be available yet
return latestPatchComparison(opts.latestK8sVersion)
},
upstreamVersionInputOverride: "INPUT_KUBECTL_VERSION",
},
Expand Down Expand Up @@ -121,11 +121,6 @@ func updateOpenEBSAddonImages(ctx context.Context, chartURL string, chartVersion
Images: make(map[string]string),
}

k0sVersion, err := getK0sVersion()
if err != nil {
return fmt.Errorf("failed to get k0s version: %w", err)
}

logrus.Infof("fetching wolfi apk index")
wolfiAPKIndex, err := GetWolfiAPKIndex()
if err != nil {
Expand Down Expand Up @@ -174,7 +169,7 @@ func updateOpenEBSAddonImages(ctx context.Context, chartURL string, chartVersion
}
}

packageName, packageVersion, err := component.getPackageNameAndVersion(wolfiAPKIndex, k0sVersion, upstreamVersion)
packageName, packageVersion, err := component.getPackageNameAndVersion(wolfiAPKIndex, upstreamVersion)
if err != nil {
return fmt.Errorf("failed to get package name and version for %s: %w", componentName, err)
}
Expand Down
10 changes: 2 additions & 8 deletions cmd/buildtools/seaweedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"
"strings"

"github.com/Masterminds/semver/v3"
"github.com/replicatedhq/embedded-cluster/pkg/addons/seaweedfs"
"github.com/replicatedhq/embedded-cluster/pkg/release"
"github.com/sirupsen/logrus"
Expand All @@ -20,7 +19,7 @@ var seaweedfsImageComponents = map[string]string{

var seaweedfsComponents = map[string]addonComponent{
"seaweedfs": {
getWolfiPackageName: func(k0sVersion *semver.Version, upstreamVersion *semver.Version) string {
getWolfiPackageName: func(opts addonComponentOptions) string {
return "seaweedfs"
},
upstreamVersionInputOverride: "INPUT_SEAWEEDFS_VERSION",
Expand Down Expand Up @@ -106,11 +105,6 @@ func updateSeaweedFSAddonImages(ctx context.Context, chartURL string, chartVersi
Images: make(map[string]string),
}

k0sVersion, err := getK0sVersion()
if err != nil {
return fmt.Errorf("failed to get k0s version: %w", err)
}

logrus.Infof("fetching wolfi apk index")
wolfiAPKIndex, err := GetWolfiAPKIndex()
if err != nil {
Expand Down Expand Up @@ -156,7 +150,7 @@ func updateSeaweedFSAddonImages(ctx context.Context, chartURL string, chartVersi
}
}

packageName, packageVersion, err := component.getPackageNameAndVersion(wolfiAPKIndex, k0sVersion, upstreamVersion)
packageName, packageVersion, err := component.getPackageNameAndVersion(wolfiAPKIndex, upstreamVersion)
if err != nil {
return fmt.Errorf("failed to get package name and version for %s: %w", componentName, err)
}
Expand Down
14 changes: 14 additions & 0 deletions cmd/buildtools/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,3 +607,17 @@ func NewHelm() (*helm.Helm, error) {
K0sVersion: sv.Original(),
})
}

func GetLatestKubernetesVersion() (*semver.Version, error) {
resp, err := http.Get("https://dl.k8s.io/release/stable.txt")
if err != nil {
return nil, fmt.Errorf("http get: %w", err)
}
defer resp.Body.Close()

scanner := bufio.NewScanner(resp.Body)
if !scanner.Scan() {
return nil, fmt.Errorf("no content in stable.txt")
}
return semver.NewVersion(scanner.Text())
}
22 changes: 9 additions & 13 deletions cmd/buildtools/velero.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,30 @@ var veleroImageComponents = map[string]string{

var veleroComponents = map[string]addonComponent{
"velero": {
getWolfiPackageName: func(k0sVersion *semver.Version, upstreamVersion *semver.Version) string {
getWolfiPackageName: func(opts addonComponentOptions) string {
return "velero"
},
upstreamVersionInputOverride: "INPUT_VELERO_VERSION",
},
"velero-plugin-for-aws": {
getWolfiPackageName: func(k0sVersion *semver.Version, upstreamVersion *semver.Version) string {
getWolfiPackageName: func(opts addonComponentOptions) string {
return "velero-plugin-for-aws"
},
upstreamVersionInputOverride: "INPUT_VELERO_AWS_PLUGIN_VERSION",
},
"velero-restore-helper": {
getWolfiPackageName: func(k0sVersion *semver.Version, upstreamVersion *semver.Version) string {
getWolfiPackageName: func(opts addonComponentOptions) string {
return "velero-restore-helper"
},
upstreamVersionInputOverride: "INPUT_VELERO_VERSION",
},
"kubectl": {
getWolfiPackageName: func(k0sVersion *semver.Version, upstreamVersion *semver.Version) string {
return fmt.Sprintf("kubectl-%d.%d-default", k0sVersion.Major(), k0sVersion.Minor())
getWolfiPackageName: func(opts addonComponentOptions) string {
return fmt.Sprintf("kubectl-%d.%d-default", opts.latestK8sVersion.Major(), opts.latestK8sVersion.Minor())
},
getWolfiPackageVersionComparison: func(k0sVersion *semver.Version, upstreamVersion *semver.Version) string {
return latestPatchComparison(k0sVersion) // since we're using the k0s version to identify the package
getWolfiPackageVersionComparison: func(opts addonComponentOptions) string {
// use latest available patch in wolfi as latest upstream might not be available yet
return latestPatchComparison(opts.latestK8sVersion)
},
upstreamVersionInputOverride: "INPUT_KUBECTL_VERSION",
},
Expand Down Expand Up @@ -200,11 +201,6 @@ func updateVeleroAddonImages(ctx context.Context, chartURL string, chartVersion
Images: make(map[string]string),
}

k0sVersion, err := getK0sVersion()
if err != nil {
return fmt.Errorf("failed to get k0s version: %w", err)
}

logrus.Infof("fetching wolfi apk index")
wolfiAPKIndex, err := GetWolfiAPKIndex()
if err != nil {
Expand Down Expand Up @@ -254,7 +250,7 @@ func updateVeleroAddonImages(ctx context.Context, chartURL string, chartVersion
}
}

packageName, packageVersion, err := component.getPackageNameAndVersion(wolfiAPKIndex, k0sVersion, upstreamVersion)
packageName, packageVersion, err := component.getPackageNameAndVersion(wolfiAPKIndex, upstreamVersion)
if err != nil {
return fmt.Errorf("failed to get package name and version for %s: %w", componentName, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/addons/openebs/static/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
version: 4.1.0
location: oci://proxy.replicated.com/anonymous/registry.replicated.com/ec-charts/openebs
images:
kubectl: 1.29.5-r0@sha256:b02581e79105d18e18ab29668838c7ba6040a5c0c096cddbc9b110e9ba24843d
kubectl: 1.30.3-r0@sha256:1eae04515815de86ce041229dfd38574930c8ba4ff2d3b1944ee43ce8e3ea757
openebs-linux-utils: 4.1.0@sha256:8aad274b0c762113d39726a3012330554f6a601c471893276ffe3512bfc65368
openebs-provisioner-localpv: 4.1.0-r0@sha256:4952e2682529d737ee2ad09dc13debcab152daf04ddf9ab636c753a66f2799fd
2 changes: 1 addition & 1 deletion pkg/addons/openebs/static/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ preUpgradeHook:
image:
registry: proxy.replicated.com/anonymous
repo: replicated/ec-kubectl
tag: '1.29.5-r0@sha256:b02581e79105d18e18ab29668838c7ba6040a5c0c096cddbc9b110e9ba24843d'
tag: '1.30.3-r0@sha256:1eae04515815de86ce041229dfd38574930c8ba4ff2d3b1944ee43ce8e3ea757'
zfs-localpv:
enabled: false
8 changes: 4 additions & 4 deletions pkg/addons/velero/static/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
version: 6.7.0
location: oci://proxy.replicated.com/anonymous/registry.replicated.com/ec-charts/velero
images:
kubectl: 1.29.5-r0@sha256:b02581e79105d18e18ab29668838c7ba6040a5c0c096cddbc9b110e9ba24843d
velero: 1.13.2@sha256:f5609c28a5e1984e7b07a93c871a19ff3fb3d168663d3e459d41f12ef629925b
velero-plugin-for-aws: 1.9.2@sha256:f2b81a1c1fcbf4e1a11b87ac0484c87e8ea7dd3facd76aa038f99cc4e1b1bcd7
velero-restore-helper: 1.13.2@sha256:dac290e821ee7fa698bdce4d1e5c98ea8e36940cfca9b21cb0d93df67864d055
kubectl: 1.30.3-r0@sha256:1eae04515815de86ce041229dfd38574930c8ba4ff2d3b1944ee43ce8e3ea757
velero: 1.13.2-r6@sha256:9914d4b9d25cbaa3bff3433132056f47d13f4c3edc87117d907a84c764be3c34
velero-plugin-for-aws: 1.9.2-r5@sha256:9f970dbdacc4317f4063bb46bc81ae8213d46e5c4c14ecc5f01625b7c46e9b8b
velero-restore-helper: 1.13.2-r6@sha256:e7886e1a6e04a319466c2982334c79da8ea9ebfef2f5b36dc4338cf558e02ccb
8 changes: 4 additions & 4 deletions pkg/addons/velero/static/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ credentials:
deployNodeAgent: true
image:
repository: proxy.replicated.com/anonymous/replicated/ec-velero
tag: '1.13.2@sha256:f5609c28a5e1984e7b07a93c871a19ff3fb3d168663d3e459d41f12ef629925b'
tag: '1.13.2-r6@sha256:9914d4b9d25cbaa3bff3433132056f47d13f4c3edc87117d907a84c764be3c34'
initContainers:
- image: 'proxy.replicated.com/anonymous/replicated/ec-velero-plugin-for-aws:1.9.2@sha256:f2b81a1c1fcbf4e1a11b87ac0484c87e8ea7dd3facd76aa038f99cc4e1b1bcd7'
- image: 'proxy.replicated.com/anonymous/replicated/ec-velero-plugin-for-aws:1.9.2-r5@sha256:9f970dbdacc4317f4063bb46bc81ae8213d46e5c4c14ecc5f01625b7c46e9b8b'
imagePullPolicy: IfNotPresent
name: velero-plugin-for-aws
volumeMounts:
Expand All @@ -28,14 +28,14 @@ initContainers:
kubectl:
image:
repository: proxy.replicated.com/anonymous/replicated/ec-kubectl
tag: '1.29.5-r0@sha256:b02581e79105d18e18ab29668838c7ba6040a5c0c096cddbc9b110e9ba24843d'
tag: '1.30.3-r0@sha256:1eae04515815de86ce041229dfd38574930c8ba4ff2d3b1944ee43ce8e3ea757'
configMaps:
fs-restore-action-config:
labels:
velero.io/plugin-config: ""
velero.io/pod-volume-restore: RestoreItemAction
data:
image: 'proxy.replicated.com/anonymous/replicated/ec-velero-restore-helper:1.13.2@sha256:dac290e821ee7fa698bdce4d1e5c98ea8e36940cfca9b21cb0d93df67864d055'
image: 'proxy.replicated.com/anonymous/replicated/ec-velero-restore-helper:1.13.2-r6@sha256:e7886e1a6e04a319466c2982334c79da8ea9ebfef2f5b36dc4338cf558e02ccb'
nodeAgent:
podVolumePath: /var/lib/k0s/kubelet/pods
snapshotsEnabled: false
2 changes: 1 addition & 1 deletion pkg/config/static/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ images:
calico-node: 3.26.4-r2@sha256:c0eb53aa2ccd366dea99845f18a24fe51cce67863fc35ffbdda88d383d9ff6ae
coredns: 1.11.3-r3@sha256:e8aa52ab1af3ed44f664ea79cba6099fea7fc8a3a4af3601a08244c6d5b34de6
envoy-distroless: 1.29.6-r0@sha256:f38f813f786c17354f1d7bf91758068f3328fedede1ac84864dde8f2c635b7a5
kube-proxy: 1.29.5-r0@sha256:ef5aeb0610089a8216a138b92f3701f61aac6894861d81a31d23c6c4a6e31526
kube-proxy: 1.29.5-r0@sha256:c2b6db991de9bf3799996d1e28c77cdda3673f9651b4da58ef9bad5c9e527ccd
metrics-server: 0.6.4-r9@sha256:58516a4f46ba645f4e0f367af41df6506951c3cd7903efd5f4ae3e17fd753e4a
pause: 1.29.5-r0@sha256:3fb2eefc6eb8a9c33ffc416cdb28e353a51587efe10fc3427eddb76fd132e110

0 comments on commit 380cf43

Please sign in to comment.