func kubeadmInitWithPhases()

in kinder/pkg/cluster/manager/actions/kubeadm-init.go [115:215]


func kubeadmInitWithPhases(cp1 *status.Node, copyCertsMode CopyCertsMode, patchesDir, ignorePreflightErrors string, vLevel int) error {
	if err := cp1.Command(
		"kubeadm", "init", "phase", "preflight", fmt.Sprintf("--config=%s", constants.KubeadmConfigPath), fmt.Sprintf("--v=%d", vLevel),
		fmt.Sprintf("--ignore-preflight-errors=%s", ignorePreflightErrors),
	).RunWithEcho(); err != nil {
		return err
	}

	if err := cp1.Command(
		"kubeadm", "init", "phase", "kubelet-start", fmt.Sprintf("--config=%s", constants.KubeadmConfigPath), fmt.Sprintf("--v=%d", vLevel),
	).RunWithEcho(); err != nil {
		return err
	}

	if err := cp1.Command(
		"kubeadm", "init", "phase", "certs", "all", fmt.Sprintf("--config=%s", constants.KubeadmConfigPath), fmt.Sprintf("--v=%d", vLevel),
	).RunWithEcho(); err != nil {
		return err
	}

	if err := cp1.Command(
		"kubeadm", "init", "phase", "kubeconfig", "all", fmt.Sprintf("--config=%s", constants.KubeadmConfigPath), fmt.Sprintf("--v=%d", vLevel),
	).RunWithEcho(); err != nil {
		return err
	}

	controlplaneArgs := []string{
		"init", "phase", "control-plane", "all", fmt.Sprintf("--config=%s", constants.KubeadmConfigPath), fmt.Sprintf("--v=%d", vLevel),
	}
	if patchesDir != "" {
		if cp1.MustKubeadmVersion().LessThan(constants.V1_22) {
			controlplaneArgs = append(controlplaneArgs, "--experimental-patches", constants.PatchesDir)
		}
	}
	if err := cp1.Command(
		"kubeadm", controlplaneArgs...,
	).RunWithEcho(); err != nil {
		return err
	}

	etcdArgs := []string{
		"init", "phase", "etcd", "local", fmt.Sprintf("--config=%s", constants.KubeadmConfigPath), fmt.Sprintf("--v=%d", vLevel),
	}
	if patchesDir != "" {
		if cp1.MustKubeadmVersion().LessThan(constants.V1_22) {
			etcdArgs = append(etcdArgs, "--experimental-patches", constants.PatchesDir)
		}
	}
	if err := cp1.Command(
		"kubeadm", etcdArgs...,
	).RunWithEcho(); err != nil {
		return err
	}

	cp1.Infof("waiting for the api server to start")
	if err := cp1.Command(
		"/bin/bash", "-c", //use shell to get $(...) resolved into the container
		fmt.Sprintf("while [[ \"$(curl -k https://localhost:%d/healthz -s -o /dev/null -w ''%%{http_code}'')\" != \"200\" ]]; do sleep 1; done", constants.APIServerPort),
	).Silent().Run(); err != nil {
		return err
	}

	if err := cp1.Command(
		"kubeadm", "init", "phase", "upload-config", "all", fmt.Sprintf("--config=%s", constants.KubeadmConfigPath), fmt.Sprintf("--v=%d", vLevel),
	).RunWithEcho(); err != nil {
		return err
	}

	if copyCertsMode == CopyCertsModeAuto {
		uploadCertsArgs := []string{
			"init", "phase", "upload-certs", "--upload-certs",
			fmt.Sprintf("--config=%s", constants.KubeadmConfigPath),
			fmt.Sprintf("--v=%d", vLevel),
		}
		if err := cp1.Command(
			"kubeadm", uploadCertsArgs...,
		).RunWithEcho(); err != nil {
			return err
		}
	}

	if err := cp1.Command(
		"kubeadm", "init", "phase", "mark-control-plane", fmt.Sprintf("--config=%s", constants.KubeadmConfigPath), fmt.Sprintf("--v=%d", vLevel),
	).RunWithEcho(); err != nil {
		return err
	}

	if err := cp1.Command(
		"kubeadm", "init", "phase", "bootstrap-token", fmt.Sprintf("--config=%s", constants.KubeadmConfigPath), fmt.Sprintf("--v=%d", vLevel),
	).RunWithEcho(); err != nil {
		return err
	}

	if err := cp1.Command(
		"kubeadm", "init", "phase", "addon", "all", fmt.Sprintf("--config=%s", constants.KubeadmConfigPath), fmt.Sprintf("--v=%d", vLevel),
	).RunWithEcho(); err != nil {
		return err
	}

	return nil
}