Skip to content

Commit 105a7ce

Browse files
Muhamad Azmyzaibon
authored andcommitted
Install binaries even if booting from overlay (#480)
* Install binaries even if u running from overlay * Store correct list of bins * Cleanup
1 parent a756f6c commit 105a7ce

File tree

2 files changed

+62
-24
lines changed

2 files changed

+62
-24
lines changed

cmds/identityd/main.go

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,23 @@ func main() {
189189
}
190190
}()
191191

192+
zinit, err := zinit.New(zinitSocket)
193+
if err != nil {
194+
log.Fatal().Err(err).Msg("failed to connect to zinit")
195+
}
196+
197+
// with volume allocation is set to nil this flister can be
198+
// only used for RO mounts. Otherwise it will panic
199+
flister := flist.New(root, nil)
200+
201+
upgrader := upgrade.Upgrader{
202+
FLister: flister,
203+
Zinit: zinit,
204+
NoSelfUpdate: debug,
205+
}
206+
207+
installBinaries(&boot, &upgrader)
208+
192209
utils.OnDone(ctx, func(_ error) {
193210
log.Info().Msg("received a termination signal")
194211
})
@@ -205,7 +222,7 @@ func main() {
205222
// 4. Start watcher for new version
206223
log.Info().Msg("start upgrade daemon")
207224

208-
upgradeLoop(ctx, &boot, root, debug, monitor, register)
225+
upgradeLoop(ctx, &boot, &upgrader, debug, monitor, register)
209226
}
210227

211228
func getBinsRepo() string {
@@ -246,31 +263,45 @@ func debugReinstall(boot *upgrade.Boot, up *upgrade.Upgrader) {
246263
}()
247264
}
248265

249-
func upgradeLoop(
250-
ctx context.Context,
251-
boot *upgrade.Boot,
252-
root string,
253-
debug bool,
254-
monitor *monitorStream,
255-
register func(string) error) {
266+
func installBinaries(boot *upgrade.Boot, upgrader *upgrade.Upgrader) {
256267

257-
zinit, err := zinit.New(zinitSocket)
268+
bins, _ := boot.CurrentBins()
269+
270+
repoWatcher := upgrade.FListRepoWatcher{
271+
Repo: getBinsRepo(),
272+
Current: bins,
273+
}
274+
275+
current, toAdd, toDel, err := repoWatcher.Diff()
258276
if err != nil {
259-
log.Fatal().Err(err).Msg("failed to connect to zinit")
277+
log.Error().Err(err).Msg("failed to list latest binaries to install")
260278
}
261279

262-
// with volume allocation is set to nil this flister can be
263-
// only used for RO mounts. Otherwise it will panic
264-
flister := flist.New(root, nil)
280+
for _, pkg := range toDel {
281+
if err := upgrader.UninstallBinary(pkg); err != nil {
282+
log.Error().Err(err).Str("flist", pkg.Fqdn()).Msg("failed to uninstall flist")
283+
}
284+
}
265285

266-
upgrader := upgrade.Upgrader{
267-
FLister: flister,
268-
Zinit: zinit,
269-
NoSelfUpdate: debug,
286+
for _, pkg := range toAdd {
287+
if err := upgrader.InstallBinary(pkg); err != nil {
288+
log.Error().Err(err).Str("package", pkg.Fqdn()).Msg("failed to install package")
289+
}
270290
}
271291

292+
boot.SetBins(current)
293+
}
294+
295+
func upgradeLoop(
296+
ctx context.Context,
297+
boot *upgrade.Boot,
298+
upgrader *upgrade.Upgrader,
299+
debug bool,
300+
monitor *monitorStream,
301+
register func(string) error) {
302+
272303
if debug {
273-
debugReinstall(boot, &upgrader)
304+
debugReinstall(boot, upgrader)
274305
}
275306

276307
flistWatcher := upgrade.FListSemverWatcher{

pkg/upgrade/watcher.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,20 +197,29 @@ func (w *FListRepoWatcher) diff(packages map[string]RepoFList) (toAdd, toDel []R
197197
return
198198
}
199199

200+
// Diff return the remote changes related to current list of packages
201+
func (w *FListRepoWatcher) Diff() (all map[string]RepoFList, toAdd, toDell []RepoFList, err error) {
202+
all, err = w.list()
203+
if err != nil {
204+
return all, nil, nil, errors.Wrap(err, "failed to get available packages")
205+
}
206+
207+
toAdd, toDell = w.diff(all)
208+
return
209+
}
210+
200211
// Watch watches a full repo for changes. Event is always of concrete type RepoEvent
201212
func (w *FListRepoWatcher) Watch(ctx context.Context) (<-chan Event, error) {
202213
if w.Duration == time.Duration(0) {
203214
//default delay of 5min
204215
w.Duration = 600 * time.Second
205216
}
206217

207-
packages, err := w.list()
218+
packages, toAdd, toDel, err := w.Diff()
208219
if err != nil {
209220
return nil, errors.Wrap(err, "failed to get available packages")
210221
}
211222

212-
toAdd, toDel := w.diff(packages)
213-
214223
ch := make(chan Event, 1)
215224

216225
if len(toAdd) > 0 || len(toDel) > 0 {
@@ -236,14 +245,12 @@ func (w *FListRepoWatcher) Watch(ctx context.Context) (<-chan Event, error) {
236245
return
237246
}
238247

239-
packages, err := w.list()
248+
packages, toAdd, toDel, err := w.Diff()
240249
if err != nil {
241250
log.Error().Err(err).Str("repo", w.Repo).Msg("failed to list repo flists")
242251
continue
243252
}
244253

245-
toAdd, toDel := w.diff(packages)
246-
247254
if len(toAdd) > 0 || len(toDel) > 0 {
248255
select {
249256
case ch <- &RepoEvent{

0 commit comments

Comments
 (0)