Skip to content

Commit

Permalink
Add into exec node pods environment variables for CRI tools (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
koct9i authored Jun 17, 2024
1 parent 021b907 commit b3cca0a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
15 changes: 15 additions & 0 deletions pkg/components/exec_node_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ func (n *baseExecNode) doBuildBase() error {
}
setContainerPrivileged(&podSpec.Containers[0])

if envSpec := n.spec.JobEnvironment; envSpec != nil && envSpec.CRI != nil {
n.addEnvironmentForCRITools(&podSpec.Containers[0])
}

for i := range podSpec.InitContainers {
setContainerPrivileged(&podSpec.InitContainers[i])
}
Expand Down Expand Up @@ -107,6 +111,15 @@ func (n *baseExecNode) doBuildBase() error {
return nil
}

func (n *baseExecNode) addEnvironmentForCRITools(container *corev1.Container) {
socketPath := ytconfig.GetContainerdSocketPath(n.spec)
container.Env = append(container.Env, []corev1.EnvVar{
{Name: "CONTAINERD_ADDRESS", Value: socketPath}, // ctr
{Name: "CONTAINERD_NAMESPACE", Value: "k8s.io"}, // ctr
{Name: "CONTAINER_RUNTIME_ENDPOINT", Value: "unix://" + socketPath}, // crictl
}...)
}

func (n *baseExecNode) doBuildCRISidecar(envSpec *ytv1.JobEnvironmentSpec, podSpec *corev1.PodSpec) {
configPath := path.Join(consts.ContainerdConfigMountPoint, consts.ContainerdConfigFileName)

Expand All @@ -128,6 +141,8 @@ func (n *baseExecNode) doBuildCRISidecar(envSpec *ytv1.JobEnvironmentSpec, podSp
},
}

n.addEnvironmentForCRITools(&jobsContainer)

jobsContainer.VolumeMounts = append(jobsContainer.VolumeMounts,
corev1.VolumeMount{
Name: consts.ContainerdConfigVolumeName,
Expand Down
4 changes: 2 additions & 2 deletions pkg/ytconfig/cri.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/ytsaurus/yt-k8s-operator/pkg/consts"
)

func getContainerdSocketPath(spec *ytv1.ExecNodesSpec) string {
func GetContainerdSocketPath(spec *ytv1.ExecNodesSpec) string {
if location := ytv1.FindFirstLocation(spec.Locations, ytv1.LocationTypeImageCache); location != nil {
return path.Join(location.Path, consts.ContainerdSocketName)
}
Expand All @@ -30,7 +30,7 @@ func (g *NodeGenerator) GetContainerdConfig(spec *ytv1.ExecNodesSpec) ([]byte, e
"root": rootPath,

"grpc": map[string]any{
"address": getContainerdSocketPath(spec),
"address": GetContainerdSocketPath(spec),
"uid": 0,
"gid": 0,
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/ytconfig/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func fillJobEnvironment(execNode *ExecNode, spec *ytv1.ExecNodesSpec, commonSpec

jobEnv.UseJobProxyFromImage = ptr.Bool(false)

endpoint := "unix://" + getContainerdSocketPath(spec)
endpoint := "unix://" + GetContainerdSocketPath(spec)

jobEnv.CriExecutor = &CriExecutor{
RuntimeEndpoint: endpoint,
Expand Down

0 comments on commit b3cca0a

Please sign in to comment.