Skip to content

Commit

Permalink
Merge pull request crossplane-contrib#1820 from atarax/atarax/globala…
Browse files Browse the repository at this point in the history
…ccelerator
  • Loading branch information
MisterMX authored Sep 1, 2023
2 parents 0334e7b + 5d59c21 commit d5f6675
Show file tree
Hide file tree
Showing 32 changed files with 6,269 additions and 4 deletions.
64 changes: 61 additions & 3 deletions CODE_GENERATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,39 @@ files that help CRD structs satisfy the Go interfaces we use in crossplane-runti
There are a few things we need to implement manually since there is no support for
their generation yet.

### Setup Api Group

If a new group of api's has been introduced, we will need write a `Setup` function to satisfy
the interface which we will need to register the contollers. For example, if you added `globalaccelerator`
api group, we will need a file in `pkg/controller/globalaccelerator/setup.go with following contents:

```golang
package globalaccelerator
import (
ctrl "sigs.k8s.io/controller-runtime"
"github.com/crossplane/crossplane-runtime/pkg/controller"
"github.com/crossplane-contrib/provider-aws/pkg/controller/globalaccelerator/accelerator"
"github.com/crossplane-contrib/provider-aws/pkg/controller/globalaccelerator/listener"
"github.com/crossplane-contrib/provider-aws/pkg/controller/globalaccelerator/endpointgroup"
"github.com/crossplane-contrib/provider-aws/pkg/utils/setup"
)
// Setup athena controllers.
func Setup(mgr ctrl.Manager, o controller.Options) error {
return setup.SetupControllers(
mgr, o,
accelerator.SetupAccelerator,
listener.SetupListener,
endpointgroup.SetupEndpointGroup,
)
}
```

Now you need to make sure this function is called in setup phase [here](https://github.com/crossplane-contrib/provider-aws/blob/2e52b0a8b9ca9efa132e82549b9a48c13345dd27/pkg/controller/aws.go#L81).

### Setup Controller

The generated controller needs to be registered with the main controller manager
Expand Down Expand Up @@ -130,8 +163,6 @@ func SetupStage(mgr ctrl.Manager, o controller.Options) error {
}
```

Now you need to make sure this function is called in setup phase [here](https://github.com/crossplane/provider-aws/blob/483058c/pkg/controller/aws.go#L84).

#### Register CRD

If the group didn't exist before, we need to register its schema [here](https://github.com/crossplane/provider-aws/blob/master/apis/aws.go).
Expand Down Expand Up @@ -210,6 +241,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 +308,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
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
2 changes: 1 addition & 1 deletion apis/cognitoidentity/v1alpha1/zz_doc.go

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

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, "")
}
}
Loading

0 comments on commit d5f6675

Please sign in to comment.