Skip to content

Commit d726cca

Browse files
committed
Add support for capability detection
Crossplane v2.2 introduces capability advertisement. Crossplane sends the capabilities it supports in the request metadata, allowing functions to detect whether the calling Crossplane will honor particular request or response fields (e.g. schema requirements, conditions). This commit updates the protos to include the new Capability enum and RequestMeta.capabilities field, and adds a request.has_capability helper that checks whether a specific capability is present. Signed-off-by: Nic Cope <nicc@rk0n.org>
1 parent 21d3696 commit d726cca

File tree

8 files changed

+282
-94
lines changed

8 files changed

+282
-94
lines changed

crossplane/function/proto/v1/run_function.proto

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,44 @@ message RequestMeta {
163163
// An opaque string identifying a request. Requests with identical tags will
164164
// be otherwise identical.
165165
string tag = 1;
166+
167+
// Capabilities supported by this version of Crossplane. Functions may use
168+
// this to determine whether Crossplane will honor certain fields in their
169+
// response, or populate certain fields in their request.
170+
repeated Capability capabilities = 2;
171+
}
172+
173+
// Capability indicates that Crossplane supports a particular feature.
174+
// Functions can check for capabilities to determine whether Crossplane will
175+
// honor a particular request or response field.
176+
enum Capability {
177+
CAPABILITY_UNSPECIFIED = 0;
178+
179+
// Crossplane sends capabilities in RequestMeta. If this capability is
180+
// present, the function knows that if another capability is absent, it's
181+
// because Crossplane doesn't support it (not because Crossplane predates
182+
// capability advertisement). Added in Crossplane v2.2.
183+
CAPABILITY_CAPABILITIES = 1;
184+
185+
// Crossplane supports the requirements.resources field. Functions can return
186+
// resource requirements and Crossplane will fetch the requested resources and
187+
// return them in required_resources. Added in Crossplane v1.15.
188+
CAPABILITY_REQUIRED_RESOURCES = 2;
189+
190+
// Crossplane supports the credentials field. Functions can receive
191+
// credentials from secrets specified in the Composition. Added in Crossplane
192+
// v1.16.
193+
CAPABILITY_CREDENTIALS = 3;
194+
195+
// Crossplane supports the conditions field. Functions can return status
196+
// conditions to be applied to the XR and optionally its claim. Added in
197+
// Crossplane v1.17.
198+
CAPABILITY_CONDITIONS = 4;
199+
200+
// Crossplane supports the requirements.schemas field. Functions can request
201+
// OpenAPI schemas and Crossplane will return them in required_schemas. Added
202+
// in Crossplane v2.2.
203+
CAPABILITY_REQUIRED_SCHEMAS = 5;
166204
}
167205

168206
// Requirements that must be satisfied for a function to run successfully.
@@ -295,7 +333,7 @@ message Resource {
295333
// * A function should set this field to READY_TRUE in a RunFunctionResponse
296334
// to indicate that a desired XR is ready. This overwrites the standard
297335
// readiness detection that determines the ready state of the composite by the
298-
// ready state of the the composed resources.
336+
// ready state of the composed resources.
299337
//
300338
// Ready is only used for composition. It's ignored by Operations.
301339
Ready ready = 3;

crossplane/function/proto/v1/run_function_pb2.py

Lines changed: 46 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crossplane/function/proto/v1/run_function_pb2.pyi

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ from typing import ClassVar as _ClassVar, Optional as _Optional, Union as _Union
1111

1212
DESCRIPTOR: _descriptor.FileDescriptor
1313

14+
class Capability(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
15+
__slots__ = ()
16+
CAPABILITY_UNSPECIFIED: _ClassVar[Capability]
17+
CAPABILITY_CAPABILITIES: _ClassVar[Capability]
18+
CAPABILITY_REQUIRED_RESOURCES: _ClassVar[Capability]
19+
CAPABILITY_CREDENTIALS: _ClassVar[Capability]
20+
CAPABILITY_CONDITIONS: _ClassVar[Capability]
21+
CAPABILITY_REQUIRED_SCHEMAS: _ClassVar[Capability]
22+
1423
class Ready(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
1524
__slots__ = ()
1625
READY_UNSPECIFIED: _ClassVar[Ready]
@@ -36,6 +45,12 @@ class Status(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
3645
STATUS_CONDITION_UNKNOWN: _ClassVar[Status]
3746
STATUS_CONDITION_TRUE: _ClassVar[Status]
3847
STATUS_CONDITION_FALSE: _ClassVar[Status]
48+
CAPABILITY_UNSPECIFIED: Capability
49+
CAPABILITY_CAPABILITIES: Capability
50+
CAPABILITY_REQUIRED_RESOURCES: Capability
51+
CAPABILITY_CREDENTIALS: Capability
52+
CAPABILITY_CONDITIONS: Capability
53+
CAPABILITY_REQUIRED_SCHEMAS: Capability
3954
READY_UNSPECIFIED: Ready
4055
READY_TRUE: Ready
4156
READY_FALSE: Ready
@@ -145,10 +160,12 @@ class RunFunctionResponse(_message.Message):
145160
def __init__(self, meta: _Optional[_Union[ResponseMeta, _Mapping]] = ..., desired: _Optional[_Union[State, _Mapping]] = ..., results: _Optional[_Iterable[_Union[Result, _Mapping]]] = ..., context: _Optional[_Union[_struct_pb2.Struct, _Mapping]] = ..., requirements: _Optional[_Union[Requirements, _Mapping]] = ..., conditions: _Optional[_Iterable[_Union[Condition, _Mapping]]] = ..., output: _Optional[_Union[_struct_pb2.Struct, _Mapping]] = ...) -> None: ...
146161

147162
class RequestMeta(_message.Message):
148-
__slots__ = ("tag",)
163+
__slots__ = ("tag", "capabilities")
149164
TAG_FIELD_NUMBER: _ClassVar[int]
165+
CAPABILITIES_FIELD_NUMBER: _ClassVar[int]
150166
tag: str
151-
def __init__(self, tag: _Optional[str] = ...) -> None: ...
167+
capabilities: _containers.RepeatedScalarFieldContainer[Capability]
168+
def __init__(self, tag: _Optional[str] = ..., capabilities: _Optional[_Iterable[_Union[Capability, str]]] = ...) -> None: ...
152169

153170
class Requirements(_message.Message):
154171
__slots__ = ("extra_resources", "resources", "schemas")

crossplane/function/proto/v1beta1/run_function.proto

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,44 @@ message RequestMeta {
165165
// An opaque string identifying a request. Requests with identical tags will
166166
// be otherwise identical.
167167
string tag = 1;
168+
169+
// Capabilities supported by this version of Crossplane. Functions may use
170+
// this to determine whether Crossplane will honor certain fields in their
171+
// response, or populate certain fields in their request.
172+
repeated Capability capabilities = 2;
173+
}
174+
175+
// Capability indicates that Crossplane supports a particular feature.
176+
// Functions can check for capabilities to determine whether Crossplane will
177+
// honor a particular request or response field.
178+
enum Capability {
179+
CAPABILITY_UNSPECIFIED = 0;
180+
181+
// Crossplane sends capabilities in RequestMeta. If this capability is
182+
// present, the function knows that if another capability is absent, it's
183+
// because Crossplane doesn't support it (not because Crossplane predates
184+
// capability advertisement). Added in Crossplane v2.2.
185+
CAPABILITY_CAPABILITIES = 1;
186+
187+
// Crossplane supports the requirements.resources field. Functions can return
188+
// resource requirements and Crossplane will fetch the requested resources and
189+
// return them in required_resources. Added in Crossplane v1.15.
190+
CAPABILITY_REQUIRED_RESOURCES = 2;
191+
192+
// Crossplane supports the credentials field. Functions can receive
193+
// credentials from secrets specified in the Composition. Added in Crossplane
194+
// v1.16.
195+
CAPABILITY_CREDENTIALS = 3;
196+
197+
// Crossplane supports the conditions field. Functions can return status
198+
// conditions to be applied to the XR and optionally its claim. Added in
199+
// Crossplane v1.17.
200+
CAPABILITY_CONDITIONS = 4;
201+
202+
// Crossplane supports the requirements.schemas field. Functions can request
203+
// OpenAPI schemas and Crossplane will return them in required_schemas. Added
204+
// in Crossplane v2.2.
205+
CAPABILITY_REQUIRED_SCHEMAS = 5;
168206
}
169207

170208
// Requirements that must be satisfied for a function to run successfully.
@@ -297,7 +335,7 @@ message Resource {
297335
// * A function should set this field to READY_TRUE in a RunFunctionResponse
298336
// to indicate that a desired XR is ready. This overwrites the standard
299337
// readiness detection that determines the ready state of the composite by the
300-
// ready state of the the composed resources.
338+
// ready state of the composed resources.
301339
//
302340
// Ready is only used for composition. It's ignored by Operations.
303341
Ready ready = 3;

0 commit comments

Comments
 (0)