MCPcopy
hub / github.com/containers/toolbox / initContainer

Function initContainer

src/cmd/initContainer.go:150–385  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

148}
149
150func initContainer(cmd *cobra.Command, args []string) error {
151 if !utils.IsInsideContainer() {
152 var builder strings.Builder
153 fmt.Fprintf(&builder, "the 'init-container' command can only be used inside containers\n")
154 fmt.Fprintf(&builder, "Run '%s --help' for usage.", executableBase)
155
156 errMsg := builder.String()
157 return errors.New(errMsg)
158 }
159
160 if !cmd.Flag("gid").Changed {
161 initContainerFlags.gid = initContainerFlags.uid
162 }
163
164 utils.EnsureXdgRuntimeDirIsSet(initContainerFlags.uid)
165
166 logrus.Debug("Creating /run/.toolboxenv")
167
168 toolboxEnvFile, err := os.Create("/run/.toolboxenv")
169 if err != nil {
170 return errors.New("failed to create /run/.toolboxenv")
171 }
172
173 defer toolboxEnvFile.Close()
174
175 if toolbxDelayEntryPoint, ok := getDelayEntryPoint(); ok {
176 delayString := toolbxDelayEntryPoint.String()
177 logrus.Debugf("Adding a delay of %s", delayString)
178 time.Sleep(toolbxDelayEntryPoint)
179 }
180
181 if toolbxFailEntryPoint, ok := getFailEntryPoint(); ok {
182 var builder strings.Builder
183 builder.WriteString("TOOLBX_FAIL_ENTRY_POINT is set")
184 if toolbxFailEntryPoint > 1 {
185 builder.WriteString("\n")
186 builder.WriteString("This environment variable should only be set when testing.")
187 }
188
189 errMsg := builder.String()
190 return errors.New(errMsg)
191 }
192
193 if utils.PathExists("/run/host/etc") {
194 logrus.Debug("Path /run/host/etc exists")
195
196 if _, err := os.Readlink("/etc/host.conf"); err != nil {
197 if err := redirectPath("/etc/host.conf",
198 "/run/host/etc/host.conf",
199 false); err != nil {
200 return err
201 }
202 }
203
204 if _, err := os.Readlink("/etc/hosts"); err != nil {
205 if err := redirectPath("/etc/hosts",
206 "/run/host/etc/hosts",
207 false); err != nil {

Callers

nothing calls this directly

Calls 15

getDelayEntryPointFunction · 0.85
getFailEntryPointFunction · 0.85
redirectPathFunction · 0.85
mountBindFunction · 0.85
configureUsersFunction · 0.85
getCDIFileForNvidiaFunction · 0.85
loadCDISpecFromFunction · 0.85
applyCDISpecForNvidiaFunction · 0.85
configureKerberosFunction · 0.85
configurePKCS11Function · 0.85
configureRPMFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…