diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 45b0a75..c703af1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ env: # The package to push, without a version tag. The default matches GitHub. For # example xpkg.upbound.io/crossplane/function-template-go. - XPKG: xpkg.upbound.io/${{ github.repository}} + XPKG: xpkg.upbound.io/crossplane-contrib/function-extra-resources # The package version to push. The default is 0.0.0-gitsha. XPKG_VERSION: ${{ inputs.version }} diff --git a/fn.go b/fn.go index 05757fe..0bda531 100644 --- a/fn.go +++ b/fn.go @@ -13,11 +13,12 @@ import ( "github.com/crossplane/crossplane-runtime/pkg/errors" "github.com/crossplane/crossplane-runtime/pkg/fieldpath" "github.com/crossplane/crossplane-runtime/pkg/logging" - "github.com/crossplane/function-extra-resources/input/v1beta1" fnv1beta1 "github.com/crossplane/function-sdk-go/proto/v1beta1" "github.com/crossplane/function-sdk-go/request" "github.com/crossplane/function-sdk-go/resource" "github.com/crossplane/function-sdk-go/response" + + "github.com/crossplane-contrib/function-extra-resources/input/v1beta1" ) // Key to retrieve extras at. diff --git a/go.mod b/go.mod index 0208a83..71eb8e0 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/crossplane/function-extra-resources +module github.com/crossplane-contrib/function-extra-resources go 1.21 diff --git a/input/v1beta1/resource_select.go b/input/v1beta1/resource_select.go index eb1efee..b2d2eb4 100644 --- a/input/v1beta1/resource_select.go +++ b/input/v1beta1/resource_select.go @@ -27,13 +27,13 @@ type InputSpec struct { // `spec.extraResourceRefs` and is only updated if it is null. ExtraResources []ResourceSource `json:"extraResources"` - // Policy represents the Resolve and Resolution policies which apply to - // all ResourceSourceReferences in ExtraResources list. + // Policy represents the Resolution policies which apply to all + // ResourceSourceReferences in ExtraResources list. // +optional - Policy *xpv1.Policy `json:"policy,omitempty"` + Policy *Policy `json:"policy,omitempty"` } -// Policy represents the Resolve and Resolution policies of Reference instance. +// Policy represents the Resolution policy of Reference instance. type Policy struct { // Resolution specifies whether resolution of this reference is required. // The default is 'Required', which means the reconcile will fail if the @@ -45,6 +45,16 @@ type Policy struct { Resolution *xpv1.ResolutionPolicy `json:"resolution,omitempty"` } +// IsResolutionPolicyOptional checks whether the resolution policy of relevant +// reference is Optional. +func (p *Policy) IsResolutionPolicyOptional() bool { + if p == nil || p.Resolution == nil { + return false + } + + return *p.Resolution == xpv1.ResolutionPolicyOptional +} + // ResourceSourceType specifies the way the ExtraResource is selected. type ResourceSourceType string diff --git a/input/v1beta1/zz_generated.deepcopy.go b/input/v1beta1/zz_generated.deepcopy.go index 614d382..32dab3c 100644 --- a/input/v1beta1/zz_generated.deepcopy.go +++ b/input/v1beta1/zz_generated.deepcopy.go @@ -47,7 +47,7 @@ func (in *InputSpec) DeepCopyInto(out *InputSpec) { } if in.Policy != nil { in, out := &in.Policy, &out.Policy - *out = new(v1.Policy) + *out = new(Policy) (*in).DeepCopyInto(*out) } } diff --git a/main.go b/main.go index 88f0def..5d08f76 100644 --- a/main.go +++ b/main.go @@ -31,6 +31,6 @@ func (c *CLI) Run() error { } func main() { - ctx := kong.Parse(&CLI{}, kong.Description("A Crossplane Composition Function.")) + ctx := kong.Parse(&CLI{}, kong.Description("A Crossplane Composition Function to retrieve extra resources to the context.")) ctx.FatalIfErrorf(ctx.Run()) } diff --git a/package/crossplane.yaml b/package/crossplane.yaml index efc618d..953cc7f 100644 --- a/package/crossplane.yaml +++ b/package/crossplane.yaml @@ -2,5 +2,18 @@ apiVersion: meta.pkg.crossplane.io/v1beta1 kind: Function metadata: - name: function-template-go -spec: {} + name: function-extra-resources + annotations: + meta.crossplane.io/maintainer: Crossplane Maintainers + meta.crossplane.io/source: github.com/crossplane-contrib/function-extra-resources + meta.crossplane.io/license: Apache-2.0 + meta.crossplane.io/description: | + A composition function that can retrieve arbitrary cluster-scoped extra resources and add them to the context. + meta.crossplane.io/readme: | + This composition function retrives arbitrary cluster-scoped extra + resources and add them in the specified order into the Context at a + well-known key, apiextensions.crossplane.io/extra-resources, so that they + can be used by other functions. +spec: + crossplane: + version: ">=v1.15.0" diff --git a/package/input/extra-resources.fn.crossplane.io_inputs.yaml b/package/input/extra-resources.fn.crossplane.io_inputs.yaml index 234e3a0..a842c6e 100644 --- a/package/input/extra-resources.fn.crossplane.io_inputs.yaml +++ b/package/input/extra-resources.fn.crossplane.io_inputs.yaml @@ -150,8 +150,8 @@ spec: type: array policy: description: |- - Policy represents the Resolve and Resolution policies which apply to - all ResourceSourceReferences in ExtraResources list. + Policy represents the Resolution policies which apply to all + ResourceSourceReferences in ExtraResources list. properties: resolution: default: Required @@ -164,16 +164,6 @@ spec: - Required - Optional type: string - resolve: - description: |- - Resolve specifies when this reference should be resolved. The default - is 'IfNotPresent', which will attempt to resolve the reference only when - the corresponding field is not present. Use 'Always' to resolve the - reference on every reconcile. - enum: - - Always - - IfNotPresent - type: string type: object required: - extraResources