Skip to content

Commit 160dfc6

Browse files
change upgrade to only upgrade modified packages (#2358)
* change upgrade to only upgrade modified packages Signed-off-by: Ashraf Fouda <ashraf.m.fouda@gmail.com> * support booting from overlay Handle the case where the node is booted without the hub --------- Signed-off-by: Ashraf Fouda <ashraf.m.fouda@gmail.com> Co-authored-by: Muhamad Azamy <muhamad@incubaid.com>
1 parent 66184cd commit 160dfc6

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

pkg/upgrade/upgrade.go

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (u *Upgrader) Run(ctx context.Context) error {
146146
return errors.Wrap(err, "failed to get remote tag")
147147
}
148148

149-
if err := u.updateTo(remote); err != nil {
149+
if err := u.updateTo(remote, nil); err != nil {
150150
return errors.Wrap(err, "failed to run update")
151151
}
152152
}
@@ -236,7 +236,7 @@ func (u *Upgrader) update() error {
236236
}
237237

238238
log.Info().Str("version", filepath.Base(remote.Target)).Msg("updating system...")
239-
if err := u.updateTo(remote); err != nil {
239+
if err := u.updateTo(remote, &current); err != nil {
240240
return errors.Wrapf(err, "failed to update to new tag '%s'", remote.Target)
241241
}
242242

@@ -249,7 +249,7 @@ func (u *Upgrader) update() error {
249249

250250
// updateTo updates flist packages to match "link"
251251
// and only update zos package if u.noZosUpgrade is set to false
252-
func (u *Upgrader) updateTo(link hub.TagLink) error {
252+
func (u *Upgrader) updateTo(link hub.TagLink, current *hub.TagLink) error {
253253
repo, tag, err := link.Destination()
254254
if err != nil {
255255
return errors.Wrap(err, "failed to get destination tag")
@@ -260,9 +260,34 @@ func (u *Upgrader) updateTo(link hub.TagLink) error {
260260
return errors.Wrapf(err, "failed to list tag '%s' packages", tag)
261261
}
262262

263+
var curPkgsNames []string
264+
if current != nil {
265+
// get current pkgs list to compare the new pkgs against it
266+
curRepo, curTag, err := current.Destination()
267+
if err != nil {
268+
return errors.Wrap(err, "failed to resolve current link")
269+
}
270+
curPkgs, err := u.hub.ListTag(curRepo, curTag)
271+
if err != nil {
272+
return errors.Wrapf(err, "failed to list tag %s", curTag)
273+
}
274+
// store curPkgs names, the only part needed for the comparison
275+
for _, pkg := range curPkgs {
276+
_, name, err := pkg.Destination(curRepo)
277+
if err == nil {
278+
curPkgsNames = append(curPkgsNames, name)
279+
}
280+
}
281+
}
282+
263283
var later [][]string
264284
for _, pkg := range packages {
265285
pkgRepo, name, err := pkg.Destination(repo)
286+
// if the new pkg is the same as the current pkg no need to reinstall it
287+
if slices.Contains(curPkgsNames, name) {
288+
log.Info().Str("package", name).Msg("skipping package")
289+
continue
290+
}
266291
if pkg.Name == ZosPackage {
267292
// this is the last to do to make sure all dependencies are installed before updating zos
268293
log.Debug().Str("repo", pkgRepo).Str("name", name).Msg("schedule package for later")
@@ -363,6 +388,7 @@ func (u *Upgrader) install(repo, name string) error {
363388
log.Info().Str("repo", repo).Str("name", name).Msg("start installing package")
364389
var cache cache = u
365390
store, err := u.getFlist(repo, name, cache)
391+
366392
if errors.Is(err, syscall.EROFS) ||
367393
errors.Is(err, syscall.EPERM) ||
368394
errors.Is(err, syscall.EIO) {

0 commit comments

Comments
 (0)