@@ -20,7 +20,6 @@ import (
2020 "path/filepath"
2121 "testing"
2222
23- kata_v1alpha1 "github.com/NVIDIA/k8s-kata-manager/api/v1alpha1/config"
2423 "github.com/stretchr/testify/assert"
2524 "github.com/stretchr/testify/require"
2625 appsv1 "k8s.io/api/apps/v1"
@@ -1933,124 +1932,6 @@ func TestTransformMigManager(t *testing.T) {
19331932 }
19341933}
19351934
1936- func TestTransformKataManager (t * testing.T ) {
1937- testCases := []struct {
1938- description string
1939- ds Daemonset
1940- cpSpec * gpuv1.ClusterPolicySpec
1941- expectedDs Daemonset
1942- }{
1943- {
1944- description : "transform kata manager" ,
1945- ds : NewDaemonset ().WithContainer (corev1.Container {Name : "nvidia-kata-manager" }),
1946- cpSpec : & gpuv1.ClusterPolicySpec {
1947- KataManager : gpuv1.KataManagerSpec {
1948- Repository : "nvcr.io/nvidia/cloud-native" ,
1949- Image : "kata-manager" ,
1950- Version : "v1.0.0" ,
1951- ImagePullPolicy : "IfNotPresent" ,
1952- ImagePullSecrets : []string {"pull-secret" },
1953- Args : []string {"--test-flag" },
1954- Config : & kata_v1alpha1.Config {
1955- ArtifactsDir : "/var/lib/kata" ,
1956- },
1957- Env : []gpuv1.EnvVar {
1958- {Name : "foo" , Value : "bar" },
1959- },
1960- },
1961- },
1962- expectedDs : NewDaemonset ().WithContainer (corev1.Container {
1963- Name : "nvidia-kata-manager" ,
1964- Image : "nvcr.io/nvidia/cloud-native/kata-manager:v1.0.0" ,
1965- ImagePullPolicy : corev1 .PullIfNotPresent ,
1966- Args : []string {"--test-flag" },
1967- Env : []corev1.EnvVar {
1968- {Name : "KATA_ARTIFACTS_DIR" , Value : "/var/lib/kata" },
1969- {Name : "foo" , Value : "bar" },
1970- {Name : "RUNTIME" , Value : "containerd" },
1971- {Name : "CONTAINERD_RUNTIME_CLASS" , Value : "nvidia" },
1972- {Name : "RUNTIME_CONFIG" , Value : "/runtime/config-dir/config.toml" },
1973- {Name : "CONTAINERD_CONFIG" , Value : "/runtime/config-dir/config.toml" },
1974- {Name : "RUNTIME_SOCKET" , Value : "/runtime/sock-dir/containerd.sock" },
1975- {Name : "CONTAINERD_SOCKET" , Value : "/runtime/sock-dir/containerd.sock" },
1976- },
1977- VolumeMounts : []corev1.VolumeMount {
1978- {Name : "kata-artifacts" , MountPath : "/var/lib/kata" },
1979- {Name : "containerd-config" , MountPath : "/runtime/config-dir/" },
1980- {Name : "containerd-socket" , MountPath : "/runtime/sock-dir/" },
1981- },
1982- }).WithPullSecret ("pull-secret" ).WithPodAnnotations (map [string ]string {"nvidia.com/kata-manager.last-applied-hash" : "1929911998" }).WithHostPathVolume ("kata-artifacts" , "/var/lib/kata" , ptr .To (corev1 .HostPathDirectoryOrCreate )).WithHostPathVolume ("containerd-config" , "/etc/containerd" , ptr .To (corev1 .HostPathDirectoryOrCreate )).WithHostPathVolume ("containerd-socket" , "/run/containerd" , nil ),
1983- },
1984- {
1985- description : "transform kata manager with custom container runtime socket" ,
1986- ds : NewDaemonset ().WithContainer (corev1.Container {Name : "nvidia-kata-manager" }),
1987- cpSpec : & gpuv1.ClusterPolicySpec {
1988- KataManager : gpuv1.KataManagerSpec {
1989- Repository : "nvcr.io/nvidia/cloud-native" ,
1990- Image : "kata-manager" ,
1991- Version : "v1.0.0" ,
1992- ImagePullPolicy : "IfNotPresent" ,
1993- ImagePullSecrets : []string {"pull-secret" },
1994- Args : []string {"--test-flag" },
1995- Config : & kata_v1alpha1.Config {
1996- ArtifactsDir : "/var/lib/kata" ,
1997- },
1998- Env : []gpuv1.EnvVar {
1999- {
2000- Name : "CONTAINERD_CONFIG" , Value : "/var/lib/rancher/k3s/agent/etc/containerd/config.toml" ,
2001- },
2002- {
2003- Name : "CONTAINERD_SOCKET" , Value : "/run/k3s/containerd/containerd.sock" ,
2004- },
2005- {
2006- Name : "CONTAINERD_RUNTIME_CLASS" , Value : "nvidia" ,
2007- },
2008- {
2009- Name : "CONTAINERD_SET_AS_DEFAULT" , Value : "true" ,
2010- },
2011- },
2012- },
2013- },
2014- expectedDs : NewDaemonset ().WithContainer (corev1.Container {
2015- Name : "nvidia-kata-manager" ,
2016- Image : "nvcr.io/nvidia/cloud-native/kata-manager:v1.0.0" ,
2017- ImagePullPolicy : corev1 .PullIfNotPresent ,
2018- Args : []string {"--test-flag" },
2019- Env : []corev1.EnvVar {
2020- {Name : "KATA_ARTIFACTS_DIR" , Value : "/var/lib/kata" },
2021- {Name : "CONTAINERD_CONFIG" , Value : "/runtime/config-dir/config.toml" },
2022- {Name : "CONTAINERD_SOCKET" , Value : "/runtime/sock-dir/containerd.sock" },
2023- {Name : "CONTAINERD_RUNTIME_CLASS" , Value : "nvidia" },
2024- {Name : "CONTAINERD_SET_AS_DEFAULT" , Value : "true" },
2025- {Name : "RUNTIME" , Value : "containerd" },
2026- {Name : "RUNTIME_CONFIG" , Value : "/runtime/config-dir/config.toml" },
2027- {Name : "RUNTIME_SOCKET" , Value : "/runtime/sock-dir/containerd.sock" },
2028- },
2029- VolumeMounts : []corev1.VolumeMount {
2030- {Name : "kata-artifacts" , MountPath : "/var/lib/kata" },
2031- {Name : "containerd-config" , MountPath : "/runtime/config-dir/" },
2032- {Name : "containerd-socket" , MountPath : "/runtime/sock-dir/" },
2033- },
2034- }).WithPullSecret ("pull-secret" ).
2035- WithPodAnnotations (map [string ]string {"nvidia.com/kata-manager.last-applied-hash" : "1929911998" }).
2036- WithHostPathVolume ("kata-artifacts" , "/var/lib/kata" , ptr .To (corev1 .HostPathDirectoryOrCreate )).
2037- WithHostPathVolume ("containerd-config" , "/var/lib/rancher/k3s/agent/etc/containerd" , ptr .To (corev1 .HostPathDirectoryOrCreate )).
2038- WithHostPathVolume ("containerd-socket" , "/run/k3s/containerd" , nil ),
2039- },
2040- }
2041-
2042- for _ , tc := range testCases {
2043- t .Run (tc .description , func (t * testing.T ) {
2044- err := TransformKataManager (tc .ds .DaemonSet , tc .cpSpec , ClusterPolicyController {
2045- runtime : gpuv1 .Containerd ,
2046- logger : ctrl .Log .WithName ("test" ),
2047- })
2048- require .NoError (t , err )
2049- require .EqualValues (t , tc .expectedDs , tc .ds )
2050- })
2051- }
2052- }
2053-
20541935func TestTransformVFIOManager (t * testing.T ) {
20551936 resources := corev1.ResourceRequirements {
20561937 Limits : corev1.ResourceList {
0 commit comments