/
update.go
54 lines (41 loc) · 1.37 KB
/
update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package backup
import (
"fmt"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/grtl/mysql-operator/pkg/cmd/util/config"
"github.com/grtl/mysql-operator/pkg/cmd/util/fail"
options "github.com/grtl/mysql-operator/pkg/cmd/util/options"
)
var timeUpd string
var backupUpdateCmd = &cobra.Command{
Use: "update [backupschedule name]",
Short: "Updates a MySQL Backup Schedule",
Long: `Updates a MySQL Backup Schedule. Specify time in CRON style to update your backup schedule
msp backup update "my-backup" --time "59 23 31 DEC Fri *"`,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if timeUpd != "" {
options := options.ExtractOptions(cmd)
err := updateBackup(args[0], options)
if err != nil {
fail.Error(err)
}
}
},
}
func init() {
Cmd.AddCommand(backupUpdateCmd)
backupUpdateCmd.Flags().StringVarP(&timeUpd, "time", "t", "", "CRON style time ")
}
func updateBackup(backupName string, options *options.Options) error {
mySQLBackupInterface := config.GetConfig().Clientset().CrV1().MySQLBackupSchedules(options.Namespace)
mySQLBackup, err := mySQLBackupInterface.Get(backupName, *new(metav1.GetOptions))
if err != nil {
return err
}
mySQLBackup.Spec.Time = timeUpd
fmt.Printf("Updating: %s/%s\n", options.Namespace, backupName)
_, err = mySQLBackupInterface.Update(mySQLBackup)
return err
}