util

package
v0.33.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ResolveClientFunc is stubbable because resolution is the first thing a command does and
	// the only step that contacts the API server before any of the work under test.
	ResolveClientFunc = ResolveClient

	// PrepareUploadFunc is stubbable because it waits for a DataImport to be reconciled and an
	// importer pod to come up, which is the whole of what a test would have to fake a cluster
	// for; the transfer it hands the URL to is the part under test.
	PrepareUploadFunc = PrepareUpload
)

Function pointers for test stubbing.

Functions

func CheckUploadProgress

func CheckUploadProgress(ctx context.Context, httpClient *safeClient.SafeClient, targetURL string) (int64, error)

CheckUploadProgress returns the offset a NEW run should start from, which is zero whenever the importer named none. That reading is right for --resume and wrong in the middle of a transfer: it cannot tell a destination the importer has never seen from one it has already finished, and it answers both with the offset that restarts the upload. Callers deciding what to do after a break ask ProbeUploadState instead.

func CreateDataImport

func CreateDataImport(
	ctx context.Context,
	backend dataapi.Backend,
	name, namespace, ttl string,
	publish, waitForFirstConsumer bool,
	pvcTpl *v1alpha1.PersistentVolumeClaimTemplateSpec,
	rtClient ctrlrtclient.Client,
) error

CreateDataImport creates a DataImport that streams the uploaded bytes into a newly created PVC, in the request shape the resolved backend understands.

backend selects that shape, and there is no shape that satisfies both producers: whichever one is addressed rejects a body written for the other. storage-foundation requires spec.mode plus a spec.pvcTemplate at the root and has no targetRef property; storage-volume-data-manager requires spec.targetRef carrying the same template and has no mode.

func DeleteDataImport

func DeleteDataImport(ctx context.Context, diName, namespace string, rtClient ctrlrtclient.Client) error

func EnsureDataImportPublish added in v0.29.8

func EnsureDataImportPublish(
	ctx context.Context,
	diObj *v1alpha1.DataImport,
	publish bool,
	rtClient ctrlrtclient.Client,
) error

EnsureDataImportPublish patches DataImport.Spec.Publish to match the resolved value. Only upgrades publish: false -> true is patched, true -> false is intentionally skipped to avoid downgrading already-published resources.

func GetDataImport

func GetDataImport(ctx context.Context, diName, namespace string, rtClient ctrlrtclient.Client) (*v1alpha1.DataImport, error)

func GetDataImportWithRestart

func GetDataImportWithRestart(
	ctx context.Context,
	backend dataapi.Backend,
	diName, namespace string,
	rtClient ctrlrtclient.Client,
	log *slog.Logger,
) (*v1alpha1.DataImport, error)

func PostFinished added in v0.32.5

func PostFinished(ctx context.Context, httpClient *safeClient.SafeClient, baseURL string) error

PostFinished signals end-of-upload to the importer (POST <baseURL>/api/v1/finished), which flips the DataImport's serverState to Finished. This is mandatory: the last data chunk (a PUT that fills the device / writes the final file) does NOT finalise on its own, and the controller only sets UploadFinished=True — the gate for rebinding the target and reaching Completed — once serverState is Finished. baseURL is the importer base (status.url / status.publicURL), the same base the /api/v1/{files,block} data endpoint hangs off of.

func PrepareUpload

func PrepareUpload(
	ctx context.Context,
	backend dataapi.Backend,
	diName, namespace string,
	publish bool,
	sClient *safeClient.SafeClient,
	log *slog.Logger,
) (string, string, string, *safeClient.SafeClient, error)

PrepareUpload waits for the import to be usable and returns the data-plane URL, the importer base URL, the volume mode and a client trusting the importer's CA. backend is the group resolved for this run; it builds this function's own control-plane client, which would otherwise default to storage-foundation's group regardless of what the cluster serves.

func ResolveClient added in v0.33.14

func ResolveClient(
	ctx context.Context,
	sClient *safeClient.SafeClient,
	namespace string,
	log *slog.Logger,
) (dataapi.Backend, ctrlrtclient.Client, error)

ResolveClient resolves which of the two producers serves DataImport to this user in this namespace, and returns both the answer and a control-plane client bound to it.

Every `d8 data import` subcommand starts here rather than registering a fixed group, because the same binary ships to clusters that serve only storage-foundation's group, only storage-volume-data-manager's, or both with the user authorized for one of them. The resolved backend is returned alongside the client because the request body differs between the two producers (see CreateDataImport) and because callers that build their own client later (PrepareUpload) must bind it to the same group.

Types

type UploadState added in v0.33.19

type UploadState struct {
	// OffsetKnown is true only when the importer actually named an offset.
	// When it is false, Offset is zero because nothing was said, not because
	// the importer said zero.
	OffsetKnown bool

	// Offset is the resume offset the importer named.
	Offset int64

	// Size is the Content-Length the importer reported, or -1 when it
	// reported none. A destination the importer does not have is reported the
	// same way, deliberately rather than as an accident of the zero value:
	// -1 is a length no upload can declare, so "the importer has nothing
	// here" can never be mistaken for "the importer has all of it" by a
	// caller comparing Size against a size of its own.
	Size int64
}

UploadState is everything a HEAD tells us about an upload destination. The three facts are kept apart because collapsing them loses the one distinction that matters after a broken transfer.

An importer holding a partly uploaded destination names its resume offset in X-Next-Offset. An importer holding a FINISHED one names no offset at all and reports the size — which is why an offset of zero and an absent offset must not read the same: the second means "nothing left to resume", not "start over". Size carries no such meaning on its own for a block destination, whose device reports its full size from creation however little has been written into it, so a caller reading Size has to say what else it is leaning on.

func ProbeUploadState added in v0.33.19

func ProbeUploadState(
	ctx context.Context,
	httpClient *safeClient.SafeClient,
	targetURL string,
) (UploadState, error)

ProbeUploadState asks the importer what it currently holds at targetURL.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL