Skip to content

Commit

Permalink
feat(globalaccelerator): Add support for accelerator, listener and en…
Browse files Browse the repository at this point in the history
…dpointgroups

Signed-off-by: cite <[email protected]>
  • Loading branch information
cite committed Aug 26, 2023
1 parent bdf4b5f commit eae6cc0
Show file tree
Hide file tree
Showing 30 changed files with 6,202 additions and 1 deletion.
30 changes: 29 additions & 1 deletion CODE_GENERATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ external name of the referenced object, you can use the following comment marker
You can add the package prefix for `type` and `extractor` configurations if they
live in a different Go package.

Be aware that once you customize the extractor, you will need to implement it yourself.
An example can be found [here](https://github.com/crossplane-contrib/provider-aws/blob/72a6950/apis/lambda/v1beta1/referencers.go#L35).

### External Name

Crossplane has the notion of external name that we put under annotations. It corresponds
Expand Down Expand Up @@ -274,9 +277,33 @@ func preDelete(_ context.Context, cr *svcapitypes.Stage, obj *svcsdk.DeleteStage
If the external-name is decided by AWS after the creation (like in most EC2
resources such as `vpc-id` of `VPC`), then you need to inject `postCreate` to
set the crossplane resource external-name to the unique identifier of the
resource, for eg see [`apigatewayv2`](https://github.com/crossplane/provider-aws/blob/master/pkg/controller/apigatewayv2/api/setup.go#L77)
resource, for eg see [`apigatewayv2`](https://github.com/crossplane/provider-aws/blob/72a6950/pkg/controller/apigatewayv2/api/setup.go#L85)
You can discover what you can inject by inspecting `zz_controller.go` file.

### Errors On Observe

In some situations aws api returns an error in cases where the resource does not exist.
It will be noticeable when the resource never gets created but you see an error from the api
which describes the object. You should see `return ok && awsErr.Code() == "ResourceNotFoundException"` in
the `IsNotFound`-function of `zz_conversion.go`.

To tell ack which error indicates that the resource is not present, add a similar config to `generator-config.yaml`:

```
resources:
Table:
fields:
PointInTimeRecoveryEnabled:
from:
operation: UpdateContinuousBackups
path: PointInTimeRecoverySpecification.PointInTimeRecoveryEnabled
exceptions:
errors:
404:
code: ResourceNotFoundException
```


### Readiness Check

Every managed resource needs to report its readiness. We'll do that in `postObserve`
Expand Down Expand Up @@ -541,3 +568,4 @@ If `IsUpToDate` check is giving false negatives, controller will make update cal
repeatedly and this causes problems. You can usually notice this easily but it's good
to check either via a breakpoint in your IDE or a print statement to see if `Update`
is run even when there is no change on the custom resource.
2 changes: 2 additions & 0 deletions apis/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import (
elbv2manualv1alpha1 "github.com/crossplane-contrib/provider-aws/apis/elbv2/manualv1alpha1"
elbv2v1alpha1 "github.com/crossplane-contrib/provider-aws/apis/elbv2/v1alpha1"
emrcontainersv1alpah1 "github.com/crossplane-contrib/provider-aws/apis/emrcontainers/v1alpha1"
globalacceleratorv1alpha1 "github.com/crossplane-contrib/provider-aws/apis/globalaccelerator/v1alpha1"
gluev1alpha1 "github.com/crossplane-contrib/provider-aws/apis/glue/v1alpha1"
iamv1alpha1 "github.com/crossplane-contrib/provider-aws/apis/iam/v1alpha1"
iamv1beta1 "github.com/crossplane-contrib/provider-aws/apis/iam/v1beta1"
Expand Down Expand Up @@ -148,6 +149,7 @@ func init() {
kafkav1alpha1.SchemeBuilder.AddToScheme,
transferv1alpha1.SchemeBuilder.AddToScheme,
gluev1alpha1.SchemeBuilder.AddToScheme,
globalacceleratorv1alpha1.SchemeBuilder.AddToScheme,
mqv1alpha1.SchemeBuilder.AddToScheme,
mwaav1alpha1.SchemeBuilder.AddToScheme,
cloudwatchlogsv1alpha1.SchemeBuilder.AddToScheme,
Expand Down
28 changes: 28 additions & 0 deletions apis/globalaccelerator/generator-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
ignore:
field_paths:
- "CreateAcceleratorInput.IdempotencyToken"
- "CreateListenerInput.AcceleratorArn"
- "CreateListenerInput.IdempotencyToken"
- "CreateEndpointGroupInput.ListenerArn"
- "CreateEndpointGroupInput.IdempotencyToken"
resource_names:
- "CustomRoutingAccelerator"
- "CustomRoutingEndpointGroup"
- "CustomRoutingListener"

resources:
Accelerator:
exceptions:
errors:
404:
code: AcceleratorNotFoundException
Listener:
exceptions:
errors:
404:
code: ListenerNotFoundException
EndpointGroup:
exceptions:
errors:
404:
code: EndpointGroupNotFoundException
64 changes: 64 additions & 0 deletions apis/globalaccelerator/v1alpha1/custom_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
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.
*/

package v1alpha1

import xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"

// CustomAcceleratorParameters contains the additional fields for AcceleratorParameters
type CustomAcceleratorParameters struct{}

// CustomEndpointGroupParameters contains the additional fields for EndpointGroupParameters
type CustomEndpointGroupParameters struct {
// ListenerArn is the ARN for the Listener.
// +immutable
// +crossplane:generate:reference:type=Listener
// +crossplane:generate:reference:extractor=ListenerARN()
// +crossplane:generate:reference:refFieldName=ListenerArnRef
// +crossplane:generate:reference:selectorFieldName=ListenerArnSelector
ListenerARN *string `json:"listenerArn,omitempty"`

// ListenerArnRef is a reference to an ARN used to set
// the ListenerArn.
// +optional
ListenerArnRef *xpv1.Reference `json:"listenerArnRef,omitempty"`

// ListenerArnSelector selects references to Listener used
// to set the Arn.
// +optional
ListenerArnSelector *xpv1.Selector `json:"listenerArnSelector,omitempty"`
}

// CustomListenerParameters contains the additional fields for ListenerParameters
type CustomListenerParameters struct {
// AcceleratorArn is the ARN for the Accelerator.
// +immutable
// +crossplane:generate:reference:type=Accelerator
// +crossplane:generate:reference:extractor=AcceleratorARN()
// +crossplane:generate:reference:refFieldName=AcceleratorArnRef
// +crossplane:generate:reference:selectorFieldName=AcceleratorArnSelector
AcceleratorArn *string `json:"acceleratorArn,omitempty"`

// AcceleratorArnRef is a reference to an ARN used to set
// the AcceleratorArn.
// +optional
AcceleratorArnRef *xpv1.Reference `json:"acceleratorArnRef,omitempty"`

// AcceleratorArnSelector selects references to Accelerator used
// to set the Arn.
// +optional
AcceleratorArnSelector *xpv1.Selector `json:"acceleratorArnSelector,omitempty"`
}
31 changes: 31 additions & 0 deletions apis/globalaccelerator/v1alpha1/referencers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package v1alpha1

import (
"github.com/crossplane/crossplane-runtime/pkg/reference"
"github.com/crossplane/crossplane-runtime/pkg/resource"
"k8s.io/utils/pointer"
)

// AcceleratorARN returns the status.atProvider.ARN of an Accelerator
func AcceleratorARN() reference.ExtractValueFn {
return func(mg resource.Managed) string {
r, ok := mg.(*Accelerator)
if !ok {
return ""
}

return pointer.StringDeref(r.Status.AtProvider.AcceleratorARN, "")
}
}

// ListenerARN returns the status.atProvider.ARN of an Listener
func ListenerARN() reference.ExtractValueFn {
return func(mg resource.Managed) string {
r, ok := mg.(*Listener)
if !ok {
return ""
}

return pointer.StringDeref(r.Status.AtProvider.ListenerARN, "")
}
}
169 changes: 169 additions & 0 deletions apis/globalaccelerator/v1alpha1/zz_accelerator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions apis/globalaccelerator/v1alpha1/zz_doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit eae6cc0

Please sign in to comment.