Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions cmd/tarmak/cmd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,31 @@ func clusterKubeconfigFlags(fs *flag.FlagSet) {
)
}

func clusterSnapshotEtcdRestoreFlags(fs *flag.FlagSet) {
store := &globalFlags.Cluster.Snapshot.Etcd.Restore

fs.StringVar(
&store.K8sMain,
consts.RestoreK8sMainFlagName,
"",
"location of k8s-main snapshot backup",
)

fs.StringVar(
&store.K8sEvents,
consts.RestoreK8sEventsFlagName,
"",
"location of k8s-events snapshot backup",
)

fs.StringVar(
&store.Overlay,
consts.RestoreOverlayFlagName,
"",
"location of overlay snapshot backup",
)
}

func init() {
RootCmd.AddCommand(clusterCmd)
}
2 changes: 0 additions & 2 deletions cmd/tarmak/cmd/cluster_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ var clusterApplyCmd = &cobra.Command{
},
Run: func(cmd *cobra.Command, args []string) {
t := tarmak.New(globalFlags)

applyCmd := t.NewCmdTarmak(cmd.Flags(), args)

t.CancellationContext().WaitOrCancel(applyCmd.Apply)
},
}
Expand Down
18 changes: 1 addition & 17 deletions cmd/tarmak/cmd/cluster_instances_ssh.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
// Copyright Jetstack Ltd. See LICENSE for details.
package cmd

import (
"github.com/spf13/cobra"

"github.com/jetstack/tarmak/pkg/tarmak"
)

var clusterInstancesSshCmd = &cobra.Command{
Use: "ssh [instance alias]",
Short: "Log into an instance with SSH",
Run: func(cmd *cobra.Command, args []string) {
t := tarmak.New(globalFlags)
defer t.Cleanup()
t.SSHPassThrough(args)
},
}

func init() {
clusterInstancesCmd.AddCommand(clusterInstancesSshCmd)
clusterInstancesCmd.AddCommand(clusterSshCmd)
}
15 changes: 15 additions & 0 deletions cmd/tarmak/cmd/cluster_snapshot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright Jetstack Ltd. See LICENSE for details.
package cmd

import (
"github.com/spf13/cobra"
)

var clusterSnapshotCmd = &cobra.Command{
Use: "snapshot",
Short: "Manage snapshots of remote consul and etcd clusters",
}

func init() {
clusterCmd.AddCommand(clusterSnapshotCmd)
}
15 changes: 15 additions & 0 deletions cmd/tarmak/cmd/cluster_snapshot_consul.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright Jetstack Ltd. See LICENSE for details.
package cmd

import (
"github.com/spf13/cobra"
)

var clusterSnapshotConsulCmd = &cobra.Command{
Use: "consul",
Short: "Manage snapshots on remote consul clusters",
}

func init() {
clusterSnapshotCmd.AddCommand(clusterSnapshotConsulCmd)
}
32 changes: 32 additions & 0 deletions cmd/tarmak/cmd/cluster_snapshot_consul_restore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright Jetstack Ltd. See LICENSE for details.
package cmd

import (
"fmt"

"github.com/spf13/cobra"

"github.com/jetstack/tarmak/pkg/tarmak"
"github.com/jetstack/tarmak/pkg/tarmak/snapshot/consul"
)

var clusterSnapshotConsulRestoreCmd = &cobra.Command{
Use: "restore [source path]",
Short: "restore consul cluster with source snapshot",
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return fmt.Errorf("expecting single source path, got=%d", len(args))
}

return nil
},
Run: func(cmd *cobra.Command, args []string) {
t := tarmak.New(globalFlags)
s := consul.New(t, args[0])
t.CancellationContext().WaitOrCancel(t.NewCmdSnapshot(cmd.Flags(), args, s).Restore)
},
}

func init() {
clusterSnapshotConsulCmd.AddCommand(clusterSnapshotConsulRestoreCmd)
}
32 changes: 32 additions & 0 deletions cmd/tarmak/cmd/cluster_snapshot_consul_save.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright Jetstack Ltd. See LICENSE for details.
package cmd

import (
"fmt"

"github.com/spf13/cobra"

"github.com/jetstack/tarmak/pkg/tarmak"
"github.com/jetstack/tarmak/pkg/tarmak/snapshot/consul"
)

var clusterSnapshotConsulSaveCmd = &cobra.Command{
Use: "save [target path]",
Short: "save consul cluster snapshot to target path",
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return fmt.Errorf("expecting single target path, got=%d", len(args))
}

return nil
},
Run: func(cmd *cobra.Command, args []string) {
t := tarmak.New(globalFlags)
s := consul.New(t, args[0])
t.CancellationContext().WaitOrCancel(t.NewCmdSnapshot(cmd.Flags(), args, s).Save)
},
}

func init() {
clusterSnapshotConsulCmd.AddCommand(clusterSnapshotConsulSaveCmd)
}
15 changes: 15 additions & 0 deletions cmd/tarmak/cmd/cluster_snapshot_etcd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright Jetstack Ltd. See LICENSE for details.
package cmd

import (
"github.com/spf13/cobra"
)

var clusterSnapshotEtcdCmd = &cobra.Command{
Use: "etcd",
Short: "Manage snapshots on remote etcd clusters",
}

func init() {
clusterSnapshotCmd.AddCommand(clusterSnapshotEtcdCmd)
}
42 changes: 42 additions & 0 deletions cmd/tarmak/cmd/cluster_snapshot_etcd_restore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright Jetstack Ltd. See LICENSE for details.
package cmd

import (
"fmt"

"github.com/spf13/cobra"

"github.com/jetstack/tarmak/pkg/tarmak"
"github.com/jetstack/tarmak/pkg/tarmak/snapshot/etcd"
"github.com/jetstack/tarmak/pkg/tarmak/utils/consts"
)

var clusterSnapshotEtcdRestoreCmd = &cobra.Command{
Use: "restore",
Short: "restore etcd cluster with source snapshots",
PreRunE: func(cmd *cobra.Command, args []string) error {
if !cmd.Flags().Changed(consts.RestoreK8sMainFlagName) &&
!cmd.Flags().Changed(consts.RestoreK8sEventsFlagName) &&
!cmd.Flags().Changed(consts.RestoreOverlayFlagName) {

return fmt.Errorf("expecting at least one set flag of [%s %s %s]",
consts.RestoreK8sMainFlagName,
consts.RestoreK8sEventsFlagName,
consts.RestoreOverlayFlagName,
)
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
t := tarmak.New(globalFlags)
s := etcd.New(t, "")
t.CancellationContext().WaitOrCancel(t.NewCmdSnapshot(cmd.Flags(), args, s).Restore)
},
}

func init() {
clusterSnapshotEtcdRestoreFlags(
clusterSnapshotEtcdRestoreCmd.PersistentFlags(),
)
clusterSnapshotEtcdCmd.AddCommand(clusterSnapshotEtcdRestoreCmd)
}
26 changes: 26 additions & 0 deletions cmd/tarmak/cmd/cluster_snapshot_etcd_save.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright Jetstack Ltd. See LICENSE for details.
package cmd

import (
"github.com/spf13/cobra"

"github.com/jetstack/tarmak/pkg/tarmak"
"github.com/jetstack/tarmak/pkg/tarmak/snapshot/etcd"
)

var clusterSnapshotEtcdSaveCmd = &cobra.Command{
Use: "save [target path prefix]",
Short: "save etcd snapshot to target path prefix, i.e 'backup-'",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
args = []string{""}
}
t := tarmak.New(globalFlags)
s := etcd.New(t, args[0])
t.CancellationContext().WaitOrCancel(t.NewCmdSnapshot(cmd.Flags(), args, s).Save)
},
}

func init() {
clusterSnapshotEtcdCmd.AddCommand(clusterSnapshotEtcdSaveCmd)
}
14 changes: 11 additions & 3 deletions cmd/tarmak/cmd/cluster_ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,26 @@
package cmd

import (
"errors"
"strings"

"github.com/spf13/cobra"

"github.com/jetstack/tarmak/pkg/tarmak"
)

var clusterSshCmd = &cobra.Command{
Use: "ssh [instance alias]",
Use: "ssh [instance alias] [optional ssh arguments]",
Short: "Log into an instance with SSH",
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("expecting an instance aliases argument")
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
t := tarmak.New(globalFlags)
defer t.Cleanup()
t.SSHPassThrough(args)
t.Perform(t.SSHPassThrough(args[0], strings.Join(args[1:], " ")))
},
}

Expand Down
56 changes: 56 additions & 0 deletions cmd/tarmak/cmd/tunnel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright Jetstack Ltd. See LICENSE for details.
package cmd

import (
"fmt"
"os"
"time"

"github.com/spf13/cobra"

"github.com/jetstack/tarmak/pkg/tarmak"
)

var tunnelCmd = &cobra.Command{
Use: "tunnel [destination] [destination port] [local port]",
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 3 {
return fmt.Errorf(
"expecting only a destination, destination and local port argument, got=%s", args)
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
t := tarmak.New(globalFlags)
tunnel := t.SSH().Tunnel(args[0], args[1], args[2], false)

retries := 5
for {
err := tunnel.Start()
if err == nil {
t.Log().Infof("tunnel started: %s", args)
break
}

t.Log().Errorf("failed to start tunnel: %s", err)
retries--
if retries == 0 {
t.Log().Error("failed to start tunnel after 5 attempts")
t.Cleanup()
os.Exit(1)
}

time.Sleep(time.Second * 2)
}

time.Sleep(time.Minute * 10)
t.Cleanup()
os.Exit(0)
},
Hidden: true,
DisableFlagParsing: true,
}

func init() {
RootCmd.AddCommand(tunnelCmd)
}
Loading