Skip to content

Commit

Permalink
fix: ignore error on duplicate for MountStatus
Browse files Browse the repository at this point in the history
We have multiple calls for `mountState` even when `STATE` is already
mounted, so we should handle it properly.

Example error:

```
[  152.736427] [talos] apply configuration failed: error running phase 2 in applyConfiguration sequence: task 1/1: failed, error creating mount status resource: resource MountStatuses.runtime.talos.dev(runtime/STATE@1) already exists
```

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
  • Loading branch information
smira committed Aug 30, 2021
1 parent 6956edd commit f8bebba
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/pkg/mount/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"sync"

"github.com/cosi-project/runtime/pkg/state"
"github.com/talos-systems/go-blockdevice/blockdevice"
"github.com/talos-systems/go-blockdevice/blockdevice/filesystem"
"golang.org/x/sys/unix"
Expand Down Expand Up @@ -206,13 +207,14 @@ func SystemPartitionMount(r runtime.Runtime, label string, opts ...Option) (err
return err
}

// record mount as the resources
// record mount as the resource
mountStatus := runtimeres.NewMountStatus(v1alpha1.NamespaceName, label)
mountStatus.TypedSpec().Source = mountpoint.Source()
mountStatus.TypedSpec().Target = mountpoint.Target()
mountStatus.TypedSpec().FilesystemType = mountpoint.Fstype()

if err = r.State().V1Alpha2().Resources().Create(context.Background(), mountStatus); err != nil {
// ignore the error if the MountStatus already exists, as many mounts are silently skipped with the flag SkipIfMounted
if err = r.State().V1Alpha2().Resources().Create(context.Background(), mountStatus); err != nil && !state.IsConflictError(err) {
return fmt.Errorf("error creating mount status resource: %w", err)
}

Expand Down

0 comments on commit f8bebba

Please sign in to comment.