Composing Infrastructure with Crossplane

Components in an XR
XRD (Composite Resource Definition)
Composition
Claim
XRD (Composite Resource Definition)
Is the schema defining the infrastructure API specification
Is like an OpenAPI Specification or Swagger API definition
The XR namesInfrastructure API name in singular and plural formatThe singular name will eventually become the
kindattribute of the new APINote: It's standard practise to use
Xas prefix for the XR name
API groupgroup the APIs logicallyMetadata nameConcatenation of the plural name of XR and a dot followed by the API group.<resource plural name>.<API group>
VersionsArray that can hold configuration for multiple versions of the sameXRAPIserved and referenceableMandatory Boolean attributes for every defined version.servedindicates if XR API is served with the given versionreferenceableflag, determines if we can define an implementation for the given API version
SchemaActual OpenAPI specificationConnection secret keyslist of keys that need to be created and populated in the k8s Secrets after the resource provisioningComposition referenceWe can have multiple API implementations for the given XRDAnd this section of XRD will help to define the default implementation or enforced implementation
DefaultCompositionRefandEnforcedCompositionRef
Claim namesOptionalCreates a proxy API for the given XR API with specified name
Applying the claim object's create, delete, and update action will create, delete, and update the underlying XR
Composition
Composition will link one or more MRs with an XR API
We can consider XRD as the CRD and
compositionas the custom controller implementationWe can use XR to refer to a new infrastructure API that we're building
Also, the composition resources list can hold both an
MRand an existingXR
XRM, composition, and XR
XRD define what XR would be created
Composition implements XRs and MRs both
Composition configuration
CompositeTypeRefmaps a specific XR version with the current compositionWriteConnectionSecretsToNamespacespecifies namespace for storing the connection SecretsResourcesholds list of MRs.We can define another XR under this section
A mandatory section, and should define at least one resource, either an MR or XR
TransformsWhen applying a patch, Crossplane supports modifying the data before applying it as a patch -transformoperation.These are predefined functions, such as
convert,math,mapetc
Policyare under each path and determines patching behaviourWe can mandate the patch path presence because the default behaviour is to skip the patch if the field is absent
ConnectionDetailsspecified under each resource and will hold the list of secret keys we want to propagate back into the XRReadinessChecksallow us to define any custom readiness logicPatchSetsSet of reusable patch functions that can be used across multiple resources. (Shared reusable function)

Composition Configuration
An
XRDversion can have more than one compositionFor example, we could have different compositions defined for production and staging
CompositionRefwithin XR can refer to a specific compositionCompositionSelectorcan be used to match compositions based on labels

XR and composition relation
Claim
Is a proxy API to the XR, created by providing claim name attributes in XRD configurations
Above,
xclouddbis the XR name andClouddbis the claim nameThis convention is not mandatory
Claims are very similar to th XR
XRs are cluster-level resources
We can keep some XR only as a private API at the cluster level for the platform team's use
Example, platform team may not be interested in exposing the XR API that creates a virtual private network
Claims are namespace level
Enables namespace level authorization
Example, we can assign different permissions for different product teams based on their namespace ownership
This pattern an be ued to support the preprovisioning of infrastructure.
A claim can just reference itself with a preprovisioned XR infrastructure, keeping the provisioning time low.

How does composition work?
Claim yaml:
XR yaml:
XR is always at cluster level
Postprovisioning of an XR
Readiness check
Every resource element in the composition can define its custom readiness logic
MatchStringMatchIntegerNoneUse the None type to consider the readiness as soon as the resource is available:
- type: None
NonEmptyUse NonEmpty to make the resource ready as soon as some value exists in the field of our choice.
Note that fieldPath falls under the status attribute
Patch status
ToCompositeFieldPathis a patch type for copying any attribute from a specific composed resource back into the XRFirst, we need to define the state fields as a part of openAPIV3Schema in the XRD to make the new status fields available in the XR
The next step is to define a patch under the specific composing resource
We can also use the
CombineToCompositepatch type if we need to copy a combination of multiple fields.
Propagating the credentials back
Connection secret-related configuration is part of the XRD, XR, claim, and composition
Define the list of connection secret keys in the XRD using the
ConnectionSecretKeysconfigurationConfigure the composing resources to define how to populate connection keys defined in the XRD. Connection details configuration can be of different types. The FromConnectionSecretKey type is correct when copying the secret from an existing secret key
We have the FromFieldPath type for copying the connection details from one of the composing resource fields
The claim or XR should save the Secrets using the
WriteConnectionSecretToRefconfiguration
Propagating the Secrets
Preprovisioned Resources
Cache the composed recourses
The platform team can provision an XR and keep the resources in the resource pool.
Then, the product team can claim these resources by adding the
ResourceRefconfiguration under the spec of a claim YAML.
Importing existing resources from the external provider into the Crossplane
crossplane.io/external-nameannotation can help with thisMR Yaml example, onboarding existing PVC
What we achieve here is to map the manual resource to a Claim
Last updated