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 Login ¶
func Login(ctx context.Context, cfg LoginConfig) error
Login performs the login operation with the control plane. This function extracts the core login logic from the original login command.
It handles the following scenarios based on the Login API Specification:
Success: - HTTP 200 OK: Returns Machine ID and Session Token.
Failures: - Validation Errors (HTTP 400):
- Invalid JSON: "cannot parse json, ..."
- Missing Machine Info: "machine info cannot be nil"
- Missing Token: "token is required"
- Missing ID/NodeGroup: "must specify a machine id or a node group id"
- Token Validation Errors:
- Invalid Token (HTTP 401): "invalid token"
- Token Validation Failed (HTTP 500): "failed to validate token"
- Machine/Node Group Validation Errors:
- Machine Not Found (HTTP 404): "machine not found"
- Node Group Mismatch (HTTP 400): "node group does not match"
- Node Group Not Found (HTTP 404): "node group <name> not found"
- Forbidden Access (HTTP 403): "only allowed to check in machines your owned"
- Forbidden Node Group (HTTP 403): "node group is not owned by the workspace"
- Internal Server Errors (HTTP 500):
- Session Token Error: "failed to find session token"
- Machine Retrieval Error: "failed to get machine"
- Update Status Error: "failed to update machine info"
- Node Group Error: "failed to find node group"
- ID Generation Error: "failed to generate id"
- Machine Creation Error: "failed to add machine"
- Login Finalization Error: "failed to login, please try again"
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
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.