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

WIP: Build an RKE2 version of hetzner-kube #349

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions cmd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ are hopefully coming soon.'`,
}

func init() {
clusterCmd.PersistentFlags().StringP("k8s-version", "v", "v1.22.4+rke2r2", "the version of Kubernetes to be installed")
rootCmd.AddCommand(clusterCmd)
}

Expand Down
26 changes: 19 additions & 7 deletions cmd/cluster_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ This tool supports these levels of kubernetes HA:
func RunClusterCreate(cmd *cobra.Command, args []string) {
workerCount, _ := cmd.Flags().GetInt("worker-count")
masterCount, _ := cmd.Flags().GetInt("master-count")
k8sVersion, _ := cmd.Flags().GetString("k8s-version")
etcdCount := 0
haEnabled, _ := cmd.Flags().GetBool("ha-enabled")
if !haEnabled {
Expand All @@ -61,7 +62,16 @@ func RunClusterCreate(cmd *cobra.Command, args []string) {
clusterName = name
}

log.Printf("Creating new cluster\n\nNAME:%s\nMASTERS: %d\nWORKERS: %d\nETCD NODES: %d\nHA: %t\nISOLATED ETCD: %t", clusterName, masterCount, workerCount, etcdCount, haEnabled, isolatedEtcd)
log.Printf(
"Creating new cluster (version: %s)\n\nNAME:%s\nMASTERS: %d\nWORKERS: %d\nETCD NODES: %d\nHA: %t\nISOLATED ETCD: %t",
k8sVersion,
clusterName,
masterCount,
workerCount,
etcdCount,
haEnabled,
isolatedEtcd,
)

sshKeyName, _ := cmd.Flags().GetString("ssh-key")
masterServerType, _ := cmd.Flags().GetString("master-server-type")
Expand All @@ -71,9 +81,10 @@ func RunClusterCreate(cmd *cobra.Command, args []string) {
cloudInit, _ := cmd.Flags().GetString("cloud-init")

hetznerProvider := hetzner.NewHetznerProvider(AppConf.Context, AppConf.Client, clustermanager.Cluster{
Name: clusterName,
NodeCIDR: nodeCidr,
CloudInitFile: cloudInit,
Name: clusterName,
NodeCIDR: nodeCidr,
CloudInitFile: cloudInit,
KubernetesVersion: k8sVersion,
}, AppConf.CurrentContext.Token)

sshClient := clustermanager.NewSSHCommunicator(AppConf.Config.SSHKeys, debug)
Expand Down Expand Up @@ -103,7 +114,7 @@ func RunClusterCreate(cmd *cobra.Command, args []string) {

coordinator := pkg.NewProgressCoordinator()

clusterManager := clustermanager.NewClusterManager(hetznerProvider, sshClient, coordinator, clusterName, haEnabled, isolatedEtcd, cloudInit)
clusterManager := clustermanager.NewClusterManager(hetznerProvider, sshClient, coordinator, clusterName, haEnabled, isolatedEtcd, cloudInit, k8sVersion)
cluster := clusterManager.Cluster()
saveCluster(&cluster)
renderProgressBars(&cluster, coordinator)
Expand All @@ -113,6 +124,7 @@ func RunClusterCreate(cmd *cobra.Command, args []string) {
phaseChain.AddPhase(phases.NewProvisionNodesPhase(clusterManager))
phaseChain.AddPhase(phases.NewNetworkSetupPhase(clusterManager))
phaseChain.AddPhase(phases.NewEtcdSetupPhase(clusterManager, hetznerProvider, phases.EtcdSetupPhaseOptions{KeepData: false}))
phaseChain.AddPhase(phases.NewDeployLoadBalancerPhase(clusterManager))
phaseChain.AddPhase(phases.NewInstallMastersPhase(clusterManager, phases.InstallMastersPhaseOptions{KeepCaCerts: false, KeepAllCerts: false}))
phaseChain.AddPhase(phases.NewSetupHighAvailabilityPhase(clusterManager))
phaseChain.AddPhase(phases.NewInstallWorkersPhase(clusterManager))
Expand Down Expand Up @@ -262,8 +274,8 @@ func init() {

clusterCreateCmd.Flags().StringP("name", "n", "", "Name of the cluster")
clusterCreateCmd.Flags().StringP("ssh-key", "k", "", "Name of the SSH key used for provisioning")
clusterCreateCmd.Flags().String("master-server-type", "cx11", "Server type used of masters")
clusterCreateCmd.Flags().String("worker-server-type", "cx11", "Server type used of workers")
clusterCreateCmd.Flags().String("master-server-type", "cx21", "Server type used of masters")
clusterCreateCmd.Flags().String("worker-server-type", "cx21", "Server type used of workers")
clusterCreateCmd.Flags().Bool("ha-enabled", false, "Install high-available control plane")
clusterCreateCmd.Flags().Bool("isolated-etcd", false, "Isolates etcd cluster from master nodes")
clusterCreateCmd.Flags().IntP("master-count", "m", 3, "Number of master nodes, works only if -ha-enabled is passed")
Expand Down
2 changes: 1 addition & 1 deletion cmd/cluster_kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Example 4: hetzner-kube cluster kubeconfig -n my-cluster -p > my-conf.yaml # pri
err = AppConf.SSHClient.(*clustermanager.SSHCommunicator).CapturePassphrase(masterNode.SSHKeyName)
FatalOnError(err)

kubeConfigContent, err := AppConf.SSHClient.RunCmd(*masterNode, "cat /etc/kubernetes/admin.conf")
kubeConfigContent, err := AppConf.SSHClient.RunCmd(*masterNode, "cat /etc/rancher/rke2/rke2.yaml")
// change the IP to public
kubeConfigContent = strings.Replace(kubeConfigContent, masterNode.PrivateIPAddress, masterNode.IPAddress, -1)

Expand Down
2 changes: 2 additions & 0 deletions cmd/cluster_phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func getCommonPhaseDependencies(steps int, cmd *cobra.Command, args []string) (c
err = AppConf.SSHClient.(*clustermanager.SSHCommunicator).CapturePassphrase(masterNode.SSHKeyName)
FatalOnError(err)
coordinator := pkg.NewProgressCoordinator()
k8sVersion, _ := cmd.Flags().GetString("k8s-version")

for _, node := range provider.GetAllNodes() {
coordinator.StartProgress(node.Name, steps)
Expand All @@ -52,6 +53,7 @@ func getCommonPhaseDependencies(steps int, cmd *cobra.Command, args []string) (c
cluster.HaEnabled,
cluster.IsolatedEtcd,
cluster.CloudInitFile,
k8sVersion,
)

return provider, clusterManager, coordinator
Expand Down
2 changes: 2 additions & 0 deletions cmd/cluster_phase_install_masters.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var installMastersPhaseCommand = &cobra.Command{
clusterName := args[0]
keepCa, _ := cmd.Flags().GetBool("keep-ca")
keepAll, _ := cmd.Flags().GetBool("keep-all-certs")
k8sVersion, _ := cmd.Flags().GetString("k8s-version")
phaseOptions := phases.InstallMastersPhaseOptions{
KeepCaCerts: keepCa,
KeepAllCerts: keepAll,
Expand Down Expand Up @@ -54,6 +55,7 @@ var installMastersPhaseCommand = &cobra.Command{
cluster.HaEnabled,
cluster.IsolatedEtcd,
cluster.CloudInitFile,
k8sVersion,
)
phase := phases.NewInstallMastersPhase(clusterManager, phaseOptions)

Expand Down
10 changes: 6 additions & 4 deletions cmd/cluster_phase_install_workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ var installWorkersCommand = &cobra.Command{
}
coordinator := pkg.NewProgressCoordinator()

for _, node := range provider.GetAllNodes() {
for _, node := range provider.GetWorkerNodes() {
steps := 2
if cluster.HaEnabled {
steps++
}
coordinator.StartProgress(node.Name, steps)
}

k8sVersion, _ := cmd.Flags().GetString("k8s-version")
clusterManager := clustermanager.NewClusterManager(
provider,
AppConf.SSHClient,
Expand All @@ -44,6 +45,7 @@ var installWorkersCommand = &cobra.Command{
cluster.HaEnabled,
cluster.IsolatedEtcd,
cluster.CloudInitFile,
k8sVersion,
)
phase := phases2.NewInstallWorkersPhase(clusterManager)

Expand All @@ -54,9 +56,9 @@ var installWorkersCommand = &cobra.Command{
}
}

for _, node := range provider.GetAllNodes() {
coordinator.AddEvent(node.Name, pkg.CompletedEvent)
}
//for _, node := range provider.GetAllNodes() {
// coordinator.AddEvent(node.Name, pkg.CompletedEvent)
//}

coordinator.Wait()

Expand Down
2 changes: 2 additions & 0 deletions cmd/cluster_phase_setup_ha.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var setupHAPhaseCommand = &cobra.Command{
coordinator.StartProgress(node.Name, steps)
}

k8sVersion, _ := cmd.Flags().GetString("k8s-version")
clusterManager := clustermanager.NewClusterManager(
provider,
AppConf.SSHClient,
Expand All @@ -46,6 +47,7 @@ var setupHAPhaseCommand = &cobra.Command{
cluster.HaEnabled,
cluster.IsolatedEtcd,
cluster.CloudInitFile,
k8sVersion,
)

phase := phases.NewSetupHighAvailabilityPhase(clusterManager)
Expand Down
Loading