Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 57 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,31 @@ considered capable of satisfying crossplane-runtime's interfaces based on the
heuristics described in the [Provider Development Guide], for example a
managed resource must:

* Embed a [`ResourceStatus`] struct in their `Status` struct.
* Embed a [`ResourceSpec`] struct in their `Spec` struct.
* Embed a `Parameters` struct in their `Spec` struct.
- Embed a [`ResourceStatus`] or [`ManagedResourceStatus`] struct in their `Status` struct.
- Embed a [`ResourceSpec`], [`ManagedResourceSpec`], or [`ClusterManagedResourceSpec`] struct in their `Spec` struct.
- Embed a `Parameters` struct in their `Spec` struct.

The newer [`ManagedResourceSpec`], [`ClusterManagedResourceSpec`], and
[`ManagedResourceStatus`] types from `github.com/crossplane/crossplane/apis/v2/core/v2`
are supported for namespaced and cluster-scoped managed resources respectively.

`angryjet` also supports provider config and provider config usage migrations
across the legacy crossplane-runtime types and the newer core API v2 types:

- Provider configs are detected when their `Status` embeds either the legacy
[`ProviderConfigStatus`] or the core API v2 [`ProviderConfigStatusV2`] type.
- For provider configs that embed the core API v2 status type, generated
condition methods use the core API v2 [`ConditionV2`] and
[`ConditionTypeV2`] types.
- Provider config usages are detected when they embed either the legacy
[`ProviderConfigUsage`] or the newer [`TypedProviderConfigUsage`] type.
- For provider config usages that embed [`TypedProviderConfigUsage`], generated
provider config reference methods use the core API v2
[`ProviderConfigReferenceV2`] type and resource reference methods use the
core API v2 [`TypedReferenceV2`] type.
- Provider config specs that migrate nested credential helper fields such as
[`CredentialsSourceV2`] and [`CommonCredentialSelectorsV2`] continue to be
supported.

Methods are not written if they are already defined outside of the file that
would be generated. Use the `//+crossplane:generate:methods=false` comment
Expand All @@ -31,6 +53,7 @@ the top level of your `api/` directory, for example:
In addition to functions that satisfy `resource.Managed`, you can use `angryjet`
to generate a `ResolveReferences` method as well. In order to generate a resolution
call for given field, you need to add the following comment marker:

```
// +crossplane:generate:reference:type=<target type>
```
Expand All @@ -41,20 +64,26 @@ as `github.com/crossplane/provider-aws/apis/ec2/v1beta1.VPC`.

The generated resolver will use the external name annotation of the target resource
to fetch the value and it assumes that reference field is named as
`FieldNameRef`/`FieldNameRefs if array` and selector field is named as
`FieldNameSelector`. You can override these defaults by adding the optional comment
markers, see the following example:
`FieldNameRef`/`FieldNameRefs if array` and selector field is named as
`FieldNameSelector`.

For cluster-scoped resolvers these fields should use the core API v2
[`ReferenceV2`] and [`SelectorV2`] types. For namespaced resolvers they should
use [`NamespacedReferenceV2`] and [`NamespacedSelectorV2`]. You can override
the default field names by adding the optional comment markers, see the
following example:

```go
type SomeParameters struct {
// +crossplane:generate:reference:type=github.com/crossplane/provider-aws/apis/ec2/v1beta1.Subnet
// +crossplane:generate:reference:extractor=github.com/crossplane/provider-aws/apis/ec2/v1beta1.SubnetARN()
// +crossplane:generate:reference:refFieldName=SubnetIDRefs
// +crossplane:generate:reference:selectorFieldName=SubnetIDSelector
SubnetIDs []string `json:"subnetIds,omitempty"`
SubnetIDRefs []xpv1.Reference `json:"subnetIdRefs,omitempty"`
SubnetIDSelector *xpv1.Selector `json:"subnetIdSelector,omitempty"`

SubnetIDRefs []xpv2.Reference `json:"subnetIdRefs,omitempty"`

SubnetIDSelector *xpv2.Selector `json:"subnetIdSelector,omitempty"`
}
```

Expand Down Expand Up @@ -94,4 +123,21 @@ Args:
[`resource.Managed`]: https://godoc.org/github.com/crossplane/crossplane-runtime/v2/pkg/resource#Managed
[`ResourceSpec`]: https://godoc.org/github.com/crossplane/crossplane-runtime/v2/apis/common/v1#ResourceSpec
[`ResourceStatus`]: https://godoc.org/github.com/crossplane/crossplane-runtime/v2/apis/common/v1#ResourceStatus
[Provider Development Guide]: https://github.com/crossplane/crossplane/blob/master/contributing/guide-provider-development.md#defining-resource-kinds
[`ManagedResourceSpec`]: https://pkg.go.dev/github.com/crossplane/crossplane/apis/v2/core/v2#ManagedResourceSpec
[`ClusterManagedResourceSpec`]: https://pkg.go.dev/github.com/crossplane/crossplane/apis/v2/core/v2#ClusterManagedResourceSpec
[`ManagedResourceStatus`]: https://pkg.go.dev/github.com/crossplane/crossplane/apis/v2/core/v2#ManagedResourceStatus
[`ProviderConfigStatus`]: https://pkg.go.dev/github.com/crossplane/crossplane-runtime/v2/apis/common/v1#ProviderConfigStatus
[`ProviderConfigStatusV2`]: https://pkg.go.dev/github.com/crossplane/crossplane/apis/v2/core/v2#ProviderConfigStatus
[`ConditionV2`]: https://pkg.go.dev/github.com/crossplane/crossplane/apis/v2/core/v2#Condition
[`ConditionTypeV2`]: https://pkg.go.dev/github.com/crossplane/crossplane/apis/v2/core/v2#ConditionType
[`ProviderConfigUsage`]: https://pkg.go.dev/github.com/crossplane/crossplane-runtime/v2/apis/common/v1#ProviderConfigUsage
[`TypedProviderConfigUsage`]: https://pkg.go.dev/github.com/crossplane/crossplane/apis/v2/core/v2#TypedProviderConfigUsage
[`ProviderConfigReferenceV2`]: https://pkg.go.dev/github.com/crossplane/crossplane/apis/v2/core/v2#ProviderConfigReference
[`ReferenceV2`]: https://pkg.go.dev/github.com/crossplane/crossplane/apis/v2/core/v2#Reference
[`SelectorV2`]: https://pkg.go.dev/github.com/crossplane/crossplane/apis/v2/core/v2#Selector
[`NamespacedReferenceV2`]: https://pkg.go.dev/github.com/crossplane/crossplane/apis/v2/core/v2#NamespacedReference
[`NamespacedSelectorV2`]: https://pkg.go.dev/github.com/crossplane/crossplane/apis/v2/core/v2#NamespacedSelector
[`TypedReferenceV2`]: https://pkg.go.dev/github.com/crossplane/crossplane/apis/v2/core/v2#TypedReference
[`CredentialsSourceV2`]: https://pkg.go.dev/github.com/crossplane/crossplane/apis/v2/core/v2#CredentialsSource
[`CommonCredentialSelectorsV2`]: https://pkg.go.dev/github.com/crossplane/crossplane/apis/v2/core/v2#CommonCredentialSelectors
[Provider Development Guide]: https://github.com/crossplane/crossplane/blob/master/contributing/guide-provider-development.md#defining-resource-kinds
Loading
Loading