forked from openshift/azure-disk-csi-driver-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hardcoded_featuregate_reader.go
78 lines (64 loc) · 2.5 KB
/
hardcoded_featuregate_reader.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
69
70
71
72
73
74
75
76
77
78
package featuregates
import (
"context"
"fmt"
configv1 "github.com/openshift/api/config/v1"
)
type hardcodedFeatureGateAccess struct {
enabled []configv1.FeatureGateName
disabled []configv1.FeatureGateName
readErr error
initialFeatureGatesObserved chan struct{}
}
// NewHardcodedFeatureGateAccess returns a FeatureGateAccess that is always initialized and always
// returns the provided feature gates.
func NewHardcodedFeatureGateAccess(enabled, disabled []configv1.FeatureGateName) FeatureGateAccess {
initialFeatureGatesObserved := make(chan struct{})
close(initialFeatureGatesObserved)
c := &hardcodedFeatureGateAccess{
enabled: enabled,
disabled: disabled,
initialFeatureGatesObserved: initialFeatureGatesObserved,
}
return c
}
// NewHardcodedFeatureGateAccessForTesting returns a FeatureGateAccess that returns stub responses
// using caller-supplied values.
func NewHardcodedFeatureGateAccessForTesting(enabled, disabled []configv1.FeatureGateName, initialFeatureGatesObserved chan struct{}, readErr error) FeatureGateAccess {
return &hardcodedFeatureGateAccess{
enabled: enabled,
disabled: disabled,
initialFeatureGatesObserved: initialFeatureGatesObserved,
readErr: readErr,
}
}
func (c *hardcodedFeatureGateAccess) SetChangeHandler(featureGateChangeHandlerFn FeatureGateChangeHandlerFunc) {
// ignore
}
func (c *hardcodedFeatureGateAccess) Run(ctx context.Context) {
// ignore
}
func (c *hardcodedFeatureGateAccess) InitialFeatureGatesObserved() <-chan struct{} {
return c.initialFeatureGatesObserved
}
func (c *hardcodedFeatureGateAccess) AreInitialFeatureGatesObserved() bool {
select {
case <-c.InitialFeatureGatesObserved():
return true
default:
return false
}
}
func (c *hardcodedFeatureGateAccess) CurrentFeatureGates() (FeatureGate, error) {
return NewFeatureGate(c.enabled, c.disabled), c.readErr
}
// NewHardcodedFeatureGateAccessFromFeatureGate returns a FeatureGateAccess that is static and initialised from
// a populated FeatureGate status.
// If the desired version is missing, this will return an error.
func NewHardcodedFeatureGateAccessFromFeatureGate(featureGate *configv1.FeatureGate, desiredVersion string) (FeatureGateAccess, error) {
features, err := featuresFromFeatureGate(featureGate, desiredVersion)
if err != nil {
return nil, fmt.Errorf("unable to determine features: %w", err)
}
return NewHardcodedFeatureGateAccess(features.Enabled, features.Disabled), nil
}