|
| 1 | +--- |
| 2 | +title: Managed Resource Definitions |
| 3 | +weight: 10 |
| 4 | +description: Understand Managed Resource Definitions (MRDs) and selective resource activation |
| 5 | +--- |
| 6 | + |
| 7 | +Managed Resource Definitions (MRDs) provide a lightweight abstraction over |
| 8 | +Kubernetes Custom Resource Definitions (CRDs) that enables selective |
| 9 | +installation and better documentation of managed resources. |
| 10 | + |
| 11 | +{{< hint "note" >}} |
| 12 | +MRDs are available in Crossplane v2.0+ as an alpha feature. |
| 13 | +{{< /hint >}} |
| 14 | + |
| 15 | +## What are managed resource definitions? |
| 16 | + |
| 17 | +A Managed Resource Definition (MRD) is essentially a CRD with additional |
| 18 | +metadata that provides: |
| 19 | + |
| 20 | +* **Connection details schema** - Documents what connection details the |
| 21 | + managed resource provides |
| 22 | +* **Activation control** - Controls whether the underlying CRD gets installed |
| 23 | + in your cluster |
| 24 | +* **Resource discovery** - Makes it easier to understand what resources are |
| 25 | + available |
| 26 | + |
| 27 | +**Every managed resource in a provider package has an associated MRD.** The MRD |
| 28 | +contains the same schema as the CRD, plus additional Crossplane-specific |
| 29 | +metadata. |
| 30 | + |
| 31 | +```mermaid |
| 32 | +flowchart LR |
| 33 | + provider(Provider Package) |
| 34 | + mrd(MRD) |
| 35 | + crd(CRD) |
| 36 | + mr(Managed Resource) |
| 37 | + |
| 38 | + provider --> mrd |
| 39 | + mrd --"when active"--> crd |
| 40 | + crd --> mr |
| 41 | + |
| 42 | + style mrd fill:#e1f5fe |
| 43 | + style crd fill:#f3e5f5 |
| 44 | +``` |
| 45 | + |
| 46 | +## Why use managed resource definitions? |
| 47 | + |
| 48 | +MRDs solve several challenges with traditional provider packages: |
| 49 | + |
| 50 | +### Performance optimization |
| 51 | +Installing a provider creates CRDs for _every_ managed resource the provider |
| 52 | +supports. For large providers like AWS, this can mean hundreds of CRDs that |
| 53 | +you may never use. |
| 54 | + |
| 55 | +**MRDs let you install only the CRDs you need**, reducing Kubernetes API |
| 56 | +server overhead and improving cluster performance. |
| 57 | + |
| 58 | +### Connection details discovery |
| 59 | +Understanding what connection details a managed resource provides requires |
| 60 | +reading provider source code or trial-and-error testing. |
| 61 | + |
| 62 | +**MRDs document connection details in the schema**, making it clear what |
| 63 | +credentials and endpoints each resource provides. |
| 64 | + |
| 65 | +### Selective installation |
| 66 | +Different environments may need different subsets of managed resources. A |
| 67 | +development environment might only need basic resources, while production |
| 68 | +needs the full set. |
| 69 | + |
| 70 | +**MRDs enable environment-specific resource activation** through policies. |
| 71 | + |
| 72 | +## How MRDs work |
| 73 | + |
| 74 | +When you install a provider package, Crossplane creates: |
| 75 | + |
| 76 | +1. **MRDs for all resources** - Every managed resource gets an MRD |
| 77 | +2. **CRDs only when activated** - Crossplane creates CRDs only for active MRDs |
| 78 | +3. **Activation policies** - ManagedResourceActivationPolicy controls which |
| 79 | + MRDs become active |
| 80 | + |
| 81 | +### MRD lifecycle |
| 82 | + |
| 83 | +```mermaid |
| 84 | +flowchart TD |
| 85 | + install[Install Provider] |
| 86 | + createMRD[Create MRDs] |
| 87 | + checkPolicy{Activation Policy<br/>Matches?} |
| 88 | + activate[Activate MRD] |
| 89 | + createCRD[Create CRD] |
| 90 | + inactive[MRD Inactive] |
| 91 | + |
| 92 | + install --> createMRD |
| 93 | + createMRD --> checkPolicy |
| 94 | + checkPolicy -->|Yes| activate |
| 95 | + checkPolicy -->|No| inactive |
| 96 | + activate --> createCRD |
| 97 | + |
| 98 | + style activate fill:#c8e6c9 |
| 99 | + style inactive fill:#ffcdd2 |
| 100 | +``` |
| 101 | + |
| 102 | +### MRD states |
| 103 | + |
| 104 | +MRDs can be in one of two states: |
| 105 | + |
| 106 | +* **Active** - The underlying CRD exists and you can create managed resources |
| 107 | +* **Inactive** - No CRD exists, managed resource creation fails |
| 108 | + |
| 109 | +You can change an MRD's state by: |
| 110 | +* Editing the MRD directly (`spec.state: Active`) |
| 111 | +* Using a ManagedResourceActivationPolicy |
| 112 | +* Provider package capabilities (SafeStart) |
| 113 | + |
| 114 | +## Connection details schema |
| 115 | + |
| 116 | +MRDs document the connection details that managed resources provide. This makes |
| 117 | +it easier to understand what credentials and endpoints you get when creating |
| 118 | +resources. |
| 119 | + |
| 120 | +```yaml |
| 121 | +apiVersion: apiextensions.crossplane.io/v1alpha1 |
| 122 | +kind: ManagedResourceDefinition |
| 123 | +metadata: |
| 124 | + name: instances.ec2.aws.crossplane.io |
| 125 | +spec: |
| 126 | + connectionDetails: |
| 127 | + - name: endpoint |
| 128 | + description: The connection endpoint for the database |
| 129 | + type: string |
| 130 | + - name: port |
| 131 | + description: The port number for connections |
| 132 | + type: integer |
| 133 | + - name: username |
| 134 | + description: The master username for the database |
| 135 | + type: string |
| 136 | + - name: password |
| 137 | + description: The master password for the database |
| 138 | + type: string |
| 139 | + fromConnectionSecretKey: password |
| 140 | +``` |
| 141 | +
|
| 142 | +The `connectionDetails` field documents: |
| 143 | +* **Connection detail names** - What keys appear in connection secrets |
| 144 | +* **Descriptions** - What each connection detail contains |
| 145 | +* **Types** - The data type of each detail |
| 146 | +* **Source keys** - How details map from provider responses |
| 147 | + |
| 148 | +## Managed Resource Activation Policy |
| 149 | + |
| 150 | +ManagedResourceActivationPolicy (MRAP) provides pattern-based control over |
| 151 | +which MRDs become active. This is more scalable than manually activating |
| 152 | +individual MRDs. |
| 153 | + |
| 154 | +```yaml |
| 155 | +apiVersion: apiextensions.crossplane.io/v1alpha1 |
| 156 | +kind: ManagedResourceActivationPolicy |
| 157 | +metadata: |
| 158 | + name: aws-core-resources |
| 159 | +spec: |
| 160 | + activations: |
| 161 | + - "instances.ec2.aws.crossplane.io" # Specific MRD |
| 162 | + - "*.rds.aws.crossplane.io" # All RDS resources |
| 163 | + - "buckets.s3.aws.crossplane.io" # S3 buckets |
| 164 | +``` |
| 165 | + |
| 166 | +### Activation patterns |
| 167 | + |
| 168 | +MRAP supports several activation patterns: |
| 169 | + |
| 170 | +* **Exact match**: `instances.ec2.aws.crossplane.io` |
| 171 | +* **Wildcard prefix**: `*.rds.aws.crossplane.io` (all RDS resources) |
| 172 | +* **Provider wildcard**: `*.aws.crossplane.io` (all AWS resources) |
| 173 | + |
| 174 | +Multiple MRAPs can exist, and their activations are combined. |
| 175 | + |
| 176 | +## Provider capabilities |
| 177 | + |
| 178 | +Providers can declare capabilities that affect MRD behavior: |
| 179 | + |
| 180 | +### SafeStart capability |
| 181 | +Providers with the `SafeStart` capability start with all MRDs inactive by |
| 182 | +default. This prevents performance issues when installing large providers. |
| 183 | + |
| 184 | +Without SafeStart, all MRDs are active by default for backward compatibility. |
| 185 | + |
| 186 | +```yaml |
| 187 | +# In provider package metadata |
| 188 | +spec: |
| 189 | + capabilities: |
| 190 | + - name: SafeStart |
| 191 | +``` |
| 192 | + |
| 193 | +{{< hint "note" >}} |
| 194 | +Implementing SafeStart requires significant provider code changes. Provider |
| 195 | +developers should follow the |
| 196 | +[SafeStart implementation guide]({{< ref "../guides/implementing-safestart" >}}) |
| 197 | +for detailed technical requirements and examples. |
| 198 | +{{< /hint >}} |
| 199 | + |
| 200 | +### SafeStart implementation examples |
| 201 | + |
| 202 | +The Crossplane community has implemented SafeStart in several providers: |
| 203 | + |
| 204 | +* **provider-nop** - [Reference implementation](https://github.com/crossplane-contrib/provider-nop/pull/24) |
| 205 | + showing SafeStart integration with both namespaced and cluster-scoped resources |
| 206 | +* **provider-aws** - Large provider demonstrating SafeStart performance benefits |
| 207 | + |
| 208 | +These implementations provide real-world examples of: |
| 209 | +- MRD controller integration |
| 210 | +- Build process modifications |
| 211 | +- Testing strategies for SafeStart behavior |
| 212 | +- Migration approaches for existing users |
| 213 | + |
| 214 | +## Key concepts |
| 215 | + |
| 216 | +Understanding these terms helps when working with MRDs: |
| 217 | + |
| 218 | +* **MRD** - The definition that may or may not have an active CRD |
| 219 | +* **MRAP** - Policy that controls which MRDs become active |
| 220 | +* **Active state** - MRD has an underlying CRD, resources can be created |
| 221 | +* **Inactive state** - No CRD exists, resource creation fails |
| 222 | +* **SafeStart** - Provider capability that defaults MRDs to inactive |
| 223 | +* **Connection details schema** - Documentation of what connection details |
| 224 | + a managed resource provides |
| 225 | + |
| 226 | +## Relationship to other Crossplane features |
| 227 | + |
| 228 | +MRDs integrate with existing Crossplane concepts: |
| 229 | + |
| 230 | +* **Providers** - Create MRDs when installed |
| 231 | +* **Managed resources** - Can only be created when their MRD is active |
| 232 | +* **Compositions** - Can reference both active and inactive managed resources |
| 233 | + (composition validation occurs at render time) |
| 234 | +* **Claims** - Work normally once the underlying managed resources are active |
| 235 | + |
| 236 | +MRDs are backward compatible. Existing providers and compositions continue to |
| 237 | +work without modification. |
0 commit comments