transformers

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver transforms the source resolver implementations so that the resolution source managed resources are no longer statically typed and thus, the implementations no longer need to import the corresponding API packages. This transformer is helpful in preventing the import cycles described in https://github.com/crossplane/upjet/issues/96 and elsewhere. Please see TransformPackages for the details of the transformation applied.

func NewResolver

func NewResolver(fs afero.Fs, apiGroupSuffix, apiResolverPackage string, ignorePackageLoadErrors bool, logger logging.Logger, opts ...ResolverOption) *Resolver

NewResolver initializes a new Resolver with the specified configuration.

func (*Resolver) TransformPackages

func (r *Resolver) TransformPackages(resolverFilePattern string, patterns ...string) error

TransformPackages applies the dynamic resolver transformation to the resolver modules loaded from the specified patterns and implemented in the specified resolver files. If `r.ignorePackageLoadErrors` is set, any errors encountered while loading the source packages are ignored. This may be required when the transformation source files have compile errors, such as import cycles. The transformed resolver implementations will use the specified API group suffix, such as, "aws.upbound.io" when determining the API groups of the resolution source managed resources. A sample transformation implemented by this transformer is from: ```

func (mg *Subnet) ResolveReferences(ctx context.Context, c client.Reader) error {
  r := reference.NewAPIResolver(c, mg)

  var rsp reference.ResolutionResponse
  var err error

  rsp, err = r.Resolve(ctx, reference.ResolutionRequest{
    CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.VPCID),
    Extract:      reference.ExternalName(),
    Reference:    mg.Spec.ForProvider.VPCIDRef,
    Selector:     mg.Spec.ForProvider.VPCIDSelector,
    To: reference.To{
      List:    &VPCList{},
      Managed: &VPC{},
    },
  })
  if err != nil {
    return errors.Wrap(err, "mg.Spec.ForProvider.VPCID")
  }
  mg.Spec.ForProvider.VPCID = reference.ToPtrValue(rsp.ResolvedValue)
  mg.Spec.ForProvider.VPCIDRef = rsp.ResolvedReference

``` to the following: ```

func (mg *Subnet) ResolveReferences(ctx context.Context, c client.Reader) error {
  var m xpresource.Managed
  var l xpresource.ManagedList
  r := reference.NewAPIResolver(c, mg)

  var rsp reference.ResolutionResponse
  var err error
  {
    m, l, err = apisresolver.GetManagedResource("ec2.aws.upbound.io", "v1beta1", "VPC", "VPCList")
    if err != nil {
      return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution")
    }

    rsp, err = r.Resolve(ctx, reference.ResolutionRequest{
      CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.VPCID),
      Extract:      reference.ExternalName(),
      Reference:    mg.Spec.ForProvider.VPCIDRef,
      Selector:     mg.Spec.ForProvider.VPCIDSelector,
      To:           reference.To{List: l, Managed: m},
    })
  }
  if err != nil {
    return errors.Wrap(err, "mg.Spec.ForProvider.VPCID")
  }
  mg.Spec.ForProvider.VPCID = reference.ToPtrValue(rsp.ResolvedValue)
  mg.Spec.ForProvider.VPCIDRef = rsp.ResolvedReference

```

type ResolverOption

type ResolverOption func(resolver *Resolver)

ResolverOption is an option used to configure the Resolver.

func WithAPIGroupOverrides

func WithAPIGroupOverrides(overrides map[string]string) ResolverOption

WithAPIGroupOverrides configures the API group overrides for a Resolver. Certain providers need to rename the short API group names they use, breaking the convention that the short group name matches the package name. An example is upbound/provider-azure, where the ResourceGroup.azure resource's short API group is the empty string.

func WithLoaderConfig

func WithLoaderConfig(c *packages.Config) ResolverOption

WithLoaderConfig configures the package loader config for a Resolver.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL