cmd/initContainer: Split out the code to configure RPM
This is meant to reduce the size of the initContainer() function that implements the heart of the 'init-container' command. https://github.com/containers/toolbox/pull/1631
This commit is contained in:
parent
69702119b4
commit
06f81546ef
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2019 – 2024 Red Hat Inc.
|
* Copyright © 2019 – 2025 Red Hat Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -317,23 +317,8 @@ func initContainer(cmd *cobra.Command, args []string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if utils.PathExists("/usr/lib/rpm/macros.d") {
|
if err := configureRPM(); err != nil {
|
||||||
logrus.Debug("Configuring RPM to ignore bind mounts")
|
return err
|
||||||
|
|
||||||
var builder strings.Builder
|
|
||||||
fmt.Fprintf(&builder, "# Written by Toolbx\n")
|
|
||||||
fmt.Fprintf(&builder, "# https://github.com/containers/toolbox\n")
|
|
||||||
fmt.Fprintf(&builder, "\n")
|
|
||||||
fmt.Fprintf(&builder,
|
|
||||||
"%%_netsharedpath /dev:/media:/mnt:/proc:/sys:/tmp:/var/lib/flatpak:/var/lib/libvirt\n")
|
|
||||||
|
|
||||||
rpmConfigString := builder.String()
|
|
||||||
rpmConfigBytes := []byte(rpmConfigString)
|
|
||||||
if err := ioutil.WriteFile("/usr/lib/rpm/macros.d/macros.toolbox",
|
|
||||||
rpmConfigBytes,
|
|
||||||
0644); err != nil {
|
|
||||||
return fmt.Errorf("failed to configure RPM to ignore bind mounts: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debug("Setting up daily ticker")
|
logrus.Debug("Setting up daily ticker")
|
||||||
|
|
@ -568,6 +553,29 @@ func applyCDISpecForNvidiaHookUpdateLDCache(hookArgs []string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func configureRPM() error {
|
||||||
|
if !utils.PathExists("/usr/lib/rpm/macros.d") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.Debug("Configuring RPM to ignore bind mounts")
|
||||||
|
|
||||||
|
var builder strings.Builder
|
||||||
|
fmt.Fprintf(&builder, "# Written by Toolbx\n")
|
||||||
|
fmt.Fprintf(&builder, "# https://github.com/containers/toolbox\n")
|
||||||
|
fmt.Fprintf(&builder, "\n")
|
||||||
|
fmt.Fprintf(&builder,
|
||||||
|
"%%_netsharedpath /dev:/media:/mnt:/proc:/sys:/tmp:/var/lib/flatpak:/var/lib/libvirt\n")
|
||||||
|
|
||||||
|
rpmConfigString := builder.String()
|
||||||
|
rpmConfigBytes := []byte(rpmConfigString)
|
||||||
|
if err := ioutil.WriteFile("/usr/lib/rpm/macros.d/macros.toolbox", rpmConfigBytes, 0644); err != nil {
|
||||||
|
return fmt.Errorf("failed to configure RPM to ignore bind mounts: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func configureUsers(targetUserUid int, targetUser, targetUserHome, targetUserShell string, homeLink bool) error {
|
func configureUsers(targetUserUid int, targetUser, targetUserHome, targetUserShell string, homeLink bool) error {
|
||||||
if homeLink {
|
if homeLink {
|
||||||
if err := redirectPath("/home", "/var/home", true); err != nil {
|
if err := redirectPath("/home", "/var/home", true); err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue