-
Notifications
You must be signed in to change notification settings - Fork 458
/
devices_status.go
68 lines (56 loc) · 1.91 KB
/
devices_status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// 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 runtime
import (
"context"
"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/safe"
"go.uber.org/zap"
"github.com/siderolabs/talos/internal/app/machined/pkg/controllers/v1alpha1"
machineruntime "github.com/siderolabs/talos/internal/app/machined/pkg/runtime"
"github.com/siderolabs/talos/pkg/machinery/resources/runtime"
)
// DevicesStatusController loads extensions.yaml and updates DevicesStatus resources.
type DevicesStatusController struct {
V1Alpha1Mode machineruntime.Mode
}
// Name implements controller.Controller interface.
func (ctrl *DevicesStatusController) Name() string {
return "runtime.DevicesStatusController"
}
// Inputs implements controller.Controller interface.
func (ctrl *DevicesStatusController) Inputs() []controller.Input {
return nil
}
// Outputs implements controller.Controller interface.
func (ctrl *DevicesStatusController) Outputs() []controller.Output {
return []controller.Output{
{
Type: runtime.DevicesStatusType,
Kind: controller.OutputExclusive,
},
}
}
// Run implements controller.Controller interface.
func (ctrl *DevicesStatusController) Run(ctx context.Context, r controller.Runtime, logger *zap.Logger) error {
// in container mode, devices are always ready
if ctrl.V1Alpha1Mode != machineruntime.ModeContainer {
if err := v1alpha1.WaitForServiceHealthy(ctx, r, "udevd", nil); err != nil {
return err
}
}
for {
select {
case <-ctx.Done():
return nil
case <-r.EventCh():
}
if err := safe.WriterModify(ctx, r, runtime.NewDevicesStatus(runtime.NamespaceName, runtime.DevicesID), func(status *runtime.DevicesStatus) error {
status.TypedSpec().Ready = true
return nil
}); err != nil {
return err
}
}
}