Artem Chernyshev b520710810
feat: introduce new flag in reset API that makes Talos reset user disks
Fixes: https://github.com/siderolabs/talos/issues/6815

Additionally, make it possible to run reset in maintenance mode: to
enable a way for resetting system disk and remove all traces of Talos
from it.

The new reset flow works in a separate sequence, changed disk probe
lookup to check the boot partition instead of the ephemeral one.

Signed-off-by: Artem Chernyshev <artem.chernyshev@talos-systems.com>
2023-02-28 15:10:41 +03:00

61 lines
1.6 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// Package internal contains server implementation.
package internal
import (
"context"
"github.com/siderolabs/gen/slices"
bddisk "github.com/siderolabs/go-blockdevice/blockdevice/util/disk"
"google.golang.org/protobuf/types/known/emptypb"
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime"
"github.com/siderolabs/talos/pkg/machinery/api/storage"
)
// Server implements storage.StorageService.
// TODO: this is not a full blown service yet, it's used as the common base in the machine and the maintenance services.
type Server struct {
storage.UnimplementedStorageServiceServer
Controller runtime.Controller
}
// Disks implements storage.StorageService.
func (s *Server) Disks(ctx context.Context, in *emptypb.Empty) (reply *storage.DisksResponse, err error) {
disks, err := bddisk.List()
if err != nil {
return nil, err
}
systemDisk := s.Controller.Runtime().State().Machine().Disk()
diskConv := func(d *bddisk.Disk) *storage.Disk {
return &storage.Disk{
DeviceName: d.DeviceName,
Model: d.Model,
Size: d.Size,
Name: d.Name,
Serial: d.Serial,
Modalias: d.Modalias,
Type: storage.Disk_DiskType(d.Type),
BusPath: d.BusPath,
SystemDisk: systemDisk != nil && d.DeviceName == systemDisk.Device().Name(),
}
}
diskList := slices.Map(disks, diskConv)
reply = &storage.DisksResponse{
Messages: []*storage.Disks{
{
Disks: diskList,
},
},
}
return reply, nil
}