checkpoint_container.go 849 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package protocol

import (
	"fmt"

	corev1 "k8s.io/api/core/v1"
)

const checkpointWorkerContainerName = "main"

func ResolveCheckpointWorkerContainer(podSpec *corev1.PodSpec) (*corev1.Container, error) {
	if podSpec == nil || len(podSpec.Containers) == 0 {
		return nil, fmt.Errorf("checkpoint job requires at least one container")
	}
	if len(podSpec.Containers) == 1 {
		return &podSpec.Containers[0], nil
	}

	for i := range podSpec.Containers {
		if podSpec.Containers[i].Name == checkpointWorkerContainerName {
			return &podSpec.Containers[i], nil
		}
	}

	return nil, fmt.Errorf("checkpoint job requires a container named %q when multiple containers are present", checkpointWorkerContainerName)
}