Add volume snapshot CLI get command
Signed-off-by: Wayne Witzel III <wayne@riotousliving.com>pull/948/head
parent
f20342aab9
commit
ffc612ac13
|
@ -35,6 +35,7 @@ import (
|
||||||
"github.com/heptio/ark/pkg/cmd/cli/restic"
|
"github.com/heptio/ark/pkg/cmd/cli/restic"
|
||||||
"github.com/heptio/ark/pkg/cmd/cli/restore"
|
"github.com/heptio/ark/pkg/cmd/cli/restore"
|
||||||
"github.com/heptio/ark/pkg/cmd/cli/schedule"
|
"github.com/heptio/ark/pkg/cmd/cli/schedule"
|
||||||
|
"github.com/heptio/ark/pkg/cmd/cli/snapshotlocation"
|
||||||
"github.com/heptio/ark/pkg/cmd/server"
|
"github.com/heptio/ark/pkg/cmd/server"
|
||||||
runplugin "github.com/heptio/ark/pkg/cmd/server/plugin"
|
runplugin "github.com/heptio/ark/pkg/cmd/server/plugin"
|
||||||
"github.com/heptio/ark/pkg/cmd/version"
|
"github.com/heptio/ark/pkg/cmd/version"
|
||||||
|
@ -73,6 +74,7 @@ operations can also be performed as 'ark backup get' and 'ark schedule create'.`
|
||||||
restic.NewCommand(f),
|
restic.NewCommand(f),
|
||||||
bug.NewCommand(),
|
bug.NewCommand(),
|
||||||
backuplocation.NewCommand(f),
|
backuplocation.NewCommand(f),
|
||||||
|
snapshotlocation.NewCommand(f),
|
||||||
)
|
)
|
||||||
|
|
||||||
// add the glog flags
|
// add the glog flags
|
||||||
|
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"github.com/heptio/ark/pkg/cmd/cli/backuplocation"
|
"github.com/heptio/ark/pkg/cmd/cli/backuplocation"
|
||||||
"github.com/heptio/ark/pkg/cmd/cli/restore"
|
"github.com/heptio/ark/pkg/cmd/cli/restore"
|
||||||
"github.com/heptio/ark/pkg/cmd/cli/schedule"
|
"github.com/heptio/ark/pkg/cmd/cli/schedule"
|
||||||
|
"github.com/heptio/ark/pkg/cmd/cli/snapshotlocation"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewCommand(f client.Factory) *cobra.Command {
|
func NewCommand(f client.Factory) *cobra.Command {
|
||||||
|
@ -45,11 +46,15 @@ func NewCommand(f client.Factory) *cobra.Command {
|
||||||
backupLocationCommand := backuplocation.NewGetCommand(f, "backup-locations")
|
backupLocationCommand := backuplocation.NewGetCommand(f, "backup-locations")
|
||||||
backupLocationCommand.Aliases = []string{"backup-location"}
|
backupLocationCommand.Aliases = []string{"backup-location"}
|
||||||
|
|
||||||
|
snapshotLocationCommand := snapshotlocation.NewGetCommand(f, "snapshot-locations")
|
||||||
|
snapshotLocationCommand.Aliases = []string{"snapshot-location"}
|
||||||
|
|
||||||
c.AddCommand(
|
c.AddCommand(
|
||||||
backupCommand,
|
backupCommand,
|
||||||
scheduleCommand,
|
scheduleCommand,
|
||||||
restoreCommand,
|
restoreCommand,
|
||||||
backupLocationCommand,
|
backupLocationCommand,
|
||||||
|
snapshotLocationCommand,
|
||||||
)
|
)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
Copyright 2018 the Heptio Ark contributors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package snapshotlocation
|
||||||
|
|
||||||
|
import (
|
||||||
|
api "github.com/heptio/ark/pkg/apis/ark/v1"
|
||||||
|
"github.com/heptio/ark/pkg/client"
|
||||||
|
"github.com/heptio/ark/pkg/cmd"
|
||||||
|
"github.com/heptio/ark/pkg/cmd/util/output"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewGetCommand(f client.Factory, use string) *cobra.Command {
|
||||||
|
var listOptions metav1.ListOptions
|
||||||
|
c := &cobra.Command{
|
||||||
|
Use: use,
|
||||||
|
Short: "Get snapshot locations",
|
||||||
|
Run: func(c *cobra.Command, args []string) {
|
||||||
|
err := output.ValidateFlags(c)
|
||||||
|
cmd.CheckError(err)
|
||||||
|
arkClient, err := f.Client()
|
||||||
|
cmd.CheckError(err)
|
||||||
|
var locations *api.VolumeSnapshotLocationList
|
||||||
|
if len(args) > 0 {
|
||||||
|
locations = new(api.VolumeSnapshotLocationList)
|
||||||
|
for _, name := range args {
|
||||||
|
location, err := arkClient.Ark().VolumeSnapshotLocations(f.Namespace()).Get(name, metav1.GetOptions{})
|
||||||
|
cmd.CheckError(err)
|
||||||
|
locations.Items = append(locations.Items, *location)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
locations, err = arkClient.ArkV1().VolumeSnapshotLocations(f.Namespace()).List(listOptions)
|
||||||
|
cmd.CheckError(err)
|
||||||
|
}
|
||||||
|
_, err = output.PrintWithFormat(c, locations)
|
||||||
|
cmd.CheckError(err)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
c.Flags().StringVarP(&listOptions.LabelSelector, "selector", "l", listOptions.LabelSelector, "only show items matching this label selector")
|
||||||
|
output.BindFlags(c.Flags())
|
||||||
|
return c
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
Copyright 2018 the Heptio Ark contributors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package snapshotlocation
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/heptio/ark/pkg/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewCommand(f client.Factory) *cobra.Command {
|
||||||
|
c := &cobra.Command{
|
||||||
|
Use: "snapshot-location",
|
||||||
|
Short: "Work with snapshot locations",
|
||||||
|
Long: "Work with snapshot locations",
|
||||||
|
}
|
||||||
|
|
||||||
|
c.AddCommand(
|
||||||
|
NewGetCommand(f, "get"),
|
||||||
|
)
|
||||||
|
|
||||||
|
return c
|
||||||
|
}
|
Loading…
Reference in New Issue