Skip to content

Commit

Permalink
pipeline/ostree-deployment:add custom-mountpount-create service
Browse files Browse the repository at this point in the history
Hooked up the create-unit-stage to add create-mountpoint.service to
ostree deployment.
Automatically add and enable osbuild-create-mountpoint.service
whenever user adds filesystem customizationi, to ensure that the
mountpoints are available post rpm-ostree upgrade.

Signed-off-by: Sayan Paul <[email protected]>
  • Loading branch information
say-paul authored and bcl committed Mar 21, 2024
1 parent 0eb091d commit 2c9b6cd
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/distro/rhel9/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,10 @@ func edgeRawImage(workload workload.Workload,
img.Filename = t.Filename()
img.Compression = t.compression

for _, fs := range customizations.GetFilesystems() {
img.CustomFilesystems = append(img.CustomFilesystems, fs.Mountpoint)
}

return img, nil
}

Expand Down Expand Up @@ -546,6 +550,10 @@ func edgeSimplifiedInstallerImage(workload workload.Workload,

rawImg.Filename = t.Filename()

for _, fs := range customizations.GetFilesystems() {
rawImg.CustomFilesystems = append(rawImg.CustomFilesystems, fs.Mountpoint)
}

// 92+ only
if kopts := customizations.GetKernel(); kopts != nil && kopts.Append != "" {
rawImg.KernelOptionsAppend = append(rawImg.KernelOptionsAppend, kopts.Append)
Expand Down
3 changes: 3 additions & 0 deletions pkg/image/ostree_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type OSTreeDiskImage struct {
// Container buildable tweaks the buildroot to be container friendly,
// i.e. to not rely on an installed osbuild-selinux
ContainerBuildable bool

CustomFilesystems []string
}

func NewOSTreeDiskImageFromCommit(commit ostree.SourceSpec) *OSTreeDiskImage {
Expand Down Expand Up @@ -107,6 +109,7 @@ func baseRawOstreeImage(img *OSTreeDiskImage, buildPipeline manifest.Build, opts
osPipeline.IgnitionPlatform = img.IgnitionPlatform
osPipeline.LockRoot = img.LockRoot
osPipeline.UseBootupd = opts.useBootupd
osPipeline.CustomFileSystems = img.CustomFilesystems

// other image types (e.g. live) pass the workload to the pipeline.
if img.Workload != nil {
Expand Down
50 changes: 50 additions & 0 deletions pkg/manifest/ostree_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ type OSTreeDeployment struct {

// Use bootupd instead of grub2 as the bootloader
UseBootupd bool

CustomFileSystems []string
}

// NewOSTreeCommitDeployment creates a pipeline for an ostree deployment from a
Expand Down Expand Up @@ -353,6 +355,19 @@ func (p *OSTreeDeployment) serialize() osbuild.Pipeline {
},
}))

// This will create a custom systemd unit that create
// mountpoints if its not present.This will safeguard
// any ostree deployment which has custom filesystem
// during ostree upgrade.
// issue # https://github.com/osbuild/images/issues/352
if len(p.CustomFileSystems) != 0 {
serviceName := "osbuild-ostree-mountpoints.service"
stageOption := osbuild.NewSystemdUnitCreateStageOptions(createMountpointService(serviceName, p.CustomFileSystems))
stageOption.MountOSTree(p.osName, ref, 0)
pipeline.AddStage(stageOption)
p.EnabledServices = append(p.EnabledServices, serviceName)
}

// We enable / disable services below using the systemd stage, but its effect
// may be overridden by systemd which may reset enabled / disabled services on
// firstboot (which happend on F37+). This behavior, if available, is triggered
Expand Down Expand Up @@ -481,3 +496,38 @@ func (p *OSTreeDeployment) getInline() []string {

return inlineData
}

// Creates systemd unit stage by ingesting the servicename and mount-points
func createMountpointService(serviceName string, mountpoints []string) *osbuild.SystemdUnitCreateStageOptions {
var conditionPathIsDirectory []string
for _, mountpoint := range mountpoints {
conditionPathIsDirectory = append(conditionPathIsDirectory, "|!"+mountpoint)
}
unit := osbuild.Unit{
Description: "Ensure custom filesystem mountpoints exist",
DefaultDependencies: false,
ConditionPathIsDirectory: conditionPathIsDirectory,
}
service := osbuild.Service{
Type: osbuild.Oneshot,
RemainAfterExit: true,
//compatibility with composefs, will require transient rootfs to be enabled too.
ExecStartPre: []string{"/bin/sh -c \"if [ -z \"$(grep -Uq composefs /run/ostree-booted)\" ]; then chattr -i /; fi\""},
ExecStopPost: []string{"/bin/sh -c \"if [ -z \"$(grep -Uq composefs /run/ostree-booted)\" ]; then chattr +i /; fi\""},
ExecStart: []string{"mkdir -p " + strings.Join(mountpoints[:], " ")},
}
install := osbuild.Install{
WantedBy: []string{"local-fs.target"},
}
options := osbuild.SystemdUnitCreateStageOptions{
Filename: serviceName,
UnitPath: osbuild.Etc,
UnitType: osbuild.System,
Config: osbuild.SystemdServiceUnit{
Unit: &unit,
Service: &service,
Install: &install,
},
}
return &options
}

0 comments on commit 2c9b6cd

Please sign in to comment.