@@ -93,6 +93,11 @@ func (b *ContainerdBuilder) Build(c *fi.NodeupModelBuilderContext) error {
9393 return err
9494 }
9595
96+ // If gVisor is enabled, emit the runsc shim config file
97+ if b .InstallGVisorRuntime () {
98+ b .buildGVisorShimConfig (c )
99+ }
100+
96101 if installContainerd {
97102 if err := b .installContainerd (c ); err != nil {
98103 return err
@@ -564,6 +569,12 @@ func (b *ContainerdBuilder) buildContainerdConfigV2() (string, error) {
564569 }
565570 }
566571
572+ if b .InstallGVisorRuntime () {
573+ if err := appendGVisorRuntimeConfig (config , []string {"plugins" , "io.containerd.grpc.v1.cri" , "containerd" , "runtimes" }); err != nil {
574+ return "" , fmt .Errorf ("appending gvisor runtime to v2 containerd config: %w" , err )
575+ }
576+ }
577+
567578 if err := applyConfigAdditions (config , containerd .ConfigAdditions ); err != nil {
568579 return "" , fmt .Errorf ("applying ConfigAdditions to v2 containerd config: %w" , err )
569580 }
@@ -617,6 +628,12 @@ func (b *ContainerdBuilder) buildContainerdConfigV3() (string, error) {
617628 }
618629 }
619630
631+ if b .InstallGVisorRuntime () {
632+ if err := appendGVisorRuntimeConfig (config , []string {"plugins" , "io.containerd.cri.v1.runtime" , "containerd" , "runtimes" }); err != nil {
633+ return "" , fmt .Errorf ("appending gvisor runtime to v3 containerd config: %w" , err )
634+ }
635+ }
636+
620637 if err := applyConfigAdditions (config , containerd .ConfigAdditions ); err != nil {
621638 return "" , fmt .Errorf ("applying ConfigAdditions to v3 containerd config: %w" , err )
622639 }
@@ -691,6 +708,45 @@ func appendNvidiaGPURuntimeConfig(config *toml.Tree, runtimesPath []string) erro
691708 return nil
692709}
693710
711+ // appendGVisorRuntimeConfig adds the "runsc" runtime entry under runtimesPath.
712+ // runtimesPath is schema-specific so the same helper can serve both v2 and v3 builders.
713+ func appendGVisorRuntimeConfig (config * toml.Tree , runtimesPath []string ) error {
714+ gvisorConfig , err := toml .TreeFromMap (
715+ map [string ]interface {}{
716+ "runtime_type" : "io.containerd.runsc.v1" ,
717+ },
718+ )
719+ if err != nil {
720+ return err
721+ }
722+
723+ path := make ([]string , len (runtimesPath )+ 1 )
724+ copy (path , runtimesPath )
725+ path [len (runtimesPath )] = "runsc"
726+ config .SetPath (path , gvisorConfig )
727+
728+ return nil
729+ }
730+
731+ // buildGVisorShimConfig emits /etc/containerd/runsc.toml, the shim-level
732+ // configuration consumed by containerd-shim-runsc-v1 at container creation.
733+ // See https://gvisor.dev/docs/user_guide/containerd/configuration/
734+ func (b * ContainerdBuilder ) buildGVisorShimConfig (c * fi.NodeupModelBuilderContext ) {
735+ platform := b .NodeupConfig .GVisor .Platform
736+ if platform == "" {
737+ platform = "systrap"
738+ }
739+
740+ shimConfig , _ := toml .Load ("" )
741+ shimConfig .SetPath ([]string {"runsc_config" , "platform" }, platform )
742+
743+ c .AddTask (& nodetasks.File {
744+ Path : "/etc/containerd/runsc.toml" ,
745+ Contents : fi .NewStringResource (shimConfig .String ()),
746+ Type : nodetasks .FileType_File ,
747+ })
748+ }
749+
694750// buildRegistryHosts emits one hosts.toml per RegistryMirrors entry under containerdRegistryDirPath.
695751// The directory is referenced by registry.config_path in the main containerd config; the
696752// emit-files-iff-mirrors-non-empty condition here must stay in sync with the registry.config_path
0 commit comments