Repository navigation
Expand file tree
/
Copy pathoptions.go
More file actions
75 lines (68 loc) · 2.95 KB
/
Copy pathoptions.go
File metadata and controls
75 lines (68 loc) · 2.95 KB
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
package gatekit
import "fmt"
// Option configures a FeatureGate at construction. Options are applied by New in
// the order given; the last one to set a value wins.
type Option func(*config) error
// config holds the resolved construction settings before a FeatureGate is built.
// It carries defaults so New can apply options over a known baseline.
type config struct {
// registry is the (unnormalized) feature registry New was called with. New
// populates it before applying options so an Option that needs to validate
// against the known features — notably WithEnvOverrides — can read it.
registry Registry
// window is the support window W: the number of prior activation versions the
// gate also supports. Defaults to 1 (strict N/N+1).
window int
// overrides forces specific features on or off regardless of the
// version-resolved default (core-spec §5). Nil until an override is set.
overrides map[Feature]bool
// allowAlpha opts the gate in to ALPHA features gate-wide (core-spec §4).
allowAlpha bool
}
// defaultConfig returns the baseline settings New applies options over.
func defaultConfig() config {
return config{window: 1}
}
// WithSupportWindow sets the support window W — the number of prior activation
// versions the gate supports in addition to Max, so Min = max(firstVersion,
// Max - W). W defaults to 1 (strict N/N+1); a consumer MAY widen it (N/N+3,
// N/N+5, ...). W is the support breadth and is distinct from the per-release
// increment rule (activation version grows by at most 1 per release). W must be
// non-negative.
func WithSupportWindow(w int) Option {
return func(c *config) error {
if w < 0 {
return fmt.Errorf("gatekit: support window must be non-negative, got %d", w)
}
c.window = w
return nil
}
}
// WithOverrides forces specific features on or off regardless of the
// version-resolved default — the highest-precedence input to resolution
// (core-spec §5), mirroring Kubernetes --feature-gates=Foo=true. An override
// takes effect regardless of the current activation version, including before a
// feature's first spec is reached. An override MAY only name a registered
// feature; New rejects an override for an unknown feature (a mistyped identifier
// would otherwise silently force nothing). Repeated calls merge, last value wins.
func WithOverrides(overrides map[Feature]bool) Option {
return func(c *config) error {
if c.overrides == nil {
c.overrides = make(map[Feature]bool, len(overrides))
}
for f, v := range overrides {
c.overrides[f] = v
}
return nil
}
}
// WithExperimental opts the gate in to ALPHA features gate-wide: an ALPHA feature
// then follows its declared default instead of being forced off (core-spec §4),
// the equivalent of an --experimental switch. A per-feature override (WithOverrides)
// still takes precedence over this. BETA/GA features are unaffected.
func WithExperimental(allow bool) Option {
return func(c *config) error {
c.allowAlpha = allow
return nil
}
}