Exemplo n.º 1
0
// RunCreateToken generates a new bootstrap token and stores it as a secret on the server.
func RunCreateToken(out io.Writer, cmd *cobra.Command, tokenDuration time.Duration, token string) error {
	client, err := kubemaster.CreateClientFromFile(path.Join(kubeadmapi.GlobalEnvParams.KubernetesDir, "admin.conf"))
	if err != nil {
		return err
	}

	d := &kubeadmapi.TokenDiscovery{}
	if token != "" {
		parsedID, parsedSecret, err := kubeadmutil.ParseToken(token)
		if err != nil {
			return err
		}
		d.ID = parsedID
		d.Secret = parsedSecret
	}
	err = kubeadmutil.GenerateTokenIfNeeded(d)
	if err != nil {
		return err
	}

	err = kubeadmutil.UpdateOrCreateToken(client, d, tokenDuration)
	if err != nil {
		return err
	}
	fmt.Fprintln(out, kubeadmutil.BearerToken(d))

	return nil
}
Exemplo n.º 2
0
// RunCreateToken generates a new bootstrap token and stores it as a secret on the server.
func RunCreateToken(out io.Writer, cmd *cobra.Command, tokenDuration time.Duration, token string) error {
	client, err := kubemaster.CreateClientFromFile(path.Join(kubeadmapi.GlobalEnvParams.KubernetesDir, kubeconfig.AdminKubeConfigFileName))
	if err != nil {
		return err
	}

	parsedID, parsedSecret, err := kubeadmutil.ParseToken(token)
	if err != nil {
		return err
	}
	td := &kubeadmapi.TokenDiscovery{ID: parsedID, Secret: parsedSecret}

	err = kubeadmutil.UpdateOrCreateToken(client, td, tokenDuration)
	if err != nil {
		return err
	}
	fmt.Fprintln(out, kubeadmutil.BearerToken(td))

	return nil
}