config.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. package generate
  2. import (
  3. rspec "github.com/opencontainers/runtime-spec/specs-go"
  4. )
  5. func (g *Generator) initConfig() {
  6. if g.Config == nil {
  7. g.Config = &rspec.Spec{}
  8. }
  9. }
  10. func (g *Generator) initConfigProcess() {
  11. g.initConfig()
  12. if g.Config.Process == nil {
  13. g.Config.Process = &rspec.Process{}
  14. }
  15. }
  16. func (g *Generator) initConfigProcessConsoleSize() {
  17. g.initConfigProcess()
  18. if g.Config.Process.ConsoleSize == nil {
  19. g.Config.Process.ConsoleSize = &rspec.Box{}
  20. }
  21. }
  22. func (g *Generator) initConfigProcessCapabilities() {
  23. g.initConfigProcess()
  24. if g.Config.Process.Capabilities == nil {
  25. g.Config.Process.Capabilities = &rspec.LinuxCapabilities{}
  26. }
  27. }
  28. func (g *Generator) initConfigRoot() {
  29. g.initConfig()
  30. if g.Config.Root == nil {
  31. g.Config.Root = &rspec.Root{}
  32. }
  33. }
  34. func (g *Generator) initConfigAnnotations() {
  35. g.initConfig()
  36. if g.Config.Annotations == nil {
  37. g.Config.Annotations = make(map[string]string)
  38. }
  39. }
  40. func (g *Generator) initConfigHooks() {
  41. g.initConfig()
  42. if g.Config.Hooks == nil {
  43. g.Config.Hooks = &rspec.Hooks{}
  44. }
  45. }
  46. func (g *Generator) initConfigLinux() {
  47. g.initConfig()
  48. if g.Config.Linux == nil {
  49. g.Config.Linux = &rspec.Linux{}
  50. }
  51. }
  52. func (g *Generator) initConfigLinuxIntelRdt() {
  53. g.initConfigLinux()
  54. if g.Config.Linux.IntelRdt == nil {
  55. g.Config.Linux.IntelRdt = &rspec.LinuxIntelRdt{}
  56. }
  57. }
  58. func (g *Generator) initConfigLinuxSysctl() {
  59. g.initConfigLinux()
  60. if g.Config.Linux.Sysctl == nil {
  61. g.Config.Linux.Sysctl = make(map[string]string)
  62. }
  63. }
  64. func (g *Generator) initConfigLinuxSeccomp() {
  65. g.initConfigLinux()
  66. if g.Config.Linux.Seccomp == nil {
  67. g.Config.Linux.Seccomp = &rspec.LinuxSeccomp{}
  68. }
  69. }
  70. func (g *Generator) initConfigLinuxResources() {
  71. g.initConfigLinux()
  72. if g.Config.Linux.Resources == nil {
  73. g.Config.Linux.Resources = &rspec.LinuxResources{}
  74. }
  75. }
  76. func (g *Generator) initConfigLinuxResourcesBlockIO() {
  77. g.initConfigLinuxResources()
  78. if g.Config.Linux.Resources.BlockIO == nil {
  79. g.Config.Linux.Resources.BlockIO = &rspec.LinuxBlockIO{}
  80. }
  81. }
  82. // InitConfigLinuxResourcesCPU initializes CPU of Linux resources
  83. func (g *Generator) InitConfigLinuxResourcesCPU() {
  84. g.initConfigLinuxResources()
  85. if g.Config.Linux.Resources.CPU == nil {
  86. g.Config.Linux.Resources.CPU = &rspec.LinuxCPU{}
  87. }
  88. }
  89. func (g *Generator) initConfigLinuxResourcesMemory() {
  90. g.initConfigLinuxResources()
  91. if g.Config.Linux.Resources.Memory == nil {
  92. g.Config.Linux.Resources.Memory = &rspec.LinuxMemory{}
  93. }
  94. }
  95. func (g *Generator) initConfigLinuxResourcesNetwork() {
  96. g.initConfigLinuxResources()
  97. if g.Config.Linux.Resources.Network == nil {
  98. g.Config.Linux.Resources.Network = &rspec.LinuxNetwork{}
  99. }
  100. }
  101. func (g *Generator) initConfigLinuxResourcesPids() {
  102. g.initConfigLinuxResources()
  103. if g.Config.Linux.Resources.Pids == nil {
  104. g.Config.Linux.Resources.Pids = &rspec.LinuxPids{}
  105. }
  106. }
  107. func (g *Generator) initConfigLinuxResourcesUnified() {
  108. g.initConfigLinuxResources()
  109. if g.Config.Linux.Resources.Unified == nil {
  110. g.Config.Linux.Resources.Unified = map[string]string{}
  111. }
  112. }
  113. func (g *Generator) initConfigSolaris() {
  114. g.initConfig()
  115. if g.Config.Solaris == nil {
  116. g.Config.Solaris = &rspec.Solaris{}
  117. }
  118. }
  119. func (g *Generator) initConfigSolarisCappedCPU() {
  120. g.initConfigSolaris()
  121. if g.Config.Solaris.CappedCPU == nil {
  122. g.Config.Solaris.CappedCPU = &rspec.SolarisCappedCPU{}
  123. }
  124. }
  125. func (g *Generator) initConfigSolarisCappedMemory() {
  126. g.initConfigSolaris()
  127. if g.Config.Solaris.CappedMemory == nil {
  128. g.Config.Solaris.CappedMemory = &rspec.SolarisCappedMemory{}
  129. }
  130. }
  131. func (g *Generator) initConfigWindows() {
  132. g.initConfig()
  133. if g.Config.Windows == nil {
  134. g.Config.Windows = &rspec.Windows{}
  135. }
  136. }
  137. func (g *Generator) initConfigWindowsNetwork() {
  138. g.initConfigWindows()
  139. if g.Config.Windows.Network == nil {
  140. g.Config.Windows.Network = &rspec.WindowsNetwork{}
  141. }
  142. }
  143. func (g *Generator) initConfigWindowsHyperV() {
  144. g.initConfigWindows()
  145. if g.Config.Windows.HyperV == nil {
  146. g.Config.Windows.HyperV = &rspec.WindowsHyperV{}
  147. }
  148. }
  149. func (g *Generator) initConfigWindowsResources() {
  150. g.initConfigWindows()
  151. if g.Config.Windows.Resources == nil {
  152. g.Config.Windows.Resources = &rspec.WindowsResources{}
  153. }
  154. }
  155. func (g *Generator) initConfigWindowsResourcesMemory() {
  156. g.initConfigWindowsResources()
  157. if g.Config.Windows.Resources.Memory == nil {
  158. g.Config.Windows.Resources.Memory = &rspec.WindowsMemoryResources{}
  159. }
  160. }
  161. func (g *Generator) initConfigVM() {
  162. g.initConfig()
  163. if g.Config.VM == nil {
  164. g.Config.VM = &rspec.VM{}
  165. }
  166. }