Skip to content

Commit

Permalink
feat(efs): crossplane#587 implement efs mounttarget
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Haar <chhaar30@googlemail.com>
  • Loading branch information
haarchri authored and negz committed Aug 15, 2021
1 parent cb30a0b commit aca2180
Show file tree
Hide file tree
Showing 15 changed files with 1,333 additions and 5 deletions.
56 changes: 56 additions & 0 deletions apis/efs/v1alpha1/custom_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,59 @@ type CustomFileSystemParameters struct {
// +optional
KMSKeyIDSelector *xpv1.Selector `json:"kmsKeyIdSelector,omitempty"`
}

// CustomMountTargetParameters contains the additional fields for MountTargetParameters.
type CustomMountTargetParameters struct {

// Up to five VPC security group IDs, of the form sg-xxxxxxxx. These must be
// for the same VPC as subnet specified.
// +immutable
// +optional
SecurityGroups []string `json:"securityGroups,omitempty"`

// SecurityGroupIDRefs are references to SecurityGroups used to set
// the SecurityGroupIDs.
// +immutable
// +optional
SecurityGroupsRefs []xpv1.Reference `json:"securityGroupsRefs,omitempty"`

// SecurityGroupIDSelector selects references to SecurityGroups used
// to set the SecurityGroupIDs.
// +immutable
// +optional
SecurityGroupsSelector *xpv1.Selector `json:"securityGroupsSelector,omitempty"`

// The ID of the file system for which to create the mount target.
// +immutable
// +optional
FileSystemID *string `json:"fileSystemID,omitempty"`

// FileSystemIDRef are references to Filesystem used to set
// the FileSystemID.
// +immutable
// +optional
FileSystemIDRef *xpv1.Reference `json:"fileSystemIDRef,omitempty"`

// FileSystemIDSelector selects references to Filesystem used
// to set the FileSystemID.
// +immutable
// +optional
FileSystemIDSelector *xpv1.Selector `json:"fileSystemIDSelector,omitempty"`

// The ID of the subnet to add the mount target in.
// +immutable
// +optional
SubnetID *string `json:"subnetID"`

// SubnetIDRef are references to Subnet used to set
// the SubnetID.
// +immutable
// +optional
SubnetIDRef *xpv1.Reference `json:"subnetIDRef,omitempty"`

// SubnetIDSelector selects references to Subnet used
// to set the SubnetID.
// +immutable
// +optional
SubnetIDSelector *xpv1.Selector `json:"subnetIDSelector,omitempty"`
}
12 changes: 10 additions & 2 deletions apis/efs/v1alpha1/generator-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
ignore:
resource_names:
- AccessPoint
- MountTarget
field_paths:
- CreateFileSystemInput.CreationToken
- CreateFileSystemInput.ProvisionedThroughputInMibps
- UpdateFileSystemInput.ProvisionedThroughputInMibps
- FileSystemDescription.ProvisionedThroughputInMibps
- FileSystemDescription.ProvisionedThroughputInMibps
- CreateMountTargetInput.SecurityGroups
- CreateMountTargetInput.FileSystemId
- CreateMountTargetInput.SubnetId
resources:
MountTarget:
exceptions:
errors:
404:
code: MountTargetNotFound
54 changes: 52 additions & 2 deletions apis/efs/v1alpha1/referencers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import (

"github.com/crossplane/crossplane-runtime/pkg/reference"

"github.com/crossplane/provider-aws/apis/kms/v1alpha1"
network "github.com/crossplane/provider-aws/apis/ec2/v1beta1"
kms "github.com/crossplane/provider-aws/apis/kms/v1alpha1"
)

// ResolveReferences of this FileSystem
Expand All @@ -36,7 +37,7 @@ func (mg *FileSystem) ResolveReferences(ctx context.Context, c client.Reader) er
CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.KMSKeyID),
Reference: mg.Spec.ForProvider.KMSKeyIDRef,
Selector: mg.Spec.ForProvider.KMSKeyIDSelector,
To: reference.To{Managed: &v1alpha1.Key{}, List: &v1alpha1.KeyList{}},
To: reference.To{Managed: &kms.Key{}, List: &kms.KeyList{}},
Extract: reference.ExternalName(),
})
if err != nil {
Expand All @@ -46,3 +47,52 @@ func (mg *FileSystem) ResolveReferences(ctx context.Context, c client.Reader) er
mg.Spec.ForProvider.KMSKeyIDRef = rsp.ResolvedReference
return nil
}

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

// Resolve spec.forProvider.securityGroups
mrsp, err := r.ResolveMultiple(ctx, reference.MultiResolutionRequest{
CurrentValues: mg.Spec.ForProvider.SecurityGroups,
References: mg.Spec.ForProvider.SecurityGroupsRefs,
Selector: mg.Spec.ForProvider.SecurityGroupsSelector,
To: reference.To{Managed: &network.SecurityGroup{}, List: &network.SecurityGroupList{}},
Extract: reference.ExternalName(),
})
if err != nil {
return errors.Wrap(err, "spec.forProvider.securityGroups")
}
mg.Spec.ForProvider.SecurityGroups = mrsp.ResolvedValues
mg.Spec.ForProvider.SecurityGroupsRefs = mrsp.ResolvedReferences

// Resolve spec.forProvider.subnetID
rsp, err := r.Resolve(ctx, reference.ResolutionRequest{
CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.SubnetID),
Reference: mg.Spec.ForProvider.SubnetIDRef,
Selector: mg.Spec.ForProvider.SubnetIDSelector,
To: reference.To{Managed: &network.Subnet{}, List: &network.SubnetList{}},
Extract: reference.ExternalName(),
})
if err != nil {
return errors.Wrap(err, "spec.forProvider.subnetID")
}
mg.Spec.ForProvider.SubnetID = reference.ToPtrValue(rsp.ResolvedValue)
mg.Spec.ForProvider.SubnetIDRef = rsp.ResolvedReference

// Resolve spec.forProvider.fileSystemID
rsp, err = r.Resolve(ctx, reference.ResolutionRequest{
CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.FileSystemID),
Reference: mg.Spec.ForProvider.FileSystemIDRef,
Selector: mg.Spec.ForProvider.FileSystemIDSelector,
To: reference.To{Managed: &FileSystem{}, List: &FileSystemList{}},
Extract: reference.ExternalName(),
})
if err != nil {
return errors.Wrap(err, "spec.forProvider.fileSystemID")
}
mg.Spec.ForProvider.FileSystemID = reference.ToPtrValue(rsp.ResolvedValue)
mg.Spec.ForProvider.FileSystemIDRef = rsp.ResolvedReference

return nil
}
Loading

0 comments on commit aca2180

Please sign in to comment.