Documentation
¶
Index ¶
- Constants
- func BuildObject(adapter Adapter, name, namespace string, spec *nvcrev1alpha1.WorkloadSpec, ...) (client.Object, error)
- func EnsureLauncherTarget(trainJobSpec *trainerv1alpha1.TrainJobSpec)
- func HasLauncherTarget(spec *nvcrev1alpha1.WorkloadSpec) bool
- func InsertConsistentLabel(labels map[string]string, key, value, fieldPath string) (map[string]string, error)
- func LabelsOf(md *nvcrev1alpha1.WorkloadMetadata) map[string]string
- func MergeLabels(base, overlay map[string]string) map[string]string
- func MetadataFrom(labels map[string]string) *nvcrev1alpha1.WorkloadMetadata
- func ReservedLabelKey(key string) bool
- func SetImagePullSecrets(trainJobSpec *trainerv1alpha1.TrainJobSpec, ...)
- func ValidateLabels(labels map[string]string, fieldPath string) error
- type Adapter
- type TrainJobAdapter
- func (a *TrainJobAdapter) Build(name, namespace string, spec *nvcrev1alpha1.WorkloadSpec) (client.Object, error)
- func (a *TrainJobAdapter) GVK() schema.GroupVersionKind
- func (a *TrainJobAdapter) GetStatus(obj client.Object) (*WorkloadStatus, error)
- func (a *TrainJobAdapter) InjectPodLabel(spec *nvcrev1alpha1.WorkloadSpec, key, value string)
- func (a *TrainJobAdapter) NewObject() client.Object
- func (a *TrainJobAdapter) NodesRequired(spec *nvcrev1alpha1.WorkloadSpec) (int, error)
- func (a *TrainJobAdapter) SetNodeAffinity(spec *nvcrev1alpha1.WorkloadSpec, affinity *corev1.NodeAffinity)
- func (a *TrainJobAdapter) SetNodeSelector(spec *nvcrev1alpha1.WorkloadSpec, selector map[string]string)
- func (a *TrainJobAdapter) SetNumNodes(spec *nvcrev1alpha1.WorkloadSpec, numNodes int)
- func (a *TrainJobAdapter) SetTolerations(spec *nvcrev1alpha1.WorkloadSpec, tolerations []corev1.Toleration)
- type WorkloadPhase
- type WorkloadStatus
Constants ¶
const ( // LabelKeyManagedBy marks the generated workload as NVCRE-managed and // ReservedLabelPrefix covers the keys that associate it with its Job. // The Job controller owns both; a user workload label may not set them. LabelKeyManagedBy = "app.kubernetes.io/managed-by" ReservedLabelPrefix = "nvcre.nvidia.com/" // MaxLabels bounds a single workloadMetadata.labels map. It mirrors the // maxProperties in the CRD schema so a map composed from several levels, // which no single admission rule ever sees whole, is held to the same // limit. MaxLabels = 32 )
const ( // RuntimePatchManager is the manager key for NVCRE controller-owned RuntimePatches. RuntimePatchManager = "nvcre.nvidia.com/controller" LauncherJobName = "launcher" NodeJobName = "node" )
Variables ¶
This section is empty.
Functions ¶
func BuildObject ¶ added in v0.5.0
func BuildObject( adapter Adapter, name, namespace string, spec *nvcrev1alpha1.WorkloadSpec, md *nvcrev1alpha1.WorkloadMetadata, ) (client.Object, error)
BuildObject constructs the framework workload object for spec and applies md's labels to it. It is the one construction seam shared by Job reconciliation and dry-run rendering, so the object the controller submits and the object the dry run validates cannot drift apart.
Adapter.Build stays responsible for the framework-specific typed object. Object labels are handled here instead of behind the Adapter interface because every workload kind exposes them identically through client.Object, so no adapter needs label-specific code. Adapter-produced labels with unrelated keys are preserved. For a requested key the adapter already set, an identical value is accepted and a different value is an error: neither side silently wins.
Only user-requested metadata is applied. The controller-owned identification labels and the owner reference remain the Job controller's to overlay afterwards.
func EnsureLauncherTarget ¶
func EnsureLauncherTarget(trainJobSpec *trainerv1alpha1.TrainJobSpec)
EnsureLauncherTarget registers the worker and launcher replicated jobs in the controller-owned RuntimePatch. SetNodeAffinity and SetTolerations derive their targets from existing runtimePatches (allTargetJobs), and the Workflow controller's blanket MPI toleration is gated on HasLauncherTarget — so an MPI TrainJob without a launcher entry gets its launcher pod scheduled with no node pinning and no tolerations. Catalog MPI entries satisfy this contract with an explicit bare `- name: launcher` runtimePatch entry; MPI WorkloadRuns build their TrainJob programmatically and must register the launcher here. The bare entries are a no-op for the trainer's patch merge.
func HasLauncherTarget ¶
func HasLauncherTarget(spec *nvcrev1alpha1.WorkloadSpec) bool
HasLauncherTarget reports whether the workload spec contains an MPI launcher target in its runtimePatches. Used by the workflow controller to decide whether to apply global tolerations (only MPI workloads need them).
func InsertConsistentLabel ¶ added in v0.5.0
func InsertConsistentLabel( labels map[string]string, key, value, fieldPath string, ) (map[string]string, error)
InsertConsistentLabel returns labels with key=value present, following the insert/same/conflict rule NVCRE uses wherever it derives a label the user may also have written: a missing key is inserted, an identical value is accepted so the merge is idempotent, and a different value is a conflict reporting the key, both values, and fieldPath. labels is never mutated.
func LabelsOf ¶ added in v0.5.0
func LabelsOf(md *nvcrev1alpha1.WorkloadMetadata) map[string]string
LabelsOf returns md's labels as a plain string map. The result is always a fresh copy, so a caller composing labels cannot write back into the API object it read them from. Absent metadata and an empty map both yield nil, which keeps an unconfigured path rendering exactly as it did before.
func MergeLabels ¶ added in v0.5.0
MergeLabels returns base overlaid with overlay, per key. Neither argument is mutated: catalog templates and API objects are shared, so composing through a shared map reference would leak the composition back into its source. An empty overlay adds nothing, and an empty string is a real label value, not a deletion — there is no deletion syntax. The result is nil when empty.
func MetadataFrom ¶ added in v0.5.0
func MetadataFrom(labels map[string]string) *nvcrev1alpha1.WorkloadMetadata
MetadataFrom wraps a label map as workload metadata, returning nil when there is nothing to set so a path that resolved no labels stays absent rather than gaining an empty object. The map is copied.
func ReservedLabelKey ¶ added in v0.5.0
ReservedLabelKey reports whether key is one the controller owns on the generated workload object.
func SetImagePullSecrets ¶
func SetImagePullSecrets(trainJobSpec *trainerv1alpha1.TrainJobSpec, secrets []corev1.LocalObjectReference)
SetImagePullSecrets applies imagePullSecrets to the worker replicated job via RuntimePatches.
func ValidateLabels ¶ added in v0.5.0
ValidateLabels mirrors the CRD schema's admission rules for a workloadMetadata.labels map. Admission already covers every value that arrives through the API, but two cases need this: offline `nvcrectl render` never reaches an API server, and a map composed from global, per-category and derived queue labels is not the map any single object was admitted with. fieldPath names the offending field in the error.
Keys are visited in sorted order so a map with several problems always reports the same one.
Types ¶
type Adapter ¶
type Adapter interface {
// GVK returns the GroupVersionKind of the workload type.
GVK() schema.GroupVersionKind
// NewObject returns a new empty typed object (for Get/Delete).
NewObject() client.Object
// Build creates a fully typed workload object from the WorkloadSpec.
// The name and namespace are set on the returned object.
Build(name, namespace string, spec *nvcrev1alpha1.WorkloadSpec) (client.Object, error)
// InjectPodLabel ensures the given label reaches pod templates.
// Mutates spec in-place — call on a DeepCopy before Build.
InjectPodLabel(spec *nvcrev1alpha1.WorkloadSpec, key, value string)
// SetNodeSelector sets nodeSelector on the workload's pod templates.
// Mutates spec in-place — call on a DeepCopy before Build.
SetNodeSelector(spec *nvcrev1alpha1.WorkloadSpec, selector map[string]string)
// SetNodeAffinity sets node affinity on the workload's pod templates.
// Mutates spec in-place — call on a DeepCopy before Build.
SetNodeAffinity(spec *nvcrev1alpha1.WorkloadSpec, affinity *corev1.NodeAffinity)
// SetTolerations appends tolerations to the workload's pod templates.
// Mutates spec in-place — call on a DeepCopy before Build.
SetTolerations(spec *nvcrev1alpha1.WorkloadSpec, tolerations []corev1.Toleration)
// NodesRequired returns the number of nodes required by the workload spec.
// This is auto-detected from the replica count in the workload definition.
NodesRequired(spec *nvcrev1alpha1.WorkloadSpec) (int, error)
// SetNumNodes overrides the number of nodes/replicas in the workload spec.
// Used by bisection to match the workload's node count to the group size,
// which changes each round. Mutates spec in-place.
SetNumNodes(spec *nvcrev1alpha1.WorkloadSpec, numNodes int)
// GetStatus reads typed status conditions and returns a normalized WorkloadStatus.
GetStatus(obj client.Object) (*WorkloadStatus, error)
}
Adapter provides a typed interface for creating and inspecting workloads.
func ForSpec ¶
func ForSpec(spec *nvcrev1alpha1.WorkloadSpec) (Adapter, error)
ForSpec returns the appropriate Adapter for the given WorkloadSpec.
type TrainJobAdapter ¶
type TrainJobAdapter struct{}
TrainJobAdapter implements Adapter for Kubeflow TrainJob.
func (*TrainJobAdapter) Build ¶
func (a *TrainJobAdapter) Build(name, namespace string, spec *nvcrev1alpha1.WorkloadSpec) (client.Object, error)
func (*TrainJobAdapter) GVK ¶
func (a *TrainJobAdapter) GVK() schema.GroupVersionKind
func (*TrainJobAdapter) GetStatus ¶
func (a *TrainJobAdapter) GetStatus(obj client.Object) (*WorkloadStatus, error)
func (*TrainJobAdapter) InjectPodLabel ¶
func (a *TrainJobAdapter) InjectPodLabel(spec *nvcrev1alpha1.WorkloadSpec, key, value string)
func (*TrainJobAdapter) NewObject ¶
func (a *TrainJobAdapter) NewObject() client.Object
func (*TrainJobAdapter) NodesRequired ¶
func (a *TrainJobAdapter) NodesRequired(spec *nvcrev1alpha1.WorkloadSpec) (int, error)
func (*TrainJobAdapter) SetNodeAffinity ¶
func (a *TrainJobAdapter) SetNodeAffinity(spec *nvcrev1alpha1.WorkloadSpec, affinity *corev1.NodeAffinity)
func (*TrainJobAdapter) SetNodeSelector ¶
func (a *TrainJobAdapter) SetNodeSelector(spec *nvcrev1alpha1.WorkloadSpec, selector map[string]string)
func (*TrainJobAdapter) SetNumNodes ¶
func (a *TrainJobAdapter) SetNumNodes(spec *nvcrev1alpha1.WorkloadSpec, numNodes int)
func (*TrainJobAdapter) SetTolerations ¶
func (a *TrainJobAdapter) SetTolerations(spec *nvcrev1alpha1.WorkloadSpec, tolerations []corev1.Toleration)
type WorkloadPhase ¶
type WorkloadPhase string
WorkloadPhase represents the normalized phase of a workload.
const ( // WorkloadPending means the workload resource exists but has not started // running — for example a TrainJob suspended by an admission controller // such as Kueue while it waits for quota. Controllers must not count // pending time against job timeouts or stall detection, and must not // attribute node failures while a workload is pending. WorkloadPending WorkloadPhase = "Pending" WorkloadRunning WorkloadPhase = "Running" WorkloadSucceeded WorkloadPhase = "Succeeded" WorkloadFailed WorkloadPhase = "Failed" )
type WorkloadStatus ¶
type WorkloadStatus struct {
Phase WorkloadPhase
Reason string
Message string
}
WorkloadStatus is the normalized status returned by adapters.