예제 #1
0
func NewJoin(cfgPath string, args []string, cfg *kubeadmapi.NodeConfiguration, skipPreFlight bool) (*Join, error) {

	fmt.Println("[kubeadm] WARNING: kubeadm is in alpha, please do not use it for production clusters.")

	if cfgPath != "" {
		b, err := ioutil.ReadFile(cfgPath)
		if err != nil {
			return nil, fmt.Errorf("unable to read config from %q [%v]", cfgPath, err)
		}
		if err := runtime.DecodeInto(api.Codecs.UniversalDecoder(), b, cfg); err != nil {
			return nil, fmt.Errorf("unable to decode config from %q [%v]", cfgPath, err)
		}
	}

	if !skipPreFlight {
		fmt.Println("[preflight] Running pre-flight checks")

		// First, check if we're root separately from the other preflight checks and fail fast
		if err := preflight.RunRootCheckOnly(); err != nil {
			return nil, err
		}

		// Then continue with the others...
		if err := preflight.RunJoinNodeChecks(cfg); err != nil {
			return nil, err
		}
	} else {
		fmt.Println("[preflight] Skipping pre-flight checks")
	}

	// Try to start the kubelet service in case it's inactive
	preflight.TryStartKubelet()

	return &Join{cfg: cfg}, nil
}
예제 #2
0
// RunJoin executes worked node provisioning and tries to join an existing cluster.
func RunJoin(out io.Writer, cmd *cobra.Command, args []string, s *kubeadmapi.NodeConfiguration, skipPreFlight bool) error {
	// TODO(phase1+) this we are missing args from the help text, there should be a way to tell cobra about it
	if !skipPreFlight {
		fmt.Println("Running pre-flight checks")
		err := preflight.RunJoinNodeChecks()
		if err != nil {
			return err
		}
	} else {
		fmt.Println("Skipping pre-flight checks")
	}

	if len(args) == 0 {
		return fmt.Errorf("<cmd/join> must specify master IP address (see --help)")
	}
	s.MasterAddresses = append(s.MasterAddresses, args...)

	ok, err := kubeadmutil.UseGivenTokenIfValid(&s.Secrets)
	if !ok {
		if err != nil {
			return fmt.Errorf("<cmd/join> %v (see --help)\n", err)
		}
		return fmt.Errorf("Must specify --token (see --help)\n")
	}

	clusterInfo, err := kubenode.RetrieveTrustedClusterInfo(s)
	if err != nil {
		return err
	}

	connectionDetails, err := kubenode.EstablishMasterConnection(s, clusterInfo)
	if err != nil {
		return err
	}

	kubeconfig, err := kubenode.PerformTLSBootstrap(connectionDetails)
	if err != nil {
		return err
	}

	err = kubeadmutil.WriteKubeconfigIfNotExists("kubelet", kubeconfig)
	if err != nil {
		return err
	}

	fmt.Fprintf(out, joinDoneMsgf)
	return nil
}
예제 #3
0
func NewJoin(cfgPath string, args []string, cfg *kubeadmapi.NodeConfiguration, skipPreFlight bool) (*Join, error) {
	if cfgPath != "" {
		b, err := ioutil.ReadFile(cfgPath)
		if err != nil {
			return nil, fmt.Errorf("unable to read config from %q [%v]", cfgPath, err)
		}
		if err := runtime.DecodeInto(api.Codecs.UniversalDecoder(), b, cfg); err != nil {
			return nil, fmt.Errorf("unable to decode config from %q [%v]", cfgPath, err)
		}
	}

	if len(args) == 0 && len(cfg.MasterAddresses) == 0 {
		return nil, fmt.Errorf("must specify master address (see --help)")
	}
	cfg.MasterAddresses = append(cfg.MasterAddresses, args...)
	if len(cfg.MasterAddresses) > 1 {
		return nil, fmt.Errorf("Must not specify more than one master address  (see --help)")
	}

	if !skipPreFlight {
		fmt.Println("Running pre-flight checks")
		err := preflight.RunJoinNodeChecks(cfg)
		if err != nil {
			return nil, &preflight.PreFlightError{Msg: err.Error()}
		}
	} else {
		fmt.Println("Skipping pre-flight checks")
	}

	ok, err := kubeadmutil.UseGivenTokenIfValid(&cfg.Secrets)
	if !ok {
		if err != nil {
			return nil, fmt.Errorf("%v (see --help)\n", err)
		}
		return nil, fmt.Errorf("Must specify --token (see --help)\n")
	}

	return &Join{cfg: cfg}, nil
}