@@ -15,7 +15,6 @@ import (
1515 "github.com/microsoft/azurelinux/toolkit/tools/imagegen/installutils"
1616 "github.com/microsoft/azurelinux/toolkit/tools/internal/exe"
1717 "github.com/microsoft/azurelinux/toolkit/tools/internal/logger"
18- "github.com/microsoft/azurelinux/toolkit/tools/internal/pkgjson"
1918 "github.com/microsoft/azurelinux/toolkit/tools/internal/timestamp"
2019 "github.com/microsoft/azurelinux/toolkit/tools/pkg/profile"
2120
@@ -135,28 +134,30 @@ func validatePackages(config configuration.Config) (err error) {
135134 selinuxPkgName = configuration .SELinuxPolicyDefault
136135 }
137136
138- for _ , pkg := range packageList {
139- // The installer tools have an undocumented feature which can support both "pkg-name" and "pkg-name=version" formats.
140- // This is in use, so we need to handle pinned versions in this check. Technically, 'tdnf' also supports "pkg-name-version" format,
141- // but it is not easily distinguishable from "long-package-name" format so it will not be supported here.
142- pkgVer , err := pkgjson .PackageStringToPackageVer (pkg )
143- if err != nil {
144- return fmt .Errorf ("%s: %w" , validateError , err )
145- }
137+ foundKernelPackage , err := installutils .PackagelistContainsPackage (packageList , kernelPkgName )
138+ if err != nil {
139+ return fmt .Errorf ("%s: %w" , validateError , err )
140+ }
146141
147- if pkgVer .Name == kernelPkgName {
148- return fmt .Errorf ("%s: kernel should not be included in a package list, add via config file's [KernelOptions] entry" , validateError )
149- }
150- if pkgVer .Name == dracutFipsPkgName {
151- foundDracutFipsPackage = true
152- }
153- if pkgVer .Name == selinuxPkgName {
154- foundSELinuxPackage = true
155- }
156- if pkgVer .Name == userAddPkgName {
157- foundUserAddPackage = true
158- }
142+ foundDracutFipsPackage , err = installutils .PackagelistContainsPackage (packageList , dracutFipsPkgName )
143+ if err != nil {
144+ return fmt .Errorf ("%s: %w" , validateError , err )
159145 }
146+
147+ foundSELinuxPackage , err = installutils .PackagelistContainsPackage (packageList , selinuxPkgName )
148+ if err != nil {
149+ return fmt .Errorf ("%s: %w" , validateError , err )
150+ }
151+
152+ foundUserAddPackage , err = installutils .PackagelistContainsPackage (packageList , userAddPkgName )
153+ if err != nil {
154+ return fmt .Errorf ("%s: %w" , validateError , err )
155+ }
156+
157+ if foundKernelPackage {
158+ return fmt .Errorf ("%s: kernel should not be included in a package list, add via config file's [KernelOptions] entry" , validateError )
159+ }
160+
160161 if strings .Contains (kernelCmdLineString , fipsKernelCmdLine ) || systemConfig .KernelCommandLine .EnableFIPS {
161162 if ! foundDracutFipsPackage {
162163 return fmt .Errorf ("%s: 'fips=1' provided on kernel cmdline, but '%s' package is not included in the package lists" , validateError , dracutFipsPkgName )
0 commit comments