Skip to content

Commit

Permalink
use init and join config alongside cluster for reconfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
kpiyush17 committed Dec 20, 2023
1 parent a321769 commit c7680f3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ VERSION 0.6
FROM alpine

ARG KUBEADM_VERSION=latest
ARG BASE_IMAGE=quay.io/kairos/core-opensuse-leap:v2.3.2
ARG BASE_IMAGE=quay.io/kairos/opensuse:leap-15.5-core-amd64-generic-v2.4.3
ARG IMAGE_REPOSITORY=quay.io/kairos
ARG CRICTL_VERSION=1.25.0
ARG RELEASE_VERSION=0.4.0
Expand Down
2 changes: 1 addition & 1 deletion scripts/kube-reconfigure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,6 @@ then
regenerate_etcd_manifests
upload_kubelet_config
fi
regenerate_kubelet_envs
regenerate_kubelet_config
regenerate_kubelet_envs
restart_kubelet
9 changes: 5 additions & 4 deletions stages/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func GetInitYipStages(cluster clusterplugin.Cluster, initCfg kubeadmapiv3.InitCo
getKubeadmInitStage(cluster, clusterCfg),
getKubeadmPostInitStage(),
getKubeadmInitUpgradeStage(cluster, clusterCfg),
getKubeadmInitCreateClusterConfigStage(clusterCfg),
getKubeadmInitCreateClusterConfigStage(clusterCfg, initCfg),
getKubeadmInitCreateKubeletConfigStage(kubeletCfg),
getKubeadmInitReconfigureStage(cluster, clusterCfg, initCfg),
}
Expand Down Expand Up @@ -110,14 +110,14 @@ func getKubeadmInitUpgradeStage(cluster clusterplugin.Cluster, clusterCfg kubead
return upgradeStage
}

func getKubeadmInitCreateClusterConfigStage(clusterCfg kubeadmapiv3.ClusterConfiguration) yip.Stage {
func getKubeadmInitCreateClusterConfigStage(clusterCfg kubeadmapiv3.ClusterConfiguration, initCfg kubeadmapiv3.InitConfiguration) yip.Stage {
return yip.Stage{
Name: "Generate Cluster Config File",
Files: []yip.File{
{
Path: filepath.Join(configurationPath, "cluster-config.yaml"),
Permissions: 0640,
Content: getUpdatedClusterConfig(clusterCfg),
Content: getUpdatedInitClusterConfig(clusterCfg, initCfg),
},
},
}
Expand Down Expand Up @@ -200,11 +200,12 @@ func getInitNodeConfiguration(cluster clusterplugin.Cluster, initCfg kubeadmapiv
return out.String()
}

func getUpdatedClusterConfig(clusterCfg kubeadmapiv3.ClusterConfiguration) string {
func getUpdatedInitClusterConfig(clusterCfg kubeadmapiv3.ClusterConfiguration, initCfg kubeadmapiv3.InitConfiguration) string {
initPrintr := printers.NewTypeSetter(scheme).ToPrinter(&printers.YAMLPrinter{})

out := bytes.NewBuffer([]byte{})
_ = initPrintr.PrintObj(&clusterCfg, out)
_ = initPrintr.PrintObj(&initCfg, out)

return out.String()
}
Expand Down
16 changes: 13 additions & 3 deletions stages/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func GetJoinYipStages(cluster clusterplugin.Cluster, clusterCfg kubeadmapiv3.Clu
}

if cluster.Role != clusterplugin.RoleWorker {
joinStg = append(joinStg, getKubeadmJoinCreateClusterConfigStage(clusterCfg), getKubeadmJoinCreateKubeletConfigStage(kubeletCfg))
joinStg = append(joinStg, getKubeadmJoinCreateClusterConfigStage(clusterCfg, joinCfg), getKubeadmJoinCreateKubeletConfigStage(kubeletCfg))
}

return append(joinStg, getKubeadmJoinReconfigureStage(cluster, clusterCfg, joinCfg))
Expand Down Expand Up @@ -123,14 +123,14 @@ func getKubeadmJoinUpgradeStage(cluster clusterplugin.Cluster, clusterCfg kubead
return upgradeStage
}

func getKubeadmJoinCreateClusterConfigStage(clusterCfg kubeadmapiv3.ClusterConfiguration) yip.Stage {
func getKubeadmJoinCreateClusterConfigStage(clusterCfg kubeadmapiv3.ClusterConfiguration, joinCfg kubeadmapiv3.JoinConfiguration) yip.Stage {
return yip.Stage{
Name: "Generate Cluster Config File",
Files: []yip.File{
{
Path: filepath.Join(configurationPath, "cluster-config.yaml"),
Permissions: 0640,
Content: getUpdatedClusterConfig(clusterCfg),
Content: getUpdatedJoinClusterConfig(clusterCfg, joinCfg),
},
},
}
Expand Down Expand Up @@ -169,3 +169,13 @@ func getKubeadmJoinReconfigureStage(cluster clusterplugin.Cluster, clusterCfg ku
}
return reconfigureStage
}

func getUpdatedJoinClusterConfig(clusterCfg kubeadmapiv3.ClusterConfiguration, joinCfg kubeadmapiv3.JoinConfiguration) string {
initPrintr := printers.NewTypeSetter(scheme).ToPrinter(&printers.YAMLPrinter{})

out := bytes.NewBuffer([]byte{})
_ = initPrintr.PrintObj(&clusterCfg, out)
_ = initPrintr.PrintObj(&joinCfg, out)

return out.String()
}
33 changes: 9 additions & 24 deletions utils/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ package utils

import (
"fmt"
"os"
"strings"

kyaml "sigs.k8s.io/yaml"
"k8s.io/kubernetes/cmd/kubeadm/app/util/initsystem"

"k8s.io/klog/v2"

"k8s.io/kubernetes/cmd/kubeadm/app/util/initsystem"

nodeutil "k8s.io/component-helpers/node/util"
kubeletv1beta1 "k8s.io/kubelet/config/v1beta1"
kubeadmapiv3 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta3"
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
Expand All @@ -37,25 +33,6 @@ var k8sVersionToPauseImage = map[string]string{
"v1.27.5": "3.9",
}

// WriteKubeletConfigToDisk writes the kubelet config object down to a file
func WriteKubeletConfigToDisk(clusterCfg *kubeadmapiv3.ClusterConfiguration, kubeletCfg *kubeletv1beta1.KubeletConfiguration, kubeletConfigPath string) {
MutateKubeletDefaults(clusterCfg, kubeletCfg)
data, _ := kyaml.Marshal(kubeletCfg)
writeConfigBytesToDisk(data, kubeletConfigPath)
}

func isServiceActive(name string) (bool, error) {
initSystem, err := initsystem.GetInitSystem()
if err != nil {
return false, err
}
return initSystem.ServiceIsActive(name), nil
}

func writeConfigBytesToDisk(b []byte, kubeletDir string) {
_ = os.WriteFile(kubeletDir, b, 0644)
}

func RegenerateKubeletKubeadmArgsFile(clusterCfg *kubeadmapiv3.ClusterConfiguration, nodeReg *kubeadmapiv3.NodeRegistrationOptions, nodeRole string) string {
var registerTaintsUsingFlags bool
if nodeRole == "worker" {
Expand Down Expand Up @@ -113,3 +90,11 @@ func getNodeNameAndHostname(cfg *kubeadmapiv3.NodeRegistrationOptions) (string,
}
return nodeName, hostname
}

func isServiceActive(name string) (bool, error) {
initSystem, err := initsystem.GetInitSystem()
if err != nil {
return false, err
}
return initSystem.ServiceIsActive(name), nil
}

0 comments on commit c7680f3

Please sign in to comment.