func GenerateToken(d *kubeadmapi.TokenDiscovery) error { tokenID, err := RandBytes(TokenIDBytes) if err != nil { return err } token, err := RandBytes(TokenBytes) if err != nil { return err } d.ID = tokenID d.Secret = token return nil }
// GenerateToken generates a new token with a token ID that is valid as a // Kubernetes DNS label. // For more info, see kubernetes/pkg/util/validation/validation.go. func GenerateToken(d *kubeadmapi.TokenDiscovery) error { tokenID, err := randBytes(TokenIDBytes) if err != nil { return err } token, err := randBytes(TokenSecretBytes) if err != nil { return err } d.ID = strings.ToLower(tokenID) d.Secret = strings.ToLower(token) return nil }
func PrepareTokenDiscovery(d *kubeadmapi.TokenDiscovery) error { if len(d.Addresses) == 0 { ip, err := netutil.ChooseHostInterface() if err != nil { return err } d.Addresses = []string{ip.String() + ":" + strconv.Itoa(kubeadmapiext.DefaultDiscoveryBindPort)} } if err := kubeadmutil.GenerateTokenIfNeeded(d); err != nil { return fmt.Errorf("failed to generate token(s) [%v]", err) } return nil }