Skip to content

Commit a125a45

Browse files
committed
Save snapshot request to object store
1 parent fcd4611 commit a125a45

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

pkg/snapshot/client.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ import (
1616
"k8s.io/klog/v2"
1717
)
1818

19+
const (
20+
RequestStoreKey = "/vcluster/snapshot/request"
21+
)
22+
1923
type Client struct {
24+
Request *Request
2025
Options Options
2126
skipKeys map[string]struct{}
2227
}
@@ -145,6 +150,19 @@ func (c *Client) writeSnapshot(ctx context.Context, etcdClient etcd.Client, obje
145150
}
146151
}
147152

153+
// write the snapshot request
154+
if c.Request != nil {
155+
requestBytes, err := json.Marshal(c.Request)
156+
if err != nil {
157+
return fmt.Errorf("failed to marshal snapshot request: %w", err)
158+
}
159+
key := fmt.Sprintf("%s/%s", RequestStoreKey, APIVersion)
160+
err = writeKeyValue(tarWriter, []byte(key), requestBytes)
161+
if err != nil {
162+
return fmt.Errorf("failed to snapshot snapshot request: %w", err)
163+
}
164+
}
165+
148166
// now write the snapshot
149167
backedUpKeys := 0
150168
for {

pkg/snapshot/controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ func (c *Reconciler) reconcileCreatingEtcdBackup(ctx context.Context, configMap
308308
// Create and save the snapshot! 💾
309309
c.logger.Infof("Creating vCluster snapshot in storage type %q", snapshotOptions.Type)
310310
snapshotClient := &Client{
311+
Request: snapshotRequest,
311312
Options: *snapshotOptions,
312313
}
313314
if !c.isHostMode {

pkg/snapshot/request.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import (
1313
)
1414

1515
const (
16+
// APIVersion is the snapshot request API version.
17+
APIVersion = "v1beta1"
18+
1619
RequestKey = "snapshotRequest"
1720
OptionsKey = "snapshotOptions"
1821

pkg/snapshot/restoreclient.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ func (o *RestoreClient) Run(ctx context.Context) (retErr error) {
128128
}
129129
}
130130

131+
// check snapshot request
132+
if strings.HasPrefix(string(key), RequestStoreKey) {
133+
klog.Infof("Found snapshot request: %s", string(value))
134+
continue
135+
}
136+
131137
// transform pods to make sure they are not deleted on start
132138
if strings.HasPrefix(string(key), "/registry/pods/") {
133139
// we need to only do this in shared nodes mode as otherwise kubelet will not update the status correctly

0 commit comments

Comments
 (0)