Documentation
¶
Overview ¶
Package preview manages preview feature gates enabled via the --preview flag.
The gates are process-wide. A binary calls Init exactly once, before anything calls IsEnabled or AsMap.
Index ¶
- Constants
- func AsMap() map[string]bool
- func ContextWithOptIn(ctx context.Context) context.Context
- func ContextWithOptOut(ctx context.Context) context.Context
- func DialOptionsWithOptIn() []grpc.DialOption
- func DisabledMap() map[string]bool
- func Init(values ...string) error
- func InitForTest(tb testingTB, values ...string)
- func InitForTestFake(tb testingTB, fakeKnownGates []Gate, values ...string)
- func IsEnabled(gate Gate) bool
- func IsEnabledFor(ctx context.Context, gate Gate) bool
- func IsOptedOut(ctx context.Context) bool
- func StreamServerInterceptor(srv any, ss grpc.ServerStream, _ *grpc.StreamServerInfo, ...) error
- func UnaryServerInterceptor(ctx context.Context, req any, _ *grpc.UnaryServerInfo, ...) (any, error)
- func Verify(values ...string) error
- type Gate
Constants ¶
const All = "ALL"
All is the pseudo-gate name that enables every known gate.
const Header = "Ate-Preview-Allowed"
Header is the gRPC metadata key with which an API client says it intends to use preview features. It is a coarse guard against using them by accident, not an access control: any client may send it, and it applies to every enabled gate at once. Its value is a boolean, e.g. "true".
Variables ¶
This section is empty.
Functions ¶
func AsMap ¶
AsMap returns the map of known gate names to their enabled state. The returned map MUST NOT be modified.
TODO: Fix this to use an interface when DV supports it.
func ContextWithOptIn ¶
ContextWithOptIn marks ctx as being opted-in to preview features, overriding any earlier ContextWithOptOut. Code which acts for the system rather than for a user, such as workflows, uses it so that work which an API request started is not limited by that request's opt-out.
func ContextWithOptOut ¶
ContextWithOptOut marks ctx as being opted-out from preview features.
func DialOptionsWithOptIn ¶
func DialOptionsWithOptIn() []grpc.DialOption
DialOptionsWithOptIn returns gRPC dial options which send Header on every call made over the connection.
func DisabledMap ¶
DisabledMap returns the map of known gate names, all disabled. The returned map MUST NOT be modified.
TODO: Fix this to use an interface when DV supports it.
func Init ¶
Init sets the process-wide preview gates from the --preview flag values. The special value All enables all known gates. With no values, all gates are disabled. It panics if called again after the first successful call.
func InitForTest ¶
func InitForTest(tb testingTB, values ...string)
InitForTest sets the process-wide preview gates for the duration of tb, as Init would with values, and restores the previous state when tb ends. It may be called whether or not Init has been. Tests that use it must not run in parallel.
func InitForTestFake ¶
InitForTestFake is InitForTest with fake gate names. Tests of the preview gate system itself should use this to avoid depending on the real gate names. Tests that use it must not run in parallel.
func IsEnabled ¶
IsEnabled reports whether the given preview gate is enabled. Unknown gates are always treated as disabled.
func IsEnabledFor ¶
IsEnabledFor reports whether gate is enabled in this process and ctx has not opted-out of preview features.
func IsOptedOut ¶
IsOptedOut reports whether the context has opted-out of using preview features. By default, contexts are allowed to use preview, but some call-paths (e.g. public API) may restrict that, so we provide this mechanism to explicitly opt out.
func StreamServerInterceptor ¶
func StreamServerInterceptor(srv any, ss grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error
StreamServerInterceptor restricts each stream that did not send Header.
func UnaryServerInterceptor ¶
func UnaryServerInterceptor(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error)
UnaryServerInterceptor restricts each request that did not send Header.
Types ¶
type Gate ¶
type Gate string
Gate identifies a gate-controlled preview feature. Preview gates are disabled by default, except:
- when a gated feature becomes "stable" (aka GA)
- when a gated feature is removed
In both cases, the gate is retained for a while (for compatibility with existing uses of the --preview flag), but the feature is either always enabled or totally disabled, respectively. Such gates are "vestigial".
const ( // GateExternalVolumes controls whether external volumes are supported. GateExternalVolumes Gate = "ExternalVolumes" // GateGoldenEgressPolicy controls configuring a golden actor's egress policy on its template. GateGoldenEgressPolicy Gate = "GoldenEgressPolicy" // GatePerTemplateSnapshotLocation controls whether an ActorTemplate's // snapshotConfig.storage_location is honored. When disabled, snapshots // are stored under ate-api-server's --snapshot-location. GatePerTemplateSnapshotLocation Gate = "PerTemplateSnapshotLocation" )
Gates should always be named in UpperCamelCase. Please keep this list sorted alphabetically by value.