Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Adds consul and etcd save and consul restore
Browse files Browse the repository at this point in the history
Signed-off-by: JoshVanL <vleeuwenjoshua@gmail.com>
  • Loading branch information
JoshVanL committed Jan 21, 2019
1 parent bbeaa49 commit 884d7da
Show file tree
Hide file tree
Showing 30 changed files with 1,485 additions and 3 deletions.
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)
}
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)
}
35 changes: 35 additions & 0 deletions docs/cmd-docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,41 @@ Command line documentation for tarmak, wing and tagging_control commands

generated/cmd/tarmak/tarmak_clusters_set-current

.. toctree::
:maxdepth: 1

generated/cmd/tarmak/tarmak_clusters_snapshot

.. toctree::
:maxdepth: 1

generated/cmd/tarmak/tarmak_clusters_snapshot_consul

.. toctree::
:maxdepth: 1

generated/cmd/tarmak/tarmak_clusters_snapshot_consul_restore

.. toctree::
:maxdepth: 1

generated/cmd/tarmak/tarmak_clusters_snapshot_consul_save

.. toctree::
:maxdepth: 1

generated/cmd/tarmak/tarmak_clusters_snapshot_etcd

.. toctree::
:maxdepth: 1

generated/cmd/tarmak/tarmak_clusters_snapshot_etcd_restore

.. toctree::
:maxdepth: 1

generated/cmd/tarmak/tarmak_clusters_snapshot_etcd_save

.. toctree::
:maxdepth: 1

Expand Down
1 change: 1 addition & 0 deletions docs/generated/cmd/tarmak/tarmak_clusters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ SEE ALSO
* `tarmak clusters list <tarmak_clusters_list.html>`_ - Print a list of clusters
* `tarmak clusters plan <tarmak_clusters_plan.html>`_ - Plan changes on the currently configured cluster
* `tarmak clusters set-current <tarmak_clusters_set-current.html>`_ - Set current cluster in config
* `tarmak clusters snapshot <tarmak_clusters_snapshot.html>`_ - Manage snapshots of remote consul and etcd clusters
* `tarmak clusters ssh <tarmak_clusters_ssh.html>`_ - Log into an instance with SSH

40 changes: 40 additions & 0 deletions docs/generated/cmd/tarmak/tarmak_clusters_snapshot.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.. _tarmak_clusters_snapshot:

tarmak clusters snapshot
------------------------

Manage snapshots of remote consul and etcd clusters

Synopsis
~~~~~~~~


Manage snapshots of remote consul and etcd clusters

Options
~~~~~~~

::

-h, --help help for snapshot

Options inherited from parent commands
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

::

-c, --config-directory string config directory for tarmak's configuration (default "~/.tarmak")
--current-cluster string override the current cluster set in the config
--ignore-missing-public-key-tags ssh_known_hosts ignore missing public key tags on instances, by falling back to populating ssh_known_hosts with the first connection (default true)
--keep-containers do not clean-up terraform/packer containers after running them
--public-api-endpoint Override kubeconfig to point to cluster's public API endpoint
-v, --verbose enable verbose logging
--wing-dev-mode use a bundled wing version rather than a tagged release from GitHub

SEE ALSO
~~~~~~~~

* `tarmak clusters <tarmak_clusters.html>`_ - Operations on clusters
* `tarmak clusters snapshot consul <tarmak_clusters_snapshot_consul.html>`_ - Manage snapshots on remote consul clusters
* `tarmak clusters snapshot etcd <tarmak_clusters_snapshot_etcd.html>`_ - Manage snapshots on remote etcd clusters

40 changes: 40 additions & 0 deletions docs/generated/cmd/tarmak/tarmak_clusters_snapshot_consul.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.. _tarmak_clusters_snapshot_consul:

tarmak clusters snapshot consul
-------------------------------

Manage snapshots on remote consul clusters

Synopsis
~~~~~~~~


Manage snapshots on remote consul clusters

Options
~~~~~~~

::

-h, --help help for consul

Options inherited from parent commands
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

::

-c, --config-directory string config directory for tarmak's configuration (default "~/.tarmak")
--current-cluster string override the current cluster set in the config
--ignore-missing-public-key-tags ssh_known_hosts ignore missing public key tags on instances, by falling back to populating ssh_known_hosts with the first connection (default true)
--keep-containers do not clean-up terraform/packer containers after running them
--public-api-endpoint Override kubeconfig to point to cluster's public API endpoint
-v, --verbose enable verbose logging
--wing-dev-mode use a bundled wing version rather than a tagged release from GitHub

SEE ALSO
~~~~~~~~

* `tarmak clusters snapshot <tarmak_clusters_snapshot.html>`_ - Manage snapshots of remote consul and etcd clusters
* `tarmak clusters snapshot consul restore <tarmak_clusters_snapshot_consul_restore.html>`_ - restore consul cluster with source snapshot
* `tarmak clusters snapshot consul save <tarmak_clusters_snapshot_consul_save.html>`_ - save consul cluster snapshot to target path

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.. _tarmak_clusters_snapshot_consul_restore:

tarmak clusters snapshot consul restore
---------------------------------------

restore consul cluster with source snapshot

Synopsis
~~~~~~~~


restore consul cluster with source snapshot

::

tarmak clusters snapshot consul restore [source path] [flags]

Options
~~~~~~~

::

-h, --help help for restore

Options inherited from parent commands
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

::

-c, --config-directory string config directory for tarmak's configuration (default "~/.tarmak")
--current-cluster string override the current cluster set in the config
--ignore-missing-public-key-tags ssh_known_hosts ignore missing public key tags on instances, by falling back to populating ssh_known_hosts with the first connection (default true)
--keep-containers do not clean-up terraform/packer containers after running them
--public-api-endpoint Override kubeconfig to point to cluster's public API endpoint
-v, --verbose enable verbose logging
--wing-dev-mode use a bundled wing version rather than a tagged release from GitHub

SEE ALSO
~~~~~~~~

* `tarmak clusters snapshot consul <tarmak_clusters_snapshot_consul.html>`_ - Manage snapshots on remote consul clusters

Loading

0 comments on commit 884d7da

Please sign in to comment.