2021-09-06 11:26:48 +00:00
|
|
|
/*
|
2022-02-22 14:09:45 +00:00
|
|
|
# Copyright (c) 2021-2022, NVIDIA CORPORATION. All rights reserved.
|
2021-09-06 11:26:48 +00:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2022-02-22 14:09:45 +00:00
|
|
|
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-container-runtime/modifier"
|
2021-09-06 11:30:15 +00:00
|
|
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
|
2022-02-22 14:09:45 +00:00
|
|
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/runtime"
|
|
|
|
"github.com/sirupsen/logrus"
|
2021-09-06 11:26:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
dockerRuncExecutableName = "docker-runc"
|
|
|
|
runcExecutableName = "runc"
|
|
|
|
)
|
|
|
|
|
2022-02-22 14:09:45 +00:00
|
|
|
// newNVIDIAContainerRuntime is a factory method that constructs a runtime based on the selected configuration and specified logger
|
|
|
|
func newNVIDIAContainerRuntime(logger *logrus.Logger, cfg *config, argv []string) (oci.Runtime, error) {
|
|
|
|
ociSpec, err := oci.NewSpec(logger, argv)
|
2021-09-06 11:26:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error constructing OCI specification: %v", err)
|
|
|
|
}
|
|
|
|
|
2022-01-31 14:11:36 +00:00
|
|
|
lowLevelRuntimeCandidates := []string{dockerRuncExecutableName, runcExecutableName}
|
2022-02-22 14:09:45 +00:00
|
|
|
lowLevelRuntime, err := oci.NewLowLevelRuntime(logger, lowLevelRuntimeCandidates)
|
2021-09-06 11:26:48 +00:00
|
|
|
if err != nil {
|
2022-01-31 14:11:36 +00:00
|
|
|
return nil, fmt.Errorf("error constructing low-level runtime: %v", err)
|
2021-09-06 11:26:48 +00:00
|
|
|
}
|
|
|
|
|
2022-02-22 14:09:45 +00:00
|
|
|
specModifier := modifier.NewStableRuntimeModifier(logger)
|
|
|
|
|
|
|
|
// Create the wrapping runtime with the specified modifier
|
|
|
|
r := runtime.NewModifyingRuntimeWrapper(
|
|
|
|
logger,
|
|
|
|
lowLevelRuntime,
|
|
|
|
ociSpec,
|
|
|
|
specModifier,
|
|
|
|
)
|
2021-09-06 11:26:48 +00:00
|
|
|
|
|
|
|
return r, nil
|
|
|
|
}
|