Skip to content

Commit

Permalink
revert to using package managers if present and remove debug output f…
Browse files Browse the repository at this point in the history
…rom check

Signed-off-by: ashnamehrotra <[email protected]>
  • Loading branch information
ashnamehrotra committed Jun 25, 2024
1 parent a43508b commit f550adc
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions pkg/pkgmgr/rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,22 +401,25 @@ func (rm *rpmManager) installUpdates(ctx context.Context, updates unversioned.Up
var installCmd string
switch {
case rm.rpmTools["dnf"] != "":
if rm.checkForUpgrades(ctx, rm.rpmTools["dnf"]) != nil {
return nil, nil, errors.New("no upgradable packages")
checkUpdateTemplate := `sh -c "%[1]s check-update; if [ $? -ne 0 ]; then echo >> /updates.txt; fi"`
if !rm.checkForUpgrades(ctx, rm.rpmTools["dnf"], checkUpdateTemplate) {
return nil, nil, fmt.Errorf("no patchable packages found")

Check warning on line 406 in pkg/pkgmgr/rpm.go

View check run for this annotation

Codecov / codecov/patch

pkg/pkgmgr/rpm.go#L404-L406

Added lines #L404 - L406 were not covered by tests
}

const dnfInstallTemplate = `sh -c '%[1]s upgrade %[2]s -y && %[1]s clean all'`
installCmd = fmt.Sprintf(dnfInstallTemplate, rm.rpmTools["dnf"], pkgs)
case rm.rpmTools["yum"] != "":
if rm.checkForUpgrades(ctx, rm.rpmTools["yum"]) != nil {
return nil, nil, errors.New("no upgradable packages")
checkUpdateTemplate := `sh -c 'if [ "$(%[1]s -q check-update | wc -l)" -ne 0 ]; then echo >> /updates.txt; fi'`
if !rm.checkForUpgrades(ctx, rm.rpmTools["yum"], checkUpdateTemplate) {
return nil, nil, fmt.Errorf("no patchable packages found")

Check warning on line 414 in pkg/pkgmgr/rpm.go

View check run for this annotation

Codecov / codecov/patch

pkg/pkgmgr/rpm.go#L412-L414

Added lines #L412 - L414 were not covered by tests
}

const yumInstallTemplate = `sh -c '%[1]s upgrade %[2]s -y && %[1]s clean all'`
installCmd = fmt.Sprintf(yumInstallTemplate, rm.rpmTools["yum"], pkgs)
case rm.rpmTools["microdnf"] != "":
if rm.checkForUpgrades(ctx, rm.rpmTools["microdnf"]) != nil {
return nil, nil, errors.New("no upgradable packages")
checkUpdateTemplate := `sh -c "%[1]s install dnf -y; dnf check-update -y; if [ $? -ne 0 ]; then echo >> /updates.txt; fi;"`
if !rm.checkForUpgrades(ctx, rm.rpmTools["microdnf"], checkUpdateTemplate) {
return nil, nil, fmt.Errorf("no patchable packages found")

Check warning on line 422 in pkg/pkgmgr/rpm.go

View check run for this annotation

Codecov / codecov/patch

pkg/pkgmgr/rpm.go#L420-L422

Added lines #L420 - L422 were not covered by tests
}

const microdnfInstallTemplate = `sh -c '%[1]s update %[2]s && %[1]s clean all'`
Expand Down Expand Up @@ -447,25 +450,18 @@ func (rm *rpmManager) installUpdates(ctx context.Context, updates unversioned.Up
return &patchMerge, resultBytes, nil
}

func (rm *rpmManager) checkForUpgrades(ctx context.Context, toolPath string) error {
checkUpdateTemplate := `sh -c "set -x; %[1]s install dnf -y; dnf check-update -y; if [ $? -ne 0 ]; then echo >> /updates.txt; fi;"`
func (rm *rpmManager) checkForUpgrades(ctx context.Context, toolPath, checkUpdateTemplate string) bool {
checkUpdate := fmt.Sprintf(checkUpdateTemplate, toolPath)
stateWithCheck := rm.config.ImageState.Run(llb.Shlex(checkUpdate)).Root()

Check warning on line 455 in pkg/pkgmgr/rpm.go

View check run for this annotation

Codecov / codecov/patch

pkg/pkgmgr/rpm.go#L453-L455

Added lines #L453 - L455 were not covered by tests

stateWithDnf := rm.config.ImageState.Run(llb.Shlex(checkUpdate)).Root()

_, err := buildkit.ExtractFileFromState(ctx, rm.config.Client, &stateWithDnf, "/updates.txt")
if err != nil {
log.Error(err)
return err
}
_, err := buildkit.ExtractFileFromState(ctx, rm.config.Client, &stateWithCheck, "/updates.txt")

Check warning on line 457 in pkg/pkgmgr/rpm.go

View check run for this annotation

Codecov / codecov/patch

pkg/pkgmgr/rpm.go#L457

Added line #L457 was not covered by tests

// if error in extracting file, that means updates.txt does not exist and there are no updates.
if err != nil {

Check failure on line 460 in pkg/pkgmgr/rpm.go

View workflow job for this annotation

GitHub Actions / lint

S1008: should use 'return err == nil' instead of 'if err != nil { return false }; return true' (gosimple)
log.Error(err)
return err
return false

Check warning on line 461 in pkg/pkgmgr/rpm.go

View check run for this annotation

Codecov / codecov/patch

pkg/pkgmgr/rpm.go#L460-L461

Added lines #L460 - L461 were not covered by tests
}

return nil
return true

Check warning on line 464 in pkg/pkgmgr/rpm.go

View check run for this annotation

Codecov / codecov/patch

pkg/pkgmgr/rpm.go#L464

Added line #L464 was not covered by tests
}

func (rm *rpmManager) unpackAndMergeUpdates(ctx context.Context, updates unversioned.UpdatePackages, toolImage string) (*llb.State, []byte, error) {
Expand Down

0 comments on commit f550adc

Please sign in to comment.