From b7c2f2d7edbbe5092843be61124bc322d79cff40 Mon Sep 17 00:00:00 2001 From: Carlisia Date: Fri, 18 Dec 2020 13:08:02 -0800 Subject: [PATCH] Better help messages and validation check Signed-off-by: Carlisia --- pkg/apis/velero/v1/backupstoragelocation_types.go | 2 +- pkg/cmd/cli/backuplocation/create.go | 5 ++++- pkg/cmd/cli/backuplocation/set.go | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/apis/velero/v1/backupstoragelocation_types.go b/pkg/apis/velero/v1/backupstoragelocation_types.go index 548adb9ad..d891071e3 100644 --- a/pkg/apis/velero/v1/backupstoragelocation_types.go +++ b/pkg/apis/velero/v1/backupstoragelocation_types.go @@ -33,7 +33,7 @@ type BackupStorageLocationSpec struct { // Credential contains the credential information intended to be used with this location // +optional - Credential *corev1api.SecretKeySelector `json:"credential"` + Credential *corev1api.SecretKeySelector `json:"credential,omitempty"` StorageType `json:",inline"` diff --git a/pkg/cmd/cli/backuplocation/create.go b/pkg/cmd/cli/backuplocation/create.go index 5c0cabbea..a0d33d3e5 100644 --- a/pkg/cmd/cli/backuplocation/create.go +++ b/pkg/cmd/cli/backuplocation/create.go @@ -89,7 +89,7 @@ func NewCreateOptions() *CreateOptions { func (o *CreateOptions) BindFlags(flags *pflag.FlagSet) { flags.StringVar(&o.Provider, "provider", o.Provider, "Name of the backup storage provider (e.g. aws, azure, gcp).") flags.StringVar(&o.Bucket, "bucket", o.Bucket, "Name of the object storage bucket where backups should be stored.") - flags.Var(&o.Credential, "credential", "The one credential to be used by this location in key-value pair, where key is the secret name, and value is the secret key name. Optional.") + flags.Var(&o.Credential, "credential", "The credential to be used by this location as a key-value pair, where the key is the Kubernetes Secret name, and the value is the data key name within the Secret. Optional, one value only.") flags.BoolVar(&o.DefaultBackupStorageLocation, "default", o.DefaultBackupStorageLocation, "Sets this new location to be the new default backup storage location. Optional.") flags.StringVar(&o.Prefix, "prefix", o.Prefix, "Prefix under which all Velero data should be stored within the bucket. Optional.") flags.DurationVar(&o.BackupSyncPeriod, "backup-sync-period", o.BackupSyncPeriod, "How often to ensure all Velero backups in object storage exist as Backup API objects in the cluster. Optional. Set this to `0s` to disable sync. Default: 1 minute.") @@ -152,6 +152,9 @@ func (o *CreateOptions) Run(c *cobra.Command, f client.Factory) error { validationFrequency = &metav1.Duration{Duration: o.ValidationFrequency} } + if len(o.Credential.Data()) > 1 { + return errors.New("--credential can only contain 1 key/value pair") + } var secretName, secretKey string for k, v := range o.Credential.Data() { secretName = k diff --git a/pkg/cmd/cli/backuplocation/set.go b/pkg/cmd/cli/backuplocation/set.go index b87199d31..8bcf8aebf 100644 --- a/pkg/cmd/cli/backuplocation/set.go +++ b/pkg/cmd/cli/backuplocation/set.go @@ -68,7 +68,7 @@ func NewSetOptions() *SetOptions { func (o *SetOptions) BindFlags(flags *pflag.FlagSet) { flags.StringVar(&o.CACertFile, "cacert", o.CACertFile, "File containing a certificate bundle to use when verifying TLS connections to the object store. Optional.") - flags.Var(&o.Credential, "credential", "Sets the one credential to be used by this location in key-value pair, where key is the secret name, and value is the secret key name. Optional.") + flags.Var(&o.Credential, "credential", "Sets the credential to be used by this location as a key-value pair, where the key is the Kubernetes Secret name, and the value is the data key name within the Secret. Optional, one value only.") flags.BoolVar(&o.DefaultBackupStorageLocation, "default", o.DefaultBackupStorageLocation, "Sets this new location to be the new default backup storage location. Optional.") }