fix: respect the k3s master node version when adding a new worker to the k3s cluster
Previously, it was possible to have a kubernetes version mismatch on new worker nodes if a newer version of kubernetes was released prior to upgrading the master nodes to that version. This can sometimes cause cluster instability. This change fetches the lowest node version associated with a master node and then uses that to install k3s on the worker node.
This commit is contained in:
2 files changed
+93
-1
No files matched your search
@@ -14,6 +14,7 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/Masterminds/semver/v3"
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/fatih/color"
|
||||
"github.com/go-openapi/jsonpointer"
|
||||
@@ -139,6 +140,42 @@ func (k KubernetesClient) Ping() error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (k KubernetesClient) GetLowestNodeVersion(ctx context.Context, input ListNodesInput) (string, error) {
|
||||
nodes, err := k.ListNodes(ctx, input)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to list nodes: %w", err)
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return "", fmt.Errorf("no nodes found in the cluster")
|
||||
}
|
||||
|
||||
var lowestVersion *semver.Version
|
||||
for _, node := range nodes {
|
||||
kubeletVersion := node.Status.NodeInfo.KubeletVersion
|
||||
if kubeletVersion == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
versionStr := strings.TrimPrefix(kubeletVersion, "v")
|
||||
version, err := semver.NewVersion(versionStr)
|
||||
if err != nil {
|
||||
common.LogWarn(fmt.Sprintf("Failed to parse version %s for node %s: %v", kubeletVersion, node.Name, err))
|
||||
continue
|
||||
}
|
||||
|
||||
if lowestVersion == nil || version.LessThan(lowestVersion) {
|
||||
lowestVersion = version
|
||||
}
|
||||
}
|
||||
|
||||
if lowestVersion == nil {
|
||||
return "", fmt.Errorf("no valid kubelet versions found")
|
||||
}
|
||||
|
||||
return "v" + lowestVersion.String(), nil
|
||||
}
|
||||
|
||||
// AnnotateNodeInput contains all the information needed to annotates a Kubernetes node
|
||||
type AnnotateNodeInput struct {
|
||||
// Name is the Kubernetes node name
|
||||
|
||||
Reference in new issue
Block a user