diff --git a/apis/efs/v1alpha1/custom_types.go b/apis/efs/v1alpha1/custom_types.go index 89f76038d3..aee0c9e5c7 100644 --- a/apis/efs/v1alpha1/custom_types.go +++ b/apis/efs/v1alpha1/custom_types.go @@ -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"` +} diff --git a/apis/efs/v1alpha1/generator-config.yaml b/apis/efs/v1alpha1/generator-config.yaml index e97eeaadce..0fb779193b 100644 --- a/apis/efs/v1alpha1/generator-config.yaml +++ b/apis/efs/v1alpha1/generator-config.yaml @@ -1,9 +1,17 @@ ignore: resource_names: - AccessPoint - - MountTarget field_paths: - CreateFileSystemInput.CreationToken - CreateFileSystemInput.ProvisionedThroughputInMibps - UpdateFileSystemInput.ProvisionedThroughputInMibps - - FileSystemDescription.ProvisionedThroughputInMibps \ No newline at end of file + - FileSystemDescription.ProvisionedThroughputInMibps + - CreateMountTargetInput.SecurityGroups + - CreateMountTargetInput.FileSystemId + - CreateMountTargetInput.SubnetId +resources: + MountTarget: + exceptions: + errors: + 404: + code: MountTargetNotFound diff --git a/apis/efs/v1alpha1/referencers.go b/apis/efs/v1alpha1/referencers.go index 253225ca32..f0f0835049 100644 --- a/apis/efs/v1alpha1/referencers.go +++ b/apis/efs/v1alpha1/referencers.go @@ -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 @@ -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 { @@ -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 +} diff --git a/apis/efs/v1alpha1/zz_generated.deepcopy.go b/apis/efs/v1alpha1/zz_generated.deepcopy.go index bbf6ce29f9..75ded9e05e 100644 --- a/apis/efs/v1alpha1/zz_generated.deepcopy.go +++ b/apis/efs/v1alpha1/zz_generated.deepcopy.go @@ -28,6 +28,11 @@ import ( // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *AccessPointDescription) DeepCopyInto(out *AccessPointDescription) { *out = *in + if in.AccessPointID != nil { + in, out := &in.AccessPointID, &out.AccessPointID + *out = new(string) + **out = **in + } if in.FileSystemID != nil { in, out := &in.FileSystemID, &out.FileSystemID *out = new(string) @@ -96,6 +101,66 @@ func (in *CustomFileSystemParameters) DeepCopy() *CustomFileSystemParameters { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CustomMountTargetParameters) DeepCopyInto(out *CustomMountTargetParameters) { + *out = *in + if in.SecurityGroups != nil { + in, out := &in.SecurityGroups, &out.SecurityGroups + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.SecurityGroupsRefs != nil { + in, out := &in.SecurityGroupsRefs, &out.SecurityGroupsRefs + *out = make([]v1.Reference, len(*in)) + copy(*out, *in) + } + if in.SecurityGroupsSelector != nil { + in, out := &in.SecurityGroupsSelector, &out.SecurityGroupsSelector + *out = new(v1.Selector) + (*in).DeepCopyInto(*out) + } + if in.FileSystemID != nil { + in, out := &in.FileSystemID, &out.FileSystemID + *out = new(string) + **out = **in + } + if in.FileSystemIDRef != nil { + in, out := &in.FileSystemIDRef, &out.FileSystemIDRef + *out = new(v1.Reference) + **out = **in + } + if in.FileSystemIDSelector != nil { + in, out := &in.FileSystemIDSelector, &out.FileSystemIDSelector + *out = new(v1.Selector) + (*in).DeepCopyInto(*out) + } + if in.SubnetID != nil { + in, out := &in.SubnetID, &out.SubnetID + *out = new(string) + **out = **in + } + if in.SubnetIDRef != nil { + in, out := &in.SubnetIDRef, &out.SubnetIDRef + *out = new(v1.Reference) + **out = **in + } + if in.SubnetIDSelector != nil { + in, out := &in.SubnetIDSelector, &out.SubnetIDSelector + *out = new(v1.Selector) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CustomMountTargetParameters. +func (in *CustomMountTargetParameters) DeepCopy() *CustomMountTargetParameters { + if in == nil { + return nil + } + out := new(CustomMountTargetParameters) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *FileSystem) DeepCopyInto(out *FileSystem) { *out = *in @@ -329,6 +394,180 @@ func (in *FileSystemStatus) DeepCopy() *FileSystemStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MountTarget) DeepCopyInto(out *MountTarget) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MountTarget. +func (in *MountTarget) DeepCopy() *MountTarget { + if in == nil { + return nil + } + out := new(MountTarget) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *MountTarget) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MountTargetList) DeepCopyInto(out *MountTargetList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]MountTarget, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MountTargetList. +func (in *MountTargetList) DeepCopy() *MountTargetList { + if in == nil { + return nil + } + out := new(MountTargetList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *MountTargetList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MountTargetObservation) DeepCopyInto(out *MountTargetObservation) { + *out = *in + if in.AvailabilityZoneID != nil { + in, out := &in.AvailabilityZoneID, &out.AvailabilityZoneID + *out = new(string) + **out = **in + } + if in.AvailabilityZoneName != nil { + in, out := &in.AvailabilityZoneName, &out.AvailabilityZoneName + *out = new(string) + **out = **in + } + if in.FileSystemID != nil { + in, out := &in.FileSystemID, &out.FileSystemID + *out = new(string) + **out = **in + } + if in.LifeCycleState != nil { + in, out := &in.LifeCycleState, &out.LifeCycleState + *out = new(string) + **out = **in + } + if in.MountTargetID != nil { + in, out := &in.MountTargetID, &out.MountTargetID + *out = new(string) + **out = **in + } + if in.NetworkInterfaceID != nil { + in, out := &in.NetworkInterfaceID, &out.NetworkInterfaceID + *out = new(string) + **out = **in + } + if in.OwnerID != nil { + in, out := &in.OwnerID, &out.OwnerID + *out = new(string) + **out = **in + } + if in.SubnetID != nil { + in, out := &in.SubnetID, &out.SubnetID + *out = new(string) + **out = **in + } + if in.VPCID != nil { + in, out := &in.VPCID, &out.VPCID + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MountTargetObservation. +func (in *MountTargetObservation) DeepCopy() *MountTargetObservation { + if in == nil { + return nil + } + out := new(MountTargetObservation) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MountTargetParameters) DeepCopyInto(out *MountTargetParameters) { + *out = *in + if in.IPAddress != nil { + in, out := &in.IPAddress, &out.IPAddress + *out = new(string) + **out = **in + } + in.CustomMountTargetParameters.DeepCopyInto(&out.CustomMountTargetParameters) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MountTargetParameters. +func (in *MountTargetParameters) DeepCopy() *MountTargetParameters { + if in == nil { + return nil + } + out := new(MountTargetParameters) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MountTargetSpec) DeepCopyInto(out *MountTargetSpec) { + *out = *in + in.ResourceSpec.DeepCopyInto(&out.ResourceSpec) + in.ForProvider.DeepCopyInto(&out.ForProvider) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MountTargetSpec. +func (in *MountTargetSpec) DeepCopy() *MountTargetSpec { + if in == nil { + return nil + } + out := new(MountTargetSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MountTargetStatus) DeepCopyInto(out *MountTargetStatus) { + *out = *in + in.ResourceStatus.DeepCopyInto(&out.ResourceStatus) + in.AtProvider.DeepCopyInto(&out.AtProvider) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MountTargetStatus. +func (in *MountTargetStatus) DeepCopy() *MountTargetStatus { + if in == nil { + return nil + } + out := new(MountTargetStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Tag) DeepCopyInto(out *Tag) { *out = *in diff --git a/apis/efs/v1alpha1/zz_generated.managed.go b/apis/efs/v1alpha1/zz_generated.managed.go index 08acae2db3..7bf3127c55 100644 --- a/apis/efs/v1alpha1/zz_generated.managed.go +++ b/apis/efs/v1alpha1/zz_generated.managed.go @@ -75,3 +75,59 @@ func (mg *FileSystem) SetProviderReference(r *xpv1.Reference) { func (mg *FileSystem) SetWriteConnectionSecretToReference(r *xpv1.SecretReference) { mg.Spec.WriteConnectionSecretToReference = r } + +// GetCondition of this MountTarget. +func (mg *MountTarget) GetCondition(ct xpv1.ConditionType) xpv1.Condition { + return mg.Status.GetCondition(ct) +} + +// GetDeletionPolicy of this MountTarget. +func (mg *MountTarget) GetDeletionPolicy() xpv1.DeletionPolicy { + return mg.Spec.DeletionPolicy +} + +// GetProviderConfigReference of this MountTarget. +func (mg *MountTarget) GetProviderConfigReference() *xpv1.Reference { + return mg.Spec.ProviderConfigReference +} + +/* +GetProviderReference of this MountTarget. +Deprecated: Use GetProviderConfigReference. +*/ +func (mg *MountTarget) GetProviderReference() *xpv1.Reference { + return mg.Spec.ProviderReference +} + +// GetWriteConnectionSecretToReference of this MountTarget. +func (mg *MountTarget) GetWriteConnectionSecretToReference() *xpv1.SecretReference { + return mg.Spec.WriteConnectionSecretToReference +} + +// SetConditions of this MountTarget. +func (mg *MountTarget) SetConditions(c ...xpv1.Condition) { + mg.Status.SetConditions(c...) +} + +// SetDeletionPolicy of this MountTarget. +func (mg *MountTarget) SetDeletionPolicy(r xpv1.DeletionPolicy) { + mg.Spec.DeletionPolicy = r +} + +// SetProviderConfigReference of this MountTarget. +func (mg *MountTarget) SetProviderConfigReference(r *xpv1.Reference) { + mg.Spec.ProviderConfigReference = r +} + +/* +SetProviderReference of this MountTarget. +Deprecated: Use SetProviderConfigReference. +*/ +func (mg *MountTarget) SetProviderReference(r *xpv1.Reference) { + mg.Spec.ProviderReference = r +} + +// SetWriteConnectionSecretToReference of this MountTarget. +func (mg *MountTarget) SetWriteConnectionSecretToReference(r *xpv1.SecretReference) { + mg.Spec.WriteConnectionSecretToReference = r +} diff --git a/apis/efs/v1alpha1/zz_generated.managedlist.go b/apis/efs/v1alpha1/zz_generated.managedlist.go index a4ae49af80..755f3d6c73 100644 --- a/apis/efs/v1alpha1/zz_generated.managedlist.go +++ b/apis/efs/v1alpha1/zz_generated.managedlist.go @@ -28,3 +28,12 @@ func (l *FileSystemList) GetItems() []resource.Managed { } return items } + +// GetItems of this MountTargetList. +func (l *MountTargetList) GetItems() []resource.Managed { + items := make([]resource.Managed, len(l.Items)) + for i := range l.Items { + items[i] = &l.Items[i] + } + return items +} diff --git a/apis/efs/v1alpha1/zz_mount_target.go b/apis/efs/v1alpha1/zz_mount_target.go new file mode 100644 index 0000000000..6653a71fce --- /dev/null +++ b/apis/efs/v1alpha1/zz_mount_target.go @@ -0,0 +1,111 @@ +/* +Copyright 2021 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by ack-generate. DO NOT EDIT. + +package v1alpha1 + +import ( + xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// MountTargetParameters defines the desired state of MountTarget +type MountTargetParameters struct { + // Region is which region the MountTarget will be created. + // +kubebuilder:validation:Required + Region string `json:"region"` + // Valid IPv4 address within the address range of the specified subnet. + IPAddress *string `json:"ipAddress,omitempty"` + CustomMountTargetParameters `json:",inline"` +} + +// MountTargetSpec defines the desired state of MountTarget +type MountTargetSpec struct { + xpv1.ResourceSpec `json:",inline"` + ForProvider MountTargetParameters `json:"forProvider"` +} + +// MountTargetObservation defines the observed state of MountTarget +type MountTargetObservation struct { + // The unique and consistent identifier of the Availability Zone (AZ) that the + // mount target resides in. For example, use1-az1 is an AZ ID for the us-east-1 + // Region and it has the same location in every AWS account. + AvailabilityZoneID *string `json:"availabilityZoneID,omitempty"` + // The name of the Availability Zone (AZ) that the mount target resides in. + // AZs are independently mapped to names for each AWS account. For example, + // the Availability Zone us-east-1a for your AWS account might not be the same + // location as us-east-1a for another AWS account. + AvailabilityZoneName *string `json:"availabilityZoneName,omitempty"` + // The ID of the file system for which the mount target is intended. + FileSystemID *string `json:"fileSystemID,omitempty"` + // Lifecycle state of the mount target. + LifeCycleState *string `json:"lifeCycleState,omitempty"` + // System-assigned mount target ID. + MountTargetID *string `json:"mountTargetID,omitempty"` + // The ID of the network interface that Amazon EFS created when it created the + // mount target. + NetworkInterfaceID *string `json:"networkInterfaceID,omitempty"` + // AWS account ID that owns the resource. + OwnerID *string `json:"ownerID,omitempty"` + // The ID of the mount target's subnet. + SubnetID *string `json:"subnetID,omitempty"` + // The Virtual Private Cloud (VPC) ID that the mount target is configured in. + VPCID *string `json:"vpcID,omitempty"` +} + +// MountTargetStatus defines the observed state of MountTarget. +type MountTargetStatus struct { + xpv1.ResourceStatus `json:",inline"` + AtProvider MountTargetObservation `json:"atProvider,omitempty"` +} + +// +kubebuilder:object:root=true + +// MountTarget is the Schema for the MountTargets API +// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status" +// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status" +// +kubebuilder:printcolumn:name="EXTERNAL-NAME",type="string",JSONPath=".metadata.annotations.crossplane\\.io/external-name" +// +kubebuilder:subresource:status +// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,aws} +type MountTarget struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + Spec MountTargetSpec `json:"spec"` + Status MountTargetStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +// MountTargetList contains a list of MountTargets +type MountTargetList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []MountTarget `json:"items"` +} + +// Repository type metadata. +var ( + MountTargetKind = "MountTarget" + MountTargetGroupKind = schema.GroupKind{Group: Group, Kind: MountTargetKind}.String() + MountTargetKindAPIVersion = MountTargetKind + "." + GroupVersion.String() + MountTargetGroupVersionKind = GroupVersion.WithKind(MountTargetKind) +) + +func init() { + SchemeBuilder.Register(&MountTarget{}, &MountTargetList{}) +} diff --git a/apis/efs/v1alpha1/zz_types.go b/apis/efs/v1alpha1/zz_types.go index 6a23c80216..ea099de26e 100644 --- a/apis/efs/v1alpha1/zz_types.go +++ b/apis/efs/v1alpha1/zz_types.go @@ -28,6 +28,8 @@ var ( ) type AccessPointDescription struct { + AccessPointID *string `json:"accessPointID,omitempty"` + FileSystemID *string `json:"fileSystemID,omitempty"` LifeCycleState *string `json:"lifeCycleState,omitempty"` diff --git a/examples/efs/filesystem.yaml b/examples/efs/filesystem.yaml index 975f60d4c1..b626bf2066 100644 --- a/examples/efs/filesystem.yaml +++ b/examples/efs/filesystem.yaml @@ -6,4 +6,4 @@ spec: forProvider: region: us-east-1 providerConfigRef: - name: default + name: example \ No newline at end of file diff --git a/examples/efs/mounttarget.yaml b/examples/efs/mounttarget.yaml new file mode 100644 index 0000000000..542271980e --- /dev/null +++ b/examples/efs/mounttarget.yaml @@ -0,0 +1,15 @@ +apiVersion: efs.aws.crossplane.io/v1alpha1 +kind: MountTarget +metadata: + name: example +spec: + forProvider: + region: us-east-1 + fileSystemIDRef: + name: example + subnetIDRef: + name: sample-subnet1 + securityGroupsRefs: + - name: sample-cluster-sg + providerConfigRef: + name: example diff --git a/package/crds/efs.aws.crossplane.io_mounttargets.yaml b/package/crds/efs.aws.crossplane.io_mounttargets.yaml new file mode 100644 index 0000000000..5f27f5d150 --- /dev/null +++ b/package/crds/efs.aws.crossplane.io_mounttargets.yaml @@ -0,0 +1,299 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.4.0 + creationTimestamp: null + name: mounttargets.efs.aws.crossplane.io +spec: + group: efs.aws.crossplane.io + names: + categories: + - crossplane + - managed + - aws + kind: MountTarget + listKind: MountTargetList + plural: mounttargets + singular: mounttarget + scope: Cluster + versions: + - additionalPrinterColumns: + - jsonPath: .status.conditions[?(@.type=='Ready')].status + name: READY + type: string + - jsonPath: .status.conditions[?(@.type=='Synced')].status + name: SYNCED + type: string + - jsonPath: .metadata.annotations.crossplane\.io/external-name + name: EXTERNAL-NAME + type: string + name: v1alpha1 + schema: + openAPIV3Schema: + description: MountTarget is the Schema for the MountTargets API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: MountTargetSpec defines the desired state of MountTarget + properties: + deletionPolicy: + default: Delete + description: DeletionPolicy specifies what will happen to the underlying + external when this managed resource is deleted - either "Delete" + or "Orphan" the external resource. + enum: + - Orphan + - Delete + type: string + forProvider: + description: MountTargetParameters defines the desired state of MountTarget + properties: + fileSystemID: + description: The ID of the file system for which to create the + mount target. + type: string + fileSystemIDRef: + description: FileSystemIDRef are references to Filesystem used + to set the FileSystemID. + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + fileSystemIDSelector: + description: FileSystemIDSelector selects references to Filesystem + used to set the FileSystemID. + properties: + matchControllerRef: + description: MatchControllerRef ensures an object with the + same controller reference as the selecting object is selected. + type: boolean + matchLabels: + additionalProperties: + type: string + description: MatchLabels ensures an object with matching labels + is selected. + type: object + type: object + ipAddress: + description: Valid IPv4 address within the address range of the + specified subnet. + type: string + region: + description: Region is which region the MountTarget will be created. + type: string + securityGroups: + description: Up to five VPC security group IDs, of the form sg-xxxxxxxx. + These must be for the same VPC as subnet specified. + items: + type: string + type: array + securityGroupsRefs: + description: SecurityGroupIDRefs are references to SecurityGroups + used to set the SecurityGroupIDs. + items: + description: A Reference to a named object. + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + type: array + securityGroupsSelector: + description: SecurityGroupIDSelector selects references to SecurityGroups + used to set the SecurityGroupIDs. + properties: + matchControllerRef: + description: MatchControllerRef ensures an object with the + same controller reference as the selecting object is selected. + type: boolean + matchLabels: + additionalProperties: + type: string + description: MatchLabels ensures an object with matching labels + is selected. + type: object + type: object + subnetID: + description: The ID of the subnet to add the mount target in. + type: string + subnetIDRef: + description: SubnetIDRef are references to Subnet used to set + the SubnetID. + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + subnetIDSelector: + description: SubnetIDSelector selects references to Subnet used + to set the SubnetID. + properties: + matchControllerRef: + description: MatchControllerRef ensures an object with the + same controller reference as the selecting object is selected. + type: boolean + matchLabels: + additionalProperties: + type: string + description: MatchLabels ensures an object with matching labels + is selected. + type: object + type: object + required: + - region + type: object + providerConfigRef: + default: + name: default + description: ProviderConfigReference specifies how the provider that + will be used to create, observe, update, and delete this managed + resource should be configured. + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + providerRef: + description: 'ProviderReference specifies the provider that will be + used to create, observe, update, and delete this managed resource. + Deprecated: Please use ProviderConfigReference, i.e. `providerConfigRef`' + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + writeConnectionSecretToRef: + description: WriteConnectionSecretToReference specifies the namespace + and name of a Secret to which any connection details for this managed + resource should be written. Connection details frequently include + the endpoint, username, and password required to connect to the + managed resource. + properties: + name: + description: Name of the secret. + type: string + namespace: + description: Namespace of the secret. + type: string + required: + - name + - namespace + type: object + required: + - forProvider + type: object + status: + description: MountTargetStatus defines the observed state of MountTarget. + properties: + atProvider: + description: MountTargetObservation defines the observed state of + MountTarget + properties: + availabilityZoneID: + description: The unique and consistent identifier of the Availability + Zone (AZ) that the mount target resides in. For example, use1-az1 + is an AZ ID for the us-east-1 Region and it has the same location + in every AWS account. + type: string + availabilityZoneName: + description: The name of the Availability Zone (AZ) that the mount + target resides in. AZs are independently mapped to names for + each AWS account. For example, the Availability Zone us-east-1a + for your AWS account might not be the same location as us-east-1a + for another AWS account. + type: string + fileSystemID: + description: The ID of the file system for which the mount target + is intended. + type: string + lifeCycleState: + description: Lifecycle state of the mount target. + type: string + mountTargetID: + description: System-assigned mount target ID. + type: string + networkInterfaceID: + description: The ID of the network interface that Amazon EFS created + when it created the mount target. + type: string + ownerID: + description: AWS account ID that owns the resource. + type: string + subnetID: + description: The ID of the mount target's subnet. + type: string + vpcID: + description: The Virtual Private Cloud (VPC) ID that the mount + target is configured in. + type: string + type: object + conditions: + description: Conditions of the resource. + items: + description: A Condition that may apply to a resource. + properties: + lastTransitionTime: + description: LastTransitionTime is the last time this condition + transitioned from one status to another. + format: date-time + type: string + message: + description: A Message containing details about this condition's + last transition from one status to another, if any. + type: string + reason: + description: A Reason for this condition's last transition from + one status to another. + type: string + status: + description: Status of this condition; is it currently True, + False, or Unknown? + type: string + type: + description: Type of this condition. At most one of each condition + type may apply to a resource at any point in time. + type: string + required: + - lastTransitionTime + - reason + - status + - type + type: object + type: array + type: object + required: + - spec + type: object + served: true + storage: true + subresources: + status: {} +status: + acceptedNames: + kind: "" + plural: "" + conditions: [] + storedVersions: [] diff --git a/pkg/controller/aws.go b/pkg/controller/aws.go index 54c4821fc9..c7cdb7c318 100644 --- a/pkg/controller/aws.go +++ b/pkg/controller/aws.go @@ -65,6 +65,7 @@ import ( "github.com/crossplane/provider-aws/pkg/controller/ecr/repository" "github.com/crossplane/provider-aws/pkg/controller/ecr/repositorypolicy" "github.com/crossplane/provider-aws/pkg/controller/efs/filesystem" + efsmounttarget "github.com/crossplane/provider-aws/pkg/controller/efs/mounttarget" "github.com/crossplane/provider-aws/pkg/controller/eks" "github.com/crossplane/provider-aws/pkg/controller/eks/fargateprofile" "github.com/crossplane/provider-aws/pkg/controller/eks/nodegroup" @@ -187,6 +188,7 @@ func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, poll ti resolverrule.SetupResolverRule, vpcpeeringconnection.SetupVPCPeeringConnection, kafkacluster.SetupCluster, + efsmounttarget.SetupMountTarget, } { if err := setup(mgr, l, rl, poll); err != nil { return err diff --git a/pkg/controller/efs/mounttarget/setup.go b/pkg/controller/efs/mounttarget/setup.go new file mode 100644 index 0000000000..2f027a6cc3 --- /dev/null +++ b/pkg/controller/efs/mounttarget/setup.go @@ -0,0 +1,81 @@ +package mounttarget + +import ( + "context" + "time" + + svcsdk "github.com/aws/aws-sdk-go/service/efs" + "k8s.io/client-go/util/workqueue" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/controller" + + xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" + "github.com/crossplane/crossplane-runtime/pkg/event" + "github.com/crossplane/crossplane-runtime/pkg/logging" + "github.com/crossplane/crossplane-runtime/pkg/meta" + "github.com/crossplane/crossplane-runtime/pkg/ratelimiter" + "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" + cpresource "github.com/crossplane/crossplane-runtime/pkg/resource" + + svcapitypes "github.com/crossplane/provider-aws/apis/efs/v1alpha1" + awsclients "github.com/crossplane/provider-aws/pkg/clients" +) + +// SetupMountTarget adds a controller that reconciles MountTarget. +func SetupMountTarget(mgr ctrl.Manager, l logging.Logger, limiter workqueue.RateLimiter, poll time.Duration) error { + name := managed.ControllerName(svcapitypes.MountTargetGroupKind) + opts := []option{ + func(e *external) { + e.postCreate = postCreate + e.preObserve = preObserve + e.postObserve = postObserve + e.preCreate = preCreate + }, + } + return ctrl.NewControllerManagedBy(mgr). + Named(name). + WithOptions(controller.Options{ + RateLimiter: ratelimiter.NewDefaultManagedRateLimiter(limiter), + }). + For(&svcapitypes.MountTarget{}). + Complete(managed.NewReconciler(mgr, + cpresource.ManagedKind(svcapitypes.MountTargetGroupVersionKind), + managed.WithInitializers(managed.NewDefaultProviderConfig(mgr.GetClient())), + managed.WithExternalConnecter(&connector{kube: mgr.GetClient(), opts: opts}), + managed.WithLogger(l.WithValues("controller", name)), + managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))))) +} + +func preCreate(_ context.Context, cr *svcapitypes.MountTarget, obj *svcsdk.CreateMountTargetInput) error { + obj.FileSystemId = cr.Spec.ForProvider.FileSystemID + obj.SubnetId = cr.Spec.ForProvider.SubnetID + return nil +} + +func postCreate(_ context.Context, cr *svcapitypes.MountTarget, obj *svcsdk.MountTargetDescription, _ managed.ExternalCreation, err error) (managed.ExternalCreation, error) { + if err != nil { + return managed.ExternalCreation{}, err + } + meta.SetExternalName(cr, awsclients.StringValue(obj.MountTargetId)) + return managed.ExternalCreation{ExternalNameAssigned: true}, nil +} + +func preObserve(_ context.Context, cr *svcapitypes.MountTarget, obj *svcsdk.DescribeMountTargetsInput) error { + // Must specify exactly one mutually exclusive parameter. + obj.AccessPointId = nil + obj.Marker = nil + obj.MaxItems = nil + obj.FileSystemId = nil + obj.MountTargetId = awsclients.String(meta.GetExternalName(cr)) + return nil +} + +func postObserve(_ context.Context, cr *svcapitypes.MountTarget, obj *svcsdk.DescribeMountTargetsOutput, obs managed.ExternalObservation, err error) (managed.ExternalObservation, error) { + if err != nil { + return managed.ExternalObservation{}, err + } + if awsclients.StringValue(obj.MountTargets[0].LifeCycleState) == string(svcapitypes.LifeCycleState_available) { + cr.SetConditions(xpv1.Available()) + } + return obs, nil +} diff --git a/pkg/controller/efs/mounttarget/zz_controller.go b/pkg/controller/efs/mounttarget/zz_controller.go new file mode 100644 index 0000000000..6241b92abd --- /dev/null +++ b/pkg/controller/efs/mounttarget/zz_controller.go @@ -0,0 +1,262 @@ +/* +Copyright 2021 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by ack-generate. DO NOT EDIT. + +package mounttarget + +import ( + "context" + + svcapi "github.com/aws/aws-sdk-go/service/efs" + svcsdk "github.com/aws/aws-sdk-go/service/efs" + svcsdkapi "github.com/aws/aws-sdk-go/service/efs/efsiface" + "github.com/google/go-cmp/cmp" + "github.com/pkg/errors" + "sigs.k8s.io/controller-runtime/pkg/client" + + xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" + "github.com/crossplane/crossplane-runtime/pkg/meta" + "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" + cpresource "github.com/crossplane/crossplane-runtime/pkg/resource" + + svcapitypes "github.com/crossplane/provider-aws/apis/efs/v1alpha1" + awsclient "github.com/crossplane/provider-aws/pkg/clients" +) + +const ( + errUnexpectedObject = "managed resource is not an MountTarget resource" + + errCreateSession = "cannot create a new session" + errCreate = "cannot create MountTarget in AWS" + errUpdate = "cannot update MountTarget in AWS" + errDescribe = "failed to describe MountTarget" + errDelete = "failed to delete MountTarget" +) + +type connector struct { + kube client.Client + opts []option +} + +func (c *connector) Connect(ctx context.Context, mg cpresource.Managed) (managed.ExternalClient, error) { + cr, ok := mg.(*svcapitypes.MountTarget) + if !ok { + return nil, errors.New(errUnexpectedObject) + } + sess, err := awsclient.GetConfigV1(ctx, c.kube, mg, cr.Spec.ForProvider.Region) + if err != nil { + return nil, errors.Wrap(err, errCreateSession) + } + return newExternal(c.kube, svcapi.New(sess), c.opts), nil +} + +func (e *external) Observe(ctx context.Context, mg cpresource.Managed) (managed.ExternalObservation, error) { + cr, ok := mg.(*svcapitypes.MountTarget) + if !ok { + return managed.ExternalObservation{}, errors.New(errUnexpectedObject) + } + if meta.GetExternalName(cr) == "" { + return managed.ExternalObservation{ + ResourceExists: false, + }, nil + } + input := GenerateDescribeMountTargetsInput(cr) + if err := e.preObserve(ctx, cr, input); err != nil { + return managed.ExternalObservation{}, errors.Wrap(err, "pre-observe failed") + } + resp, err := e.client.DescribeMountTargetsWithContext(ctx, input) + if err != nil { + return managed.ExternalObservation{ResourceExists: false}, awsclient.Wrap(cpresource.Ignore(IsNotFound, err), errDescribe) + } + resp = e.filterList(cr, resp) + if len(resp.MountTargets) == 0 { + return managed.ExternalObservation{ResourceExists: false}, nil + } + currentSpec := cr.Spec.ForProvider.DeepCopy() + if err := e.lateInitialize(&cr.Spec.ForProvider, resp); err != nil { + return managed.ExternalObservation{}, errors.Wrap(err, "late-init failed") + } + GenerateMountTarget(resp).Status.AtProvider.DeepCopyInto(&cr.Status.AtProvider) + + upToDate, err := e.isUpToDate(cr, resp) + if err != nil { + return managed.ExternalObservation{}, errors.Wrap(err, "isUpToDate check failed") + } + return e.postObserve(ctx, cr, resp, managed.ExternalObservation{ + ResourceExists: true, + ResourceUpToDate: upToDate, + ResourceLateInitialized: !cmp.Equal(&cr.Spec.ForProvider, currentSpec), + }, nil) +} + +func (e *external) Create(ctx context.Context, mg cpresource.Managed) (managed.ExternalCreation, error) { + cr, ok := mg.(*svcapitypes.MountTarget) + if !ok { + return managed.ExternalCreation{}, errors.New(errUnexpectedObject) + } + cr.Status.SetConditions(xpv1.Creating()) + input := GenerateCreateMountTargetInput(cr) + if err := e.preCreate(ctx, cr, input); err != nil { + return managed.ExternalCreation{}, errors.Wrap(err, "pre-create failed") + } + resp, err := e.client.CreateMountTargetWithContext(ctx, input) + if err != nil { + return managed.ExternalCreation{}, awsclient.Wrap(err, errCreate) + } + + if resp.AvailabilityZoneId != nil { + cr.Status.AtProvider.AvailabilityZoneID = resp.AvailabilityZoneId + } else { + cr.Status.AtProvider.AvailabilityZoneID = nil + } + if resp.AvailabilityZoneName != nil { + cr.Status.AtProvider.AvailabilityZoneName = resp.AvailabilityZoneName + } else { + cr.Status.AtProvider.AvailabilityZoneName = nil + } + if resp.FileSystemId != nil { + cr.Status.AtProvider.FileSystemID = resp.FileSystemId + } else { + cr.Status.AtProvider.FileSystemID = nil + } + if resp.LifeCycleState != nil { + cr.Status.AtProvider.LifeCycleState = resp.LifeCycleState + } else { + cr.Status.AtProvider.LifeCycleState = nil + } + if resp.MountTargetId != nil { + cr.Status.AtProvider.MountTargetID = resp.MountTargetId + } else { + cr.Status.AtProvider.MountTargetID = nil + } + if resp.NetworkInterfaceId != nil { + cr.Status.AtProvider.NetworkInterfaceID = resp.NetworkInterfaceId + } else { + cr.Status.AtProvider.NetworkInterfaceID = nil + } + if resp.OwnerId != nil { + cr.Status.AtProvider.OwnerID = resp.OwnerId + } else { + cr.Status.AtProvider.OwnerID = nil + } + if resp.SubnetId != nil { + cr.Status.AtProvider.SubnetID = resp.SubnetId + } else { + cr.Status.AtProvider.SubnetID = nil + } + if resp.VpcId != nil { + cr.Status.AtProvider.VPCID = resp.VpcId + } else { + cr.Status.AtProvider.VPCID = nil + } + + return e.postCreate(ctx, cr, resp, managed.ExternalCreation{}, err) +} + +func (e *external) Update(ctx context.Context, mg cpresource.Managed) (managed.ExternalUpdate, error) { + return e.update(ctx, mg) + +} + +func (e *external) Delete(ctx context.Context, mg cpresource.Managed) error { + cr, ok := mg.(*svcapitypes.MountTarget) + if !ok { + return errors.New(errUnexpectedObject) + } + cr.Status.SetConditions(xpv1.Deleting()) + input := GenerateDeleteMountTargetInput(cr) + ignore, err := e.preDelete(ctx, cr, input) + if err != nil { + return errors.Wrap(err, "pre-delete failed") + } + if ignore { + return nil + } + resp, err := e.client.DeleteMountTargetWithContext(ctx, input) + return e.postDelete(ctx, cr, resp, awsclient.Wrap(cpresource.Ignore(IsNotFound, err), errDelete)) +} + +type option func(*external) + +func newExternal(kube client.Client, client svcsdkapi.EFSAPI, opts []option) *external { + e := &external{ + kube: kube, + client: client, + preObserve: nopPreObserve, + postObserve: nopPostObserve, + lateInitialize: nopLateInitialize, + isUpToDate: alwaysUpToDate, + filterList: nopFilterList, + preCreate: nopPreCreate, + postCreate: nopPostCreate, + preDelete: nopPreDelete, + postDelete: nopPostDelete, + update: nopUpdate, + } + for _, f := range opts { + f(e) + } + return e +} + +type external struct { + kube client.Client + client svcsdkapi.EFSAPI + preObserve func(context.Context, *svcapitypes.MountTarget, *svcsdk.DescribeMountTargetsInput) error + postObserve func(context.Context, *svcapitypes.MountTarget, *svcsdk.DescribeMountTargetsOutput, managed.ExternalObservation, error) (managed.ExternalObservation, error) + filterList func(*svcapitypes.MountTarget, *svcsdk.DescribeMountTargetsOutput) *svcsdk.DescribeMountTargetsOutput + lateInitialize func(*svcapitypes.MountTargetParameters, *svcsdk.DescribeMountTargetsOutput) error + isUpToDate func(*svcapitypes.MountTarget, *svcsdk.DescribeMountTargetsOutput) (bool, error) + preCreate func(context.Context, *svcapitypes.MountTarget, *svcsdk.CreateMountTargetInput) error + postCreate func(context.Context, *svcapitypes.MountTarget, *svcsdk.MountTargetDescription, managed.ExternalCreation, error) (managed.ExternalCreation, error) + preDelete func(context.Context, *svcapitypes.MountTarget, *svcsdk.DeleteMountTargetInput) (bool, error) + postDelete func(context.Context, *svcapitypes.MountTarget, *svcsdk.DeleteMountTargetOutput, error) error + update func(context.Context, cpresource.Managed) (managed.ExternalUpdate, error) +} + +func nopPreObserve(context.Context, *svcapitypes.MountTarget, *svcsdk.DescribeMountTargetsInput) error { + return nil +} +func nopPostObserve(_ context.Context, _ *svcapitypes.MountTarget, _ *svcsdk.DescribeMountTargetsOutput, obs managed.ExternalObservation, err error) (managed.ExternalObservation, error) { + return obs, err +} +func nopFilterList(_ *svcapitypes.MountTarget, list *svcsdk.DescribeMountTargetsOutput) *svcsdk.DescribeMountTargetsOutput { + return list +} + +func nopLateInitialize(*svcapitypes.MountTargetParameters, *svcsdk.DescribeMountTargetsOutput) error { + return nil +} +func alwaysUpToDate(*svcapitypes.MountTarget, *svcsdk.DescribeMountTargetsOutput) (bool, error) { + return true, nil +} + +func nopPreCreate(context.Context, *svcapitypes.MountTarget, *svcsdk.CreateMountTargetInput) error { + return nil +} +func nopPostCreate(_ context.Context, _ *svcapitypes.MountTarget, _ *svcsdk.MountTargetDescription, cre managed.ExternalCreation, err error) (managed.ExternalCreation, error) { + return cre, err +} +func nopPreDelete(context.Context, *svcapitypes.MountTarget, *svcsdk.DeleteMountTargetInput) (bool, error) { + return false, nil +} +func nopPostDelete(_ context.Context, _ *svcapitypes.MountTarget, _ *svcsdk.DeleteMountTargetOutput, err error) error { + return err +} +func nopUpdate(context.Context, cpresource.Managed) (managed.ExternalUpdate, error) { + return managed.ExternalUpdate{}, nil +} diff --git a/pkg/controller/efs/mounttarget/zz_conversions.go b/pkg/controller/efs/mounttarget/zz_conversions.go new file mode 100644 index 0000000000..d680c10b64 --- /dev/null +++ b/pkg/controller/efs/mounttarget/zz_conversions.go @@ -0,0 +1,138 @@ +/* +Copyright 2021 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by ack-generate. DO NOT EDIT. + +package mounttarget + +import ( + "github.com/aws/aws-sdk-go/aws/awserr" + svcsdk "github.com/aws/aws-sdk-go/service/efs" + + svcapitypes "github.com/crossplane/provider-aws/apis/efs/v1alpha1" +) + +// NOTE(muvaf): We return pointers in case the function needs to start with an +// empty object, hence need to return a new pointer. + +// GenerateDescribeMountTargetsInput returns input for read +// operation. +func GenerateDescribeMountTargetsInput(cr *svcapitypes.MountTarget) *svcsdk.DescribeMountTargetsInput { + res := &svcsdk.DescribeMountTargetsInput{} + + if cr.Status.AtProvider.FileSystemID != nil { + res.SetFileSystemId(*cr.Status.AtProvider.FileSystemID) + } + if cr.Status.AtProvider.MountTargetID != nil { + res.SetMountTargetId(*cr.Status.AtProvider.MountTargetID) + } + + return res +} + +// GenerateMountTarget returns the current state in the form of *svcapitypes.MountTarget. +func GenerateMountTarget(resp *svcsdk.DescribeMountTargetsOutput) *svcapitypes.MountTarget { + cr := &svcapitypes.MountTarget{} + + found := false + for _, elem := range resp.MountTargets { + if elem.AvailabilityZoneId != nil { + cr.Status.AtProvider.AvailabilityZoneID = elem.AvailabilityZoneId + } else { + cr.Status.AtProvider.AvailabilityZoneID = nil + } + if elem.AvailabilityZoneName != nil { + cr.Status.AtProvider.AvailabilityZoneName = elem.AvailabilityZoneName + } else { + cr.Status.AtProvider.AvailabilityZoneName = nil + } + if elem.FileSystemId != nil { + cr.Status.AtProvider.FileSystemID = elem.FileSystemId + } else { + cr.Status.AtProvider.FileSystemID = nil + } + if elem.IpAddress != nil { + cr.Spec.ForProvider.IPAddress = elem.IpAddress + } else { + cr.Spec.ForProvider.IPAddress = nil + } + if elem.LifeCycleState != nil { + cr.Status.AtProvider.LifeCycleState = elem.LifeCycleState + } else { + cr.Status.AtProvider.LifeCycleState = nil + } + if elem.MountTargetId != nil { + cr.Status.AtProvider.MountTargetID = elem.MountTargetId + } else { + cr.Status.AtProvider.MountTargetID = nil + } + if elem.NetworkInterfaceId != nil { + cr.Status.AtProvider.NetworkInterfaceID = elem.NetworkInterfaceId + } else { + cr.Status.AtProvider.NetworkInterfaceID = nil + } + if elem.OwnerId != nil { + cr.Status.AtProvider.OwnerID = elem.OwnerId + } else { + cr.Status.AtProvider.OwnerID = nil + } + if elem.SubnetId != nil { + cr.Status.AtProvider.SubnetID = elem.SubnetId + } else { + cr.Status.AtProvider.SubnetID = nil + } + if elem.VpcId != nil { + cr.Status.AtProvider.VPCID = elem.VpcId + } else { + cr.Status.AtProvider.VPCID = nil + } + found = true + break + } + if !found { + return cr + } + + return cr +} + +// GenerateCreateMountTargetInput returns a create input. +func GenerateCreateMountTargetInput(cr *svcapitypes.MountTarget) *svcsdk.CreateMountTargetInput { + res := &svcsdk.CreateMountTargetInput{} + + if cr.Spec.ForProvider.IPAddress != nil { + res.SetIpAddress(*cr.Spec.ForProvider.IPAddress) + } + + return res +} + +// GenerateDeleteMountTargetInput returns a deletion input. +func GenerateDeleteMountTargetInput(cr *svcapitypes.MountTarget) *svcsdk.DeleteMountTargetInput { + res := &svcsdk.DeleteMountTargetInput{} + + if cr.Status.AtProvider.MountTargetID != nil { + res.SetMountTargetId(*cr.Status.AtProvider.MountTargetID) + } + + return res +} + +// IsNotFound returns whether the given error is of type NotFound or not. +func IsNotFound(err error) bool { + awsErr, ok := err.(awserr.Error) + return ok && awsErr.Code() == "MountTargetNotFound" +}