-
Notifications
You must be signed in to change notification settings - Fork 548
/
condition.go
59 lines (48 loc) · 1.53 KB
/
condition.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
// 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/resource"
"github.com/cosi-project/runtime/pkg/state"
"github.com/siderolabs/talos/pkg/machinery/kernel"
)
// KernelParamsSetCondition implements condition which waits for the kernels to be in sync.
type KernelParamsSetCondition struct {
state state.State
props []*kernel.Param
}
// NewKernelParamsSetCondition builds a coondition which waits for the kernel to be in sync.
func NewKernelParamsSetCondition(state state.State, props ...*kernel.Param) *KernelParamsSetCondition {
return &KernelParamsSetCondition{
state: state,
props: props,
}
}
func (condition *KernelParamsSetCondition) String() string {
return "kernelParams"
}
// Wait implements condition interface.
func (condition *KernelParamsSetCondition) Wait(ctx context.Context) error {
for _, prop := range condition.props {
prop := prop
if _, err := condition.state.WatchFor(
ctx,
resource.NewMetadata(NamespaceName, KernelParamStatusType, prop.Key, resource.VersionUndefined),
state.WithCondition(func(r resource.Resource) (bool, error) {
if resource.IsTombstone(r) {
return false, nil
}
status := r.(*KernelParamStatus).TypedSpec()
if status.Current != prop.Value {
return false, nil
}
return true, nil
}),
); err != nil {
return err
}
}
return nil
}