Skip to content

Commit b8172d2

Browse files
committed
Add--include-volumes flag to vcluster snapshot create
1 parent b843d29 commit b8172d2

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

cmd/vclusterctl/cmd/snapshot/create.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import (
1212

1313
type CreateCmd struct {
1414
*flags.GlobalFlags
15-
Snapshot snapshot.Options
16-
Log log.Logger
15+
Snapshot snapshot.Options
16+
IncludeVolumes bool
17+
Log log.Logger
1718
}
1819

1920
func NewCreateCmd(globalFlags *flags.GlobalFlags) *cobra.Command {
@@ -45,12 +46,13 @@ vcluster snapshot create my-vcluster container:///data/my-local-snapshot.tar.gz
4546
Args: nameValidator,
4647
ValidArgsFunction: completion.NewValidVClusterNameFunc(globalFlags),
4748
RunE: func(cobraCmd *cobra.Command, args []string) error {
48-
return cli.Snapshot(cobraCmd.Context(), args, cmd.GlobalFlags, &cmd.Snapshot, nil, cmd.Log, true)
49+
return cli.Snapshot(cobraCmd.Context(), args, cmd.GlobalFlags, &cmd.Snapshot, nil, cmd.Log, true, cmd.IncludeVolumes)
4950
},
5051
}
5152

5253
// add storage flags
5354
snapshot.AddFlags(createCmd.Flags(), &cmd.Snapshot)
55+
createCmd.Flags().BoolVarP(&cmd.IncludeVolumes, "include-volumes", "", false, "Create CSI volume snapshots (shared and private nodes only)")
5456

5557
return createCmd
5658
}

cmd/vclusterctl/cmd/snapshot/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ vcluster snapshot my-vcluster container:///data/my-local-snapshot.tar.gz
4848
Args: nameValidator,
4949
ValidArgsFunction: completion.NewValidVClusterNameFunc(globalFlags),
5050
RunE: func(cobraCmd *cobra.Command, args []string) error {
51-
return cli.Snapshot(cobraCmd.Context(), args, rootCmd.GlobalFlags, &rootCmd.Snapshot, &rootCmd.Pod, rootCmd.Log, false)
51+
return cli.Snapshot(cobraCmd.Context(), args, rootCmd.GlobalFlags, &rootCmd.Snapshot, &rootCmd.Pod, rootCmd.Log, false, false)
5252
},
5353
}
5454

pkg/cli/snapshot_helm.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const (
2626
minAsyncSnapshotVersion = "0.29.0-alpha.1"
2727
)
2828

29-
func Snapshot(ctx context.Context, args []string, globalFlags *flags.GlobalFlags, snapshotOpts *snapshot.Options, podOptions *pod.Options, log log.Logger, async bool) error {
29+
func Snapshot(ctx context.Context, args []string, globalFlags *flags.GlobalFlags, snapshotOpts *snapshot.Options, podOptions *pod.Options, log log.Logger, async, includeVolumes bool) error {
3030
// init kube client and vCluster
3131
vCluster, kubeClient, restConfig, err := initSnapshotCommand(ctx, args, globalFlags, snapshotOpts, log)
3232
if err != nil {
@@ -57,7 +57,7 @@ func Snapshot(ctx context.Context, args []string, globalFlags *flags.GlobalFlags
5757
}
5858

5959
// creating snapshot request with 'vcluster snapshot create' command
60-
err = createSnapshotRequest(ctx, vCluster, kubeClient, snapshotOpts, log)
60+
err = createSnapshotRequest(ctx, vCluster, kubeClient, snapshotOpts, log, includeVolumes)
6161
if err != nil {
6262
return err
6363
}
@@ -129,7 +129,7 @@ func initSnapshotCommand(
129129
return vCluster, kubeClient, restClient, nil
130130
}
131131

132-
func createSnapshotRequest(ctx context.Context, vCluster *find.VCluster, kubeClient *kubernetes.Clientset, snapshotOpts *snapshot.Options, log log.Logger) error {
132+
func createSnapshotRequest(ctx context.Context, vCluster *find.VCluster, kubeClient *kubernetes.Clientset, snapshotOpts *snapshot.Options, log log.Logger, includeVolumes bool) error {
133133
vClusterConfig, err := getVClusterConfig(ctx, vCluster, kubeClient, snapshotOpts)
134134
if err != nil {
135135
return err
@@ -156,6 +156,9 @@ func createSnapshotRequest(ctx context.Context, vCluster *find.VCluster, kubeCli
156156
// then create the snapshot request that will be reconciled by the controller
157157
snapshotRequest := &snapshot.Request{
158158
Name: secret.Name,
159+
Spec: snapshot.RequestSpec{
160+
IncludeVolumes: includeVolumes,
161+
},
159162
}
160163
configMap, err := snapshot.CreateSnapshotRequestConfigMap(vCluster.Namespace, vCluster.Name, snapshotRequest)
161164
if err != nil {

pkg/snapshot/controller.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,13 @@ func (c *Reconciler) Register() error {
265265

266266
// reconcileNewRequest updates the snapshot request phase to "InProgress".
267267
func (c *Reconciler) reconcileNewRequest(ctx context.Context, configMap *corev1.ConfigMap, snapshotRequest *Request) error {
268-
snapshotRequest.Status.Phase = RequestPhaseCreatingVolumeSnapshots
269-
c.eventRecorder.Eventf(configMap, corev1.EventTypeNormal, "SnapshotRequestCreatingVolumeSnapshots", "Started to create volume snapshots for snapshot request %s/%s", configMap.Namespace, configMap.Name)
268+
if snapshotRequest.Spec.IncludeVolumes {
269+
snapshotRequest.Status.Phase = RequestPhaseCreatingVolumeSnapshots
270+
c.eventRecorder.Eventf(configMap, corev1.EventTypeNormal, "SnapshotRequestCreatingVolumeSnapshots", "Started to create volume snapshots for snapshot request %s/%s", configMap.Namespace, configMap.Name)
271+
} else {
272+
snapshotRequest.Status.Phase = RequestPhaseCreatingEtcdBackup
273+
c.eventRecorder.Eventf(configMap, corev1.EventTypeNormal, "SnapshotRequestCreatingEtcdBackup", "Started to create etcd backup for snapshot request %s/%s", configMap.Namespace, configMap.Name)
274+
}
270275
return nil
271276
}
272277

pkg/snapshot/request.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ func (r *Request) Done() bool {
3939
}
4040

4141
type RequestSpec struct {
42-
VolumeSnapshots volumes.SnapshotRequest `json:"volumeSnapshots"`
42+
IncludeVolumes bool `json:"includeVolumes,omitempty"`
43+
VolumeSnapshots volumes.SnapshotRequest `json:"volumeSnapshots,omitempty"`
4344
Options Options `json:"-"`
4445
}
4546

0 commit comments

Comments
 (0)