Skip to content

Commit

Permalink
Cluster backup: add useClusterSecret option to enable backup command (#…
Browse files Browse the repository at this point in the history
…320)

* Cluster backup: add useClusterSecret option to enable backup command (#321)

* Update internal/cli/command/cluster/integratedservice/services/backup/enable.go

Co-authored-by: Máté Őry <[email protected]>

* fix description

Co-authored-by: Máté Őry <[email protected]>
  • Loading branch information
sancyx and Máté Őry authored Nov 9, 2020
1 parent a6026b9 commit 505bebb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
8 changes: 8 additions & 0 deletions internal/cli/command/cluster/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ type Context interface {
Init(...string) error
ClusterID() int32
ClusterName() string
ClusterCloud() string
}

type clusterContext struct {
id int32
name string
cloud string
banzaiCli cli.Cli
}

Expand All @@ -60,6 +62,10 @@ func (c *clusterContext) ClusterName() string {
return c.name
}

func (c *clusterContext) ClusterCloud() string {
return c.cloud
}

// Init completes the cluster context from the options, env vars, and if possible from the user
func (c *clusterContext) Init(args ...string) error {
pipeline := c.banzaiCli.Client()
Expand All @@ -84,6 +90,7 @@ func (c *clusterContext) Init(args ...string) error {
}

c.name = cluster.Name

return nil
}

Expand Down Expand Up @@ -115,6 +122,7 @@ func (c *clusterContext) Init(args ...string) error {
for _, cluster := range clusters {
if c.name == cluster.Name {
c.id = cluster.Id
c.cloud = cluster.Cloud
return nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/spf13/cobra"

"github.com/banzaicloud/banzai-cli/internal/cli"
clustercontext "github.com/banzaicloud/banzai-cli/internal/cli/command/cluster/context"
"github.com/banzaicloud/banzai-cli/internal/cli/command/cluster/context"
)

const (
Expand Down Expand Up @@ -126,7 +126,7 @@ func enableService(banzaiCli cli.Cli, options enableOptions) error {

var request pipeline.EnableArkRequest
if options.filePath == "" && banzaiCli.Interactive() {
if request, err = buildEnableRequestInteractively(banzaiCli); err != nil {
if request, err = buildEnableRequestInteractively(banzaiCli, options); err != nil {
return errors.WrapIf(err, "failed to build enable backup service request interactively")
}
} else {
Expand Down Expand Up @@ -164,7 +164,7 @@ func readEnableReqFromFileOrStdin(filePath string, req *pipeline.EnableArkReques
return nil
}

func buildEnableRequestInteractively(banzaiCli cli.Cli) (pipeline.EnableArkRequest, error) {
func buildEnableRequestInteractively(banzaiCli cli.Cli, options enableOptions) (pipeline.EnableArkRequest, error) {
var scheduleLabel string
var ttlLabel string

Expand Down Expand Up @@ -223,12 +223,29 @@ func buildEnableRequestInteractively(banzaiCli cli.Cli) (pipeline.EnableArkReque
return pipeline.EnableArkRequest{}, errors.WrapIf(err, "failed to get bucket")
}

useClusterSecret := false
if options.ClusterCloud() == amazonType {
err = input.DoQuestions([]input.QuestionMaker{
input.QuestionConfirm{
QuestionBase: input.QuestionBase{
Message: "Deploy cluster secret to give access for Velero to make volume snapshots",
Help: "This option deploys the cloud provider secret used for creating this cluster to the cluster itself. In case you are not deploying cluster secret you must add snapshot permissions to your node instance role."},
DefaultValue: false,
Output: &useClusterSecret,
},
})
if err != nil {
return pipeline.EnableArkRequest{}, errors.WrapIf(err, "error during getting useClusterSecret option")
}
}

return pipeline.EnableArkRequest{
Cloud: bucketInfo.provider,
BucketName: bucketInfo.name,
Schedule: selectedSchedule,
Ttl: selectedTTL,
SecretId: bucketInfo.secretID,
UseClusterSecret: useClusterSecret,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/cli/command/cluster/restore/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func newCreateCommand(banzaiCli cli.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "create",
Aliases: []string{"c"},
Short: "Restore backup into a new cluster",
Short: "Restore backup to the cluster",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
Expand Down

0 comments on commit 505bebb

Please sign in to comment.