Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use init and join config alongside cluster for reconfiguration #120

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 0 additions & 79 deletions .github/workflows/publish.yaml

This file was deleted.

43 changes: 2 additions & 41 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
push:
branches:
- main
- dev

permissions:
contents: read
Expand Down Expand Up @@ -38,43 +37,5 @@ jobs:
- run: earthly --ci --output +provider-package-all-platforms --IMAGE_REPOSITORY=ghcr.io/kairos-io
- name: Push to testing
run: |
docker tag ghcr.io/kairos-io/provider-kubeadm:latest ttl.sh/kairos-io/provider-kubeadm-${{ github.sha }}:8h
docker push ttl.sh/kairos-io/provider-kubeadm-${{ github.sha }}:8h
build:
runs-on: ubuntu-latest
permissions:
id-token: write
strategy:
matrix:
base-image:
- quay.io/kairos/core-opensuse-leap:v2.3.2
- quay.io/kairos/core-ubuntu-20-lts:v2.3.2
- quay.io/kairos/core-ubuntu-22-lts:v2.3.2
kubeadm-version:
- 1.24.6
steps:
- uses: actions/checkout@v2
- uses: docker-practice/actions-setup-docker@master
- uses: earthly/actions-setup@v1
with:
version: "v0.6.30"
- run: earthly --ci +docker-all-platforms --KUBEADM_VERSION=${{ matrix.kubeadm-version }} --BASE_IMAGE=${{ matrix.base-image }}
build-fips:
runs-on: ubuntu-latest
permissions:
id-token: write
strategy:
matrix:
base-image:
- quay.io/kairos/core-opensuse-leap:v2.3.2
- quay.io/kairos/core-ubuntu-20-lts:v2.3.2
- quay.io/kairos/core-ubuntu-22-lts:v2.3.2
kubeadm-version:
- 1.24.6
steps:
- uses: actions/checkout@v2
- uses: docker-practice/actions-setup-docker@master
- uses: earthly/actions-setup@v1
with:
version: "v0.6.30"
- run: earthly --ci +docker-all-platforms --KUBEADM_VERSION=${{ matrix.kubeadm-version }} --BASE_IMAGE=${{ matrix.base-image }} --FIPS_ENABLED=true
docker tag ghcr.io/kairos-io/provider-kubeadm:latest ttl.sh/kairos-io/provider-kubeadm-${{ github.sha }}:24h
docker push ttl.sh/kairos-io/provider-kubeadm-${{ github.sha }}:24h
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
}
Loading