mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-05 04:55:22 +00:00
Add cacert flag for velero backup-location create (#2778)
Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>
This commit is contained in:
1
changelogs/unreleased/2778-jenting
Normal file
1
changelogs/unreleased/2778-jenting
Normal file
@@ -0,0 +1 @@
|
||||
Add cacert flag for velero backup-location create
|
||||
@@ -19,6 +19,8 @@ package backuplocation
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -65,6 +67,7 @@ type CreateOptions struct {
|
||||
BackupSyncPeriod, ValidationFrequency time.Duration
|
||||
Config flag.Map
|
||||
Labels flag.Map
|
||||
CACertFile string
|
||||
AccessMode *flag.Enum
|
||||
}
|
||||
|
||||
@@ -87,6 +90,7 @@ func (o *CreateOptions) BindFlags(flags *pflag.FlagSet) {
|
||||
flags.DurationVar(&o.ValidationFrequency, "validation-frequency", o.ValidationFrequency, "how often to verify if the backup storage location is valid. Optional. Set this to `0s` to disable sync. Default 1 minute.")
|
||||
flags.Var(&o.Config, "config", "configuration key-value pairs")
|
||||
flags.Var(&o.Labels, "labels", "labels to apply to the backup storage location")
|
||||
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.AccessMode,
|
||||
"access-mode",
|
||||
@@ -122,6 +126,18 @@ func (o *CreateOptions) Complete(args []string, f client.Factory) error {
|
||||
func (o *CreateOptions) Run(c *cobra.Command, f client.Factory) error {
|
||||
var backupSyncPeriod, validationFrequency *metav1.Duration
|
||||
|
||||
var caCertData []byte
|
||||
if o.CACertFile != "" {
|
||||
realPath, err := filepath.Abs(o.CACertFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
caCertData, err = ioutil.ReadFile(realPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if c.Flags().Changed("backup-sync-period") {
|
||||
backupSyncPeriod = &metav1.Duration{Duration: o.BackupSyncPeriod}
|
||||
}
|
||||
@@ -142,6 +158,7 @@ func (o *CreateOptions) Run(c *cobra.Command, f client.Factory) error {
|
||||
ObjectStorage: &velerov1api.ObjectStorageLocation{
|
||||
Bucket: o.Bucket,
|
||||
Prefix: o.Prefix,
|
||||
CACert: caCertData,
|
||||
},
|
||||
},
|
||||
Config: o.Config.Data(),
|
||||
|
||||
Reference in New Issue
Block a user