Skip to content

Commit

Permalink
fix(kubelet-config): adding versioned kubelet config
Browse files Browse the repository at this point in the history
  • Loading branch information
jds9090 authored and prometherion committed Jul 4, 2023
1 parent 8f57ff4 commit 4413061
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion internal/kubeadm/uploadconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
package kubeadm

import (
"fmt"

"github.com/blang/semver"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
Expand All @@ -19,6 +22,14 @@ import (
"github.com/clastix/kamaji/internal/utilities"
)

const (
// kubeletConfigMapName defines base kubelet configuration ConfigMap name for kubeadm < 1.24.
kubeletConfigMapName = "kubelet-config-%d.%d"
)

// minVerUnversionedKubeletConfig defines minimum version from which kubeadm uses kubelet-config as a ConfigMap name.
var minVerUnversionedKubeletConfig = semver.MustParse("1.24.0")

func UploadKubeadmConfig(client kubernetes.Interface, config *Configuration) ([]byte, error) {
return nil, uploadconfig.UploadConfiguration(&config.InitConfiguration, client)
}
Expand All @@ -34,7 +45,10 @@ func UploadKubeletConfig(client kubernetes.Interface, config *Configuration) ([]
return nil, err
}

configMapName := kubeadmconstants.KubeletBaseConfigurationConfigMap
configMapName, err := generateKubeletConfigMapName(config.Parameters.TenantControlPlaneVersion)
if err != nil {
return nil, err
}

configMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -156,3 +170,17 @@ func createConfigMapRBACRules(client kubernetes.Interface) error {
},
})
}

func generateKubeletConfigMapName(version string) (string, error) {
parsedVersion, err := semver.ParseTolerant(version)
if err != nil {
return "", errors.Wrapf(err, "failed to parse kubernetes version %q", version)
}

majorMinor := semver.Version{Major: parsedVersion.Major, Minor: parsedVersion.Minor}
if majorMinor.GTE(minVerUnversionedKubeletConfig) {
return kubeadmconstants.KubeletBaseConfigurationConfigMap, nil
}

return fmt.Sprintf(kubeletConfigMapName, parsedVersion.Major, parsedVersion.Minor), nil
}

0 comments on commit 4413061

Please sign in to comment.