Skip to content

Commit

Permalink
feat(cloud): Introduce debug code
Browse files Browse the repository at this point in the history
To be removed after everything is confirmed working

Signed-off-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io>
  • Loading branch information
craciunoiuc committed May 14, 2024
1 parent 52369fa commit 589457c
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions internal/cli/kraft/cloud/volume/import/volimport.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,23 @@ func volumeSanityCheck(ctx context.Context, cli kcvolumes.VolumesService, volID
}

// runVolimport spawns a volume data import instance with the given volume attached.
func runVolimport(ctx context.Context, cli kcinstances.InstancesService, volUUID, authStr string) (instID, fqdn string, err error) {
func runVolimport(ctx context.Context, cli kcinstances.InstancesService, volUUID, authStr string, timeoutS uint64) (instID, fqdn string, err error) {
args := []string{
"-p", strconv.FormatUint(uint64(volimportPort), 10),
"-a", authStr,
}

if timeoutS > 0 {
// Note(craciunoiuc): Add a 10-second buffer to the timeout.
// This is to allow the client to close the connection first.
// Otherwise there is a chance that the volume becomes corrupted.
args = append(args, "-t", strconv.FormatUint(timeoutS+10, 10))
}

crinstResp, err := cli.Create(ctx, kcinstances.CreateRequest{
Image: "official/kraftcloud/volimport:latest",
MemoryMB: ptr(32),
Args: []string{
"-p", strconv.FormatUint(uint64(volimportPort), 10),
"-a", authStr,
},
Image: "sergiu.unikraft.io/volimport-test:latest", // TODO(craciunoiuc): Replace with official image before merging
MemoryMB: ptr(128), // TODO(craciunoiuc): see if it works fine with 64
Args: args,
ServiceGroup: &kcinstances.CreateRequestServiceGroup{
Services: []kcservices.CreateRequestService{{
Port: int(volimportPort),
Expand All @@ -64,6 +73,18 @@ func runVolimport(ctx context.Context, cli kcinstances.InstancesService, volUUID
}
inst, err := crinstResp.FirstOrErr()
if err != nil {
// TODO(craciunoiuc): Uncomment code to ensure deletion
// if inst != nil && inst.Name != "" {
// // Delete the instance if it was created but failed to start.
// crdelResp, err := cli.Delete(ctx, inst.UUID)
// if err != nil {
// return "", "", fmt.Errorf("deleting volume data import instance on fail: %w", err)
// }

// if _, err = crdelResp.FirstOrErr(); err != nil {
// return "", "", fmt.Errorf("deleting volume data import instance on fail: %w", err)
// }
// }
return "", "", fmt.Errorf("creating volume data import instance: %w", err)
}

Expand Down Expand Up @@ -96,13 +117,14 @@ func terminateVolimport(ctx context.Context, icli kcinstances.InstancesService,
return fmt.Errorf("waiting for volume data import instance '%s' to stop: %w", instID, err)
}

delinstResp, err := icli.Delete(ctx, instID)
if err != nil {
return fmt.Errorf("deleting volume data import instance '%s': %w", instID, err)
}
if _, err = delinstResp.FirstOrErr(); err != nil {
return fmt.Errorf("deleting volume data import instance '%s': %w", instID, err)
}
// TODO(craciunoiuc): Uncomment to ensure deletion
// delinstResp, err := icli.Delete(ctx, instID)
// if err != nil {
// return fmt.Errorf("deleting volume data import instance '%s': %w", instID, err)
// }
// if _, err = delinstResp.FirstOrErr(); err != nil {
// return fmt.Errorf("deleting volume data import instance '%s': %w", instID, err)
// }
return nil
}

Expand Down

0 comments on commit 589457c

Please sign in to comment.