login

package
v0.12.11 Latest Latest
Warning

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

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

Documentation

Overview

Package login provides login functionality for GPUd.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyMachineID = errors.New("login request failed with empty machine ID")

ErrEmptyMachineID reports a successful login response that omitted the assigned machine ID.

View Source
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

func ParseNodeLabelsJSON added in v0.11.1

func ParseNodeLabelsJSON(raw string) (map[string]string, error)

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

func ValidateNodeLabels(labels map[string]string) error

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. This handles workspace token rotation at the cost of one
	// extra login round-trip per start. The container/DaemonSet pattern sets it
	// true; the default (false) preserves the skip-login optimization for
	// host/systemd installs.
	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.

Jump to

Keyboard shortcuts

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