Skip to content

Commit df61a22

Browse files
committed
manifest: use local variables for OSCustomizations
Writing directly to OSCustomizations is not a good idea. Use local variables instead. This patch refactors Subscription, WSL and Firstboot customizations all at once since this is the pattern that is common to all of them.
1 parent 6222883 commit df61a22

1 file changed

Lines changed: 19 additions & 18 deletions

File tree

pkg/manifest/os.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,8 @@ func (p *OS) serialize() (osbuild.Pipeline, error) {
544544
return osbuild.Pipeline{}, err
545545
}
546546

547+
var subscriptionEnabledServices []string
548+
547549
if p.ostreeParentSpec != nil {
548550
pipeline.AddStage(osbuild.NewOSTreePasswdStage("org.osbuild.source", p.ostreeParentSpec.Checksum))
549551
}
@@ -694,22 +696,16 @@ func (p *OS) serialize() (osbuild.Pipeline, error) {
694696
p.addStagesForAllFilesAndInlineData(&pipeline, fbFiles)
695697
}
696698

697-
if len(fbCerts) > 0 {
698-
p.OSCustomizations.CACerts = append(p.OSCustomizations.CACerts, fbCerts...)
699-
}
700-
701-
if fbUnit != nil {
702-
p.OSCustomizations.EnabledServices = append(p.OSCustomizations.EnabledServices, fbUnit.Filename)
703-
p.OSCustomizations.SystemdUnit = append(p.OSCustomizations.SystemdUnit, fbUnit)
704-
}
705-
706699
for _, systemdUnitConfig := range p.OSCustomizations.SystemdDropin {
707700
pipeline.AddStage(osbuild.NewSystemdUnitStage(systemdUnitConfig))
708701
}
709702

710703
for _, systemdUnitCreateConfig := range p.OSCustomizations.SystemdUnit {
711704
pipeline.AddStage(osbuild.NewSystemdUnitCreateStage(systemdUnitCreateConfig))
712705
}
706+
if fbUnit != nil {
707+
pipeline.AddStage(osbuild.NewSystemdUnitCreateStage(fbUnit))
708+
}
713709

714710
if p.OSCustomizations.Authselect != nil {
715711
pipeline.AddStage(osbuild.NewAuthselectStage(p.OSCustomizations.Authselect))
@@ -789,7 +785,7 @@ func (p *OS) serialize() (osbuild.Pipeline, error) {
789785
pipeline.AddStage(subStage)
790786
pipeline.AddStages(osbuild.GenDirectoryNodesStages(subDirs)...)
791787
p.addStagesForAllFilesAndInlineData(&pipeline, subFiles)
792-
p.OSCustomizations.EnabledServices = append(p.OSCustomizations.EnabledServices, subServices...)
788+
subscriptionEnabledServices = subServices
793789
}
794790

795791
if p.OSCustomizations.RHSMConfig != nil {
@@ -930,6 +926,10 @@ func (p *OS) serialize() (osbuild.Pipeline, error) {
930926
disabledServices := []string{}
931927
maskedServices := []string{}
932928
enabledServices = append(enabledServices, p.OSCustomizations.EnabledServices...)
929+
if fbUnit != nil {
930+
enabledServices = append(enabledServices, fbUnit.Filename)
931+
}
932+
enabledServices = append(enabledServices, subscriptionEnabledServices...)
933933
disabledServices = append(disabledServices, p.OSCustomizations.DisabledServices...)
934934
maskedServices = append(maskedServices, p.OSCustomizations.MaskedServices...)
935935
if p.Environment != nil {
@@ -955,14 +955,13 @@ func (p *OS) serialize() (osbuild.Pipeline, error) {
955955
}
956956

957957
if p.OSCustomizations.WSLDistributionConfig != nil {
958-
// We format in our version string into the name field, if there's no %s in there nothing
959-
// special will happen.
960-
p.OSCustomizations.WSLDistributionConfig.OOBE.DefaultName = fmt.Sprintf(
961-
p.OSCustomizations.WSLDistributionConfig.OOBE.DefaultName,
958+
// Format version into the name field; if there's no %s nothing special happens.
959+
wslDistConfig := *p.OSCustomizations.WSLDistributionConfig
960+
wslDistConfig.OOBE.DefaultName = fmt.Sprintf(
961+
wslDistConfig.OOBE.DefaultName,
962962
p.OSVersion,
963963
)
964-
965-
pipeline.AddStage(osbuild.NewWSLDistributionConfStage(p.OSCustomizations.WSLDistributionConfig))
964+
pipeline.AddStage(osbuild.NewWSLDistributionConfStage(&wslDistConfig))
966965
}
967966

968967
if p.OSCustomizations.FIPS {
@@ -988,8 +987,10 @@ func (p *OS) serialize() (osbuild.Pipeline, error) {
988987
}))
989988
}
990989

991-
if len(p.OSCustomizations.CACerts) > 0 {
992-
for _, cc := range p.OSCustomizations.CACerts {
990+
allCACerts := append([]string{}, p.OSCustomizations.CACerts...)
991+
allCACerts = append(allCACerts, fbCerts...)
992+
if len(allCACerts) > 0 {
993+
for _, cc := range allCACerts {
993994
files, err := osbuild.NewCAFileNodes(cc)
994995
if err != nil {
995996
return osbuild.Pipeline{}, err

0 commit comments

Comments
 (0)