Skip to content

Commit

Permalink
chore: annotate installer errors
Browse files Browse the repository at this point in the history
I want to catch a spurious error `ENODEV`, where exactly it comes from.

Signed-off-by: Andrey Smirnov <[email protected]>
  • Loading branch information
smira committed Mar 21, 2024
1 parent f737e64 commit 7d43c9a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
20 changes: 10 additions & 10 deletions cmd/installer/pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (i *Installer) Install(ctx context.Context, mode Mode) (err error) {

bd, err = retryBlockdeviceOpen(device)
if err != nil {
return err
return fmt.Errorf("error opening blockdevice %s: %w", device, err)
}

defer bd.Close() //nolint:errcheck
Expand All @@ -279,19 +279,19 @@ func (i *Installer) Install(ctx context.Context, mode Mode) (err error) {

mountpoint, err = mount.SystemMountPointForLabel(ctx, bd, label, mount.WithPrefix(i.options.MountPrefix))
if err != nil {
return err
return fmt.Errorf("error finding system mount points for %s: %w", device, err)
}

mountpoints.Set(label, mountpoint)

return nil
}(); err != nil {
return err
return fmt.Errorf("error mounting for label %q: %w", label, err)
}
}

if err = mount.Mount(mountpoints); err != nil {
return err
return fmt.Errorf("failed to mount standard mountpoints: %w", err)
}

defer func() {
Expand All @@ -312,7 +312,7 @@ func (i *Installer) Install(ctx context.Context, mode Mode) (err error) {
BootAssets: i.options.BootAssets,
Printf: i.options.Printf,
}); err != nil {
return err
return fmt.Errorf("failed to install bootloader: %w", err)
}

if i.options.Board != constants.BoardNone {
Expand All @@ -333,7 +333,7 @@ func (i *Installer) Install(ctx context.Context, mode Mode) (err error) {
RPiFirmwarePath: i.options.BootAssets.RPiFirmwarePath,
Printf: i.options.Printf,
}); err != nil {
return err
return fmt.Errorf("failed to install for board %s: %w", b.Name(), err)
}
}

Expand All @@ -344,7 +344,7 @@ func (i *Installer) Install(ctx context.Context, mode Mode) (err error) {
ArtifactsPath: filepath.Join(i.options.OverlayExtractedDir, constants.ImagerOverlayArtifactsPath),
ExtraOptions: i.options.ExtraOptions,
}); err != nil {
return err
return fmt.Errorf("failed to run overlay installer: %w", err)
}
}

Expand Down Expand Up @@ -373,7 +373,7 @@ func (i *Installer) Install(ctx context.Context, mode Mode) (err error) {
}

if metaState, err = meta.New(context.Background(), nil, meta.WithPrinter(i.options.Printf), meta.WithFixedPath(metaPartitionName)); err != nil {
return err
return fmt.Errorf("failed to open META: %w", err)
}

var ok bool
Expand All @@ -391,7 +391,7 @@ func (i *Installer) Install(ctx context.Context, mode Mode) (err error) {
}

if err = metaState.Flush(); err != nil {
return err
return fmt.Errorf("failed to flush META: %w", err)
}
}

Expand Down Expand Up @@ -423,7 +423,7 @@ func retryBlockdeviceOpen(device string) (*blockdevice.BlockDevice, error) {
err := retry.Constant(10*time.Second, retry.WithUnits(100*time.Millisecond)).Retry(func() error {
var openErr error

bd, openErr = blockdevice.Open(device)
bd, openErr = blockdevice.Open(device, blockdevice.WithExclusiveLock(true))
if openErr == nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/app/machined/pkg/controllers/block/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (ctrl *DevicesController) processEvent(ctx context.Context, r controller.Ru
}

if err := inotifyWatcher.Remove(devPath); err != nil {
return fmt.Errorf("failed to remove inotify watch for %q: %w", devPath, err)
logger.Debug("failed to remove inotify watch", zap.String("device", devPath), zap.Error(err))
}
default:
logger.Debug("skipped, as action is not supported")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ func (w *watches) remove(wd uint32) {
w.mu.Lock()
defer w.mu.Unlock()

delete(w.path, w.wd[wd].path)
if _, ok := w.wd[wd]; ok {
delete(w.path, w.wd[wd].path)
}

delete(w.wd, wd)
}

Expand Down Expand Up @@ -207,7 +210,7 @@ func (w *Watcher) Run() (<-chan string, <-chan error) {
}

// Send the events that are not ignored on the events channel
if mask&unix.IN_IGNORED == 0 {
if mask&unix.IN_IGNORED == 0 && mask&unix.IN_CLOSE_WRITE != 0 {
eventCh <- name
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/siderolabs/talos/internal/app/machined/pkg/controllers/block/internal/inotify"
)

//nolint:gocyclo
func TestWatcher(t *testing.T) {
watcher, err := inotify.NewWatcher()
require.NoError(t, err)
Expand Down Expand Up @@ -67,6 +68,17 @@ func TestWatcher(t *testing.T) {
case <-time.After(100 * time.Millisecond):
}

// remove file2
require.NoError(t, os.Remove(filepath.Join(d, "file2")))

select {
case path := <-watchCh:
require.FailNow(t, "unexpected path", "%s", path)
case err = <-errCh:
require.FailNow(t, "unexpected error", "%s", err)
case <-time.After(100 * time.Millisecond):
}

require.NoError(t, watcher.Remove(filepath.Join(d, "file2")))

require.NoError(t, watcher.Close())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
package kobject

import (
"errors"
"fmt"
"sync"

"github.com/mdlayher/kobject"
"go.uber.org/zap"
"golang.org/x/sys/unix"
)

const readBufferSize = 64 * 1024 * 1024
Expand Down Expand Up @@ -77,7 +79,9 @@ func (w *Watcher) Run(logger *zap.Logger) <-chan *Event {
for {
ev, err := w.cli.Receive()
if err != nil {
logger.Error("failed to receive kobject event", zap.Error(err))
if !errors.Is(err, unix.EBADF) {
logger.Error("failed to receive kobject event", zap.Error(err))
}

return
}
Expand Down
5 changes: 5 additions & 0 deletions internal/pkg/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ func (c *Client) LeaveCluster(ctx context.Context, st state.State) error {
return retry.ExpectedError(err)
}

if errors.Is(err, rpctypes.ErrStopped) {
// retry the stopped errors as the member might be in the process of shutting down
return retry.ExpectedError(err)
}

return err
}); err != nil {
return err
Expand Down

0 comments on commit 7d43c9a

Please sign in to comment.