Skip to content

Commit

Permalink
Add volume snapshot CLI get command
Browse files Browse the repository at this point in the history
Signed-off-by: Wayne Witzel III <[email protected]>
  • Loading branch information
wwitzel3 authored and skriss committed Oct 17, 2018
1 parent f20342a commit ffc612a
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/cmd/ark/ark.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/heptio/ark/pkg/cmd/cli/restic"
"github.com/heptio/ark/pkg/cmd/cli/restore"
"github.com/heptio/ark/pkg/cmd/cli/schedule"
"github.com/heptio/ark/pkg/cmd/cli/snapshotlocation"
"github.com/heptio/ark/pkg/cmd/server"
runplugin "github.com/heptio/ark/pkg/cmd/server/plugin"
"github.com/heptio/ark/pkg/cmd/version"
Expand Down Expand Up @@ -73,6 +74,7 @@ operations can also be performed as 'ark backup get' and 'ark schedule create'.`
restic.NewCommand(f),
bug.NewCommand(),
backuplocation.NewCommand(f),
snapshotlocation.NewCommand(f),
)

// add the glog flags
Expand Down
5 changes: 5 additions & 0 deletions pkg/cmd/cli/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/heptio/ark/pkg/cmd/cli/backuplocation"
"github.com/heptio/ark/pkg/cmd/cli/restore"
"github.com/heptio/ark/pkg/cmd/cli/schedule"
"github.com/heptio/ark/pkg/cmd/cli/snapshotlocation"
)

func NewCommand(f client.Factory) *cobra.Command {
Expand All @@ -45,11 +46,15 @@ func NewCommand(f client.Factory) *cobra.Command {
backupLocationCommand := backuplocation.NewGetCommand(f, "backup-locations")
backupLocationCommand.Aliases = []string{"backup-location"}

snapshotLocationCommand := snapshotlocation.NewGetCommand(f, "snapshot-locations")
snapshotLocationCommand.Aliases = []string{"snapshot-location"}

c.AddCommand(
backupCommand,
scheduleCommand,
restoreCommand,
backupLocationCommand,
snapshotLocationCommand,
)

return c
Expand Down
57 changes: 57 additions & 0 deletions pkg/cmd/cli/snapshotlocation/get.go
Original file line number Diff line number Diff line change
@@ -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
}
37 changes: 37 additions & 0 deletions pkg/cmd/cli/snapshotlocation/snapshot_location.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit ffc612a

Please sign in to comment.