Documentation
¶
Overview ¶
Package login provides login functionality for GPUd.
Index ¶
- Variables
- func Login(ctx context.Context, cfg LoginConfig) error
- func ParseNodeLabelsJSON(raw string) (map[string]string, error)
- func SendRequest(ctx context.Context, endpoint string, req apiv1.LoginRequest) (*apiv1.LoginResponse, error)
- func ValidateNodeLabels(labels map[string]string) error
- type LoginConfig
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyMachineID = errors.New("login request failed with empty machine ID")
ErrEmptyMachineID reports a successful login response that omitted the assigned machine ID.
var ErrEmptyToken = errors.New("token is empty")
ErrEmptyToken reports a login attempt without a registration token.
Functions ¶
func ParseNodeLabelsJSON ¶ added in v0.11.1
ParseNodeLabelsJSON parses a JSON object of Kubernetes label key/value pairs. Keys without the managed prefix are normalized later. Omit the flag to send no nodeLabels field, or pass {} to explicitly clear the labels.
func SendRequest ¶ added in v0.5.0
func SendRequest(ctx context.Context, endpoint string, req apiv1.LoginRequest) (*apiv1.LoginResponse, error)
SendRequest sends a login request and blocks until the login request is processed. It also validates the response field to ensure the login request is processed successfully.
The server responds with the following status codes and messages:
Success: - 200 OK: Login successful. Returns Machine ID and Token.
Failures: - 400 Bad Request:
- Invalid JSON
- Missing Machine Info
- Missing Token
- Missing ID/NodeGroup
- Node Group Mismatch
- 401 Unauthorized: Invalid Token - 403 Forbidden:
- Forbidden Access (machine not owned by workspace)
- Forbidden Node Group (node group not owned by workspace)
- 404 Not Found:
- Machine Not Found
- Node Group Not Found
- 500 Internal Server Error:
- Token Validation Failed
- Session Token Error
- Machine Retrieval/Creation/Update Errors
- Node Group Error
- ID Generation Error
func ValidateNodeLabels ¶ added in v0.11.1
ValidateNodeLabels validates the final Kubernetes label keys and values that GPUd sends during login, after managed-prefix normalization has been applied. This means the Kubernetes qualified-name length checks run against the fully prefixed key.
Types ¶
type LoginConfig ¶ added in v0.9.0
type LoginConfig struct {
Token string
Endpoint string
MachineID string // optional: can be empty
NodeGroup string // optional
// MachineIDOverwrite, when true, allows an explicitly-supplied MachineID that
// differs from the locally-persisted one to replace it: the persisted login
// identity (machine ID + session token, in the metadata table) is discarded
// and the next login checks in using the supplied MachineID. Health/system
// state (reboot history, events) in other tables is preserved.
//
// When false (the default), a differing MachineID is rejected with an error
// instead of silently retargeting the node. This is the safe default for
// host/systemd installs; the container/DaemonSet pattern sets it true so a
// node re-enrolled with a new machine object checks in automatically.
MachineIDOverwrite bool
// RefreshSessionToken, when true, forces a fresh login on every start even
// when a machine ID is already persisted -- instead of taking the "skip login"
// fast path and reusing the persisted session token.
//
// The control plane looks up the current workspace-scoped session token on
// every successful login, so re-login persists the token currently served by
// the control plane. Re-login requires the caller-provided registration token,
// which GPUd does not persist. Keep this false outside BYOK deployments that
// inject a valid registration token on every start.
RefreshSessionToken bool
DataDir string
// GPUCount is the number of GPUs to be reported to the control plane.
// If not specified, the control plane will use the detected number of GPUs.
GPUCount string
// NodeLabels contains Kubernetes label key/value pairs to attach during login.
// Keys without the managed "user.node.lepton.ai/" prefix are normalized before validation and sending.
// Nil means "leave labels unchanged"; an empty but non-nil map means "clear labels".
NodeLabels map[string]string
PublicIP string // optional: overrides detected public IP
PrivateIP string // optional: overrides detected private IP
}
LoginConfig contains the configuration for the login operation.