mirror of https://github.com/kubernetes/kops.git
Clean up "create secret weavepassword"
This commit is contained in:
parent
df325d28a3
commit
597192981d
|
|
@ -11,7 +11,7 @@ go_library(
|
|||
"create_secret_ciliumpassword.go",
|
||||
"create_secret_dockerconfig.go",
|
||||
"create_secret_encryptionconfig.go",
|
||||
"create_secret_weave_encryptionconfig.go",
|
||||
"create_secret_weavepassword.go",
|
||||
"create_sshpublickey.go",
|
||||
"delete.go",
|
||||
"delete_cluster.go",
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ func NewCmdCreateSecret(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
cmd.AddCommand(NewCmdCreateSecretCiliumPassword(f, out))
|
||||
cmd.AddCommand(NewCmdCreateSecretDockerConfig(f, out))
|
||||
cmd.AddCommand(NewCmdCreateSecretEncryptionConfig(f, out))
|
||||
cmd.AddCommand(NewCmdCreateSecretWeaveEncryptionConfig(f, out))
|
||||
cmd.AddCommand(NewCmdCreateSecretWeavePassword(f, out))
|
||||
|
||||
sshPublicKey := NewCmdCreateSSHPublicKey(f, out)
|
||||
sshPublicKey.Hidden = true
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import (
|
|||
"io/ioutil"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"k8s.io/kops/pkg/commands/commandutils"
|
||||
|
||||
"k8s.io/kops/cmd/kops/util"
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
|
|
@ -31,74 +32,66 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
createSecretWeaveEncryptionconfigLong = templates.LongDesc(i18n.T(`
|
||||
Create a new weave encryption secret, and store it in the state store.
|
||||
Used to weave networking to use encrypted communication between nodes.
|
||||
createSecretWeavePasswordLong = templates.LongDesc(i18n.T(`
|
||||
Create a new weave encryption secret and store it in the state store.
|
||||
Used by Weave networking to encrypt communication between nodes.
|
||||
|
||||
If no password is provided, kOps will generate one at random.
|
||||
|
||||
WARNING: cannot be enabled on a running cluster without downtime.`))
|
||||
WARNING: cannot be enabled or changed on a running cluster without downtime.`))
|
||||
|
||||
createSecretWeaveEncryptionconfigExample = templates.Examples(i18n.T(`
|
||||
createSecretWeavePasswordExample = templates.Examples(i18n.T(`
|
||||
# Create a new random weave password.
|
||||
kops create secret weavepassword \
|
||||
--name k8s-cluster.example.com --state s3://my-state-store
|
||||
|
||||
# Install a specific weave password.
|
||||
kops create secret weavepassword -f /path/to/weavepassword \
|
||||
--name k8s-cluster.example.com --state s3://my-state-store
|
||||
|
||||
# Install a specific weave password via stdin.
|
||||
kops create secret weavepassword -f - \
|
||||
--name k8s-cluster.example.com --state s3://my-state-store
|
||||
# Replace an existing weavepassword secret.
|
||||
|
||||
# Replace an existing weave password.
|
||||
kops create secret weavepassword -f /path/to/weavepassword --force \
|
||||
--name k8s-cluster.example.com --state s3://my-state-store
|
||||
`))
|
||||
|
||||
createSecretWeaveEncryptionconfigShort = i18n.T(`Create a weave encryption config.`)
|
||||
createSecretWeavePasswordShort = i18n.T(`Create a Weave password.`)
|
||||
)
|
||||
|
||||
type CreateSecretWeaveEncryptionConfigOptions struct {
|
||||
type CreateSecretWeavePasswordOptions struct {
|
||||
ClusterName string
|
||||
WeavePasswordFilePath string
|
||||
Force bool
|
||||
}
|
||||
|
||||
func NewCmdCreateSecretWeaveEncryptionConfig(f *util.Factory, out io.Writer) *cobra.Command {
|
||||
options := &CreateSecretWeaveEncryptionConfigOptions{}
|
||||
func NewCmdCreateSecretWeavePassword(f *util.Factory, out io.Writer) *cobra.Command {
|
||||
options := &CreateSecretWeavePasswordOptions{}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "weavepassword",
|
||||
Short: createSecretWeaveEncryptionconfigShort,
|
||||
Long: createSecretWeaveEncryptionconfigLong,
|
||||
Example: createSecretWeaveEncryptionconfigExample,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
ctx := context.TODO()
|
||||
|
||||
err := rootCommand.ProcessArgs(args[0:])
|
||||
if err != nil {
|
||||
exitWithError(err)
|
||||
}
|
||||
|
||||
options.ClusterName = rootCommand.ClusterName(true)
|
||||
|
||||
err = RunCreateSecretWeaveEncryptionConfig(ctx, f, options)
|
||||
if err != nil {
|
||||
exitWithError(err)
|
||||
}
|
||||
Use: "weavepassword [CLUSTER]",
|
||||
Short: createSecretWeavePasswordShort,
|
||||
Long: createSecretWeavePasswordLong,
|
||||
Example: createSecretWeavePasswordExample,
|
||||
Args: rootCommand.clusterNameArgs(&options.ClusterName),
|
||||
ValidArgsFunction: commandutils.CompleteClusterName(&rootCommand, true, false),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return RunCreateSecretWeavePassword(context.TODO(), f, out, options)
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringVarP(&options.WeavePasswordFilePath, "", "f", "", "Path to the weave password file (optional)")
|
||||
cmd.Flags().BoolVar(&options.Force, "force", options.Force, "Force replace the kOps secret if it already exists")
|
||||
cmd.Flags().StringVarP(&options.WeavePasswordFilePath, "filename", "f", "", "Path to Weave password file")
|
||||
cmd.Flags().BoolVar(&options.Force, "force", options.Force, "Force replace the secret if it already exists")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func RunCreateSecretWeaveEncryptionConfig(ctx context.Context, f *util.Factory, options *CreateSecretWeaveEncryptionConfigOptions) error {
|
||||
|
||||
func RunCreateSecretWeavePassword(ctx context.Context, f *util.Factory, out io.Writer, options *CreateSecretWeavePasswordOptions) error {
|
||||
secret, err := fi.CreateSecret()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating encryption secret: %v", err)
|
||||
return fmt.Errorf("creating Weave password: %v", err)
|
||||
}
|
||||
|
||||
cluster, err := GetCluster(ctx, f, options.ClusterName)
|
||||
|
|
@ -121,14 +114,13 @@ func RunCreateSecretWeaveEncryptionConfig(ctx context.Context, f *util.Factory,
|
|||
if options.WeavePasswordFilePath == "-" {
|
||||
data, err = ConsumeStdin()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading weave password file from stdin: %v", err)
|
||||
return fmt.Errorf("reading Weave password file from stdin: %v", err)
|
||||
}
|
||||
} else {
|
||||
data, err = ioutil.ReadFile(options.WeavePasswordFilePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading weave password file %v: %v", options.WeavePasswordFilePath, err)
|
||||
return fmt.Errorf("reading Weave password file %v: %v", options.WeavePasswordFilePath, err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
secret.Data = data
|
||||
|
|
@ -137,15 +129,15 @@ func RunCreateSecretWeaveEncryptionConfig(ctx context.Context, f *util.Factory,
|
|||
if !options.Force {
|
||||
_, created, err := secretStore.GetOrCreateSecret("weavepassword", secret)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error adding weavepassword secret: %v", err)
|
||||
return fmt.Errorf("adding weavepassword secret: %v", err)
|
||||
}
|
||||
if !created {
|
||||
return fmt.Errorf("failed to create the weavepassword secret as it already exists. The `--force` flag can be passed to replace an existing secret")
|
||||
return fmt.Errorf("failed to create the weavepassword secret as it already exists. Pass the `--force` flag to replace an existing secret")
|
||||
}
|
||||
} else {
|
||||
_, err := secretStore.ReplaceSecret("weavepassword", secret)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error updating weavepassword secret: %v", err)
|
||||
return fmt.Errorf("updating weavepassword secret: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -38,5 +38,5 @@ Create a secret.
|
|||
* [kops create secret ciliumpassword](kops_create_secret_ciliumpassword.md) - Create a Cilium IPsec configuration.
|
||||
* [kops create secret dockerconfig](kops_create_secret_dockerconfig.md) - Create a Docker config.
|
||||
* [kops create secret encryptionconfig](kops_create_secret_encryptionconfig.md) - Create an encryption config.
|
||||
* [kops create secret weavepassword](kops_create_secret_weavepassword.md) - Create a weave encryption config.
|
||||
* [kops create secret weavepassword](kops_create_secret_weavepassword.md) - Create a Weave password.
|
||||
|
||||
|
|
|
|||
|
|
@ -3,18 +3,18 @@
|
|||
|
||||
## kops create secret weavepassword
|
||||
|
||||
Create a weave encryption config.
|
||||
Create a Weave password.
|
||||
|
||||
### Synopsis
|
||||
|
||||
Create a new weave encryption secret, and store it in the state store. Used to weave networking to use encrypted communication between nodes.
|
||||
Create a new weave encryption secret and store it in the state store. Used by Weave networking to encrypt communication between nodes.
|
||||
|
||||
If no password is provided, kOps will generate one at random.
|
||||
|
||||
WARNING: cannot be enabled on a running cluster without downtime.
|
||||
WARNING: cannot be enabled or changed on a running cluster without downtime.
|
||||
|
||||
```
|
||||
kops create secret weavepassword [flags]
|
||||
kops create secret weavepassword [CLUSTER] [flags]
|
||||
```
|
||||
|
||||
### Examples
|
||||
|
|
@ -23,13 +23,16 @@ kops create secret weavepassword [flags]
|
|||
# Create a new random weave password.
|
||||
kops create secret weavepassword \
|
||||
--name k8s-cluster.example.com --state s3://my-state-store
|
||||
|
||||
# Install a specific weave password.
|
||||
kops create secret weavepassword -f /path/to/weavepassword \
|
||||
--name k8s-cluster.example.com --state s3://my-state-store
|
||||
|
||||
# Install a specific weave password via stdin.
|
||||
kops create secret weavepassword -f - \
|
||||
--name k8s-cluster.example.com --state s3://my-state-store
|
||||
# Replace an existing weavepassword secret.
|
||||
|
||||
# Replace an existing weave password.
|
||||
kops create secret weavepassword -f /path/to/weavepassword --force \
|
||||
--name k8s-cluster.example.com --state s3://my-state-store
|
||||
```
|
||||
|
|
@ -37,9 +40,9 @@ kops create secret weavepassword [flags]
|
|||
### Options
|
||||
|
||||
```
|
||||
-f, -- string Path to the weave password file (optional)
|
||||
--force Force replace the kOps secret if it already exists
|
||||
-h, --help help for weavepassword
|
||||
-f, --filename string Path to Weave password file
|
||||
--force Force replace the secret if it already exists
|
||||
-h, --help help for weavepassword
|
||||
```
|
||||
|
||||
### Options inherited from parent commands
|
||||
|
|
|
|||
Loading…
Reference in New Issue