// RunJoin executes worked node provisioning and tries to join an existing cluster. func RunJoin(out io.Writer, cmd *cobra.Command, args []string, s *kubeadmapi.KubeadmConfig) error { // TODO(phase1+) this we are missing args from the help text, there should be a way to tell cobra about it if len(args) == 0 { return fmt.Errorf("<cmd/join> must specify master IP address (see --help)") } for _, i := range args { addr := net.ParseIP(i) // TODO(phase1+) should allow resolvable names too if addr == nil { return fmt.Errorf("<cmd/join> failed to parse argument (%q) as an IP address", i) } s.JoinFlags.MasterAddrs = append(s.JoinFlags.MasterAddrs, addr) } ok, err := kubeadmutil.UseGivenTokenIfValid(s) if !ok { if err != nil { return fmt.Errorf("<cmd/join> %v (see --help)\n", err) } return fmt.Errorf("Must specify --token (see --help)\n") } kubeconfig, err := kubenode.RetrieveTrustedClusterInfo(s) if err != nil { return err } err = kubeadmutil.WriteKubeconfigIfNotExists(s, "kubelet", kubeconfig) if err != nil { return err } fmt.Fprintf(out, joinDoneMsgf) return nil }
// 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) error { // TODO(phase1+) this we are missing args from the help text, there should be a way to tell cobra about it 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") } kubeconfig, err := kubenode.RetrieveTrustedClusterInfo(s) if err != nil { return err } err = kubeadmutil.WriteKubeconfigIfNotExists("kubelet", kubeconfig) if err != nil { return err } fmt.Fprintf(out, joinDoneMsgf) return nil }
// 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 }
func generateTokenIfNeeded(s *kubeadmapi.Secrets) error { ok, err := kubeadmutil.UseGivenTokenIfValid(s) // TODO(phase1+) @krousey: I know it won't happen with the way it is currently implemented, but this doesn't handle case where ok is true and err is non-nil. if !ok { if err != nil { return err } err = kubeadmutil.GenerateToken(s) if err != nil { return err } fmt.Printf("<master/tokens> generated token: %q\n", s.GivenToken) } else { fmt.Println("<master/tokens> accepted provided token") } return nil }
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 }