Skip to content

Commit d5f6675

Browse files
authored
Merge pull request #1820 from atarax/atarax/globalaccelerator
2 parents 0334e7b + 5d59c21 commit d5f6675

32 files changed

+6269
-4
lines changed

CODE_GENERATION.md

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,39 @@ files that help CRD structs satisfy the Go interfaces we use in crossplane-runti
100100
There are a few things we need to implement manually since there is no support for
101101
their generation yet.
102102

103+
### Setup Api Group
104+
105+
If a new group of api's has been introduced, we will need write a `Setup` function to satisfy
106+
the interface which we will need to register the contollers. For example, if you added `globalaccelerator`
107+
api group, we will need a file in `pkg/controller/globalaccelerator/setup.go with following contents:
108+
109+
```golang
110+
package globalaccelerator
111+
112+
import (
113+
ctrl "sigs.k8s.io/controller-runtime"
114+
115+
"github.com/crossplane/crossplane-runtime/pkg/controller"
116+
117+
"github.com/crossplane-contrib/provider-aws/pkg/controller/globalaccelerator/accelerator"
118+
"github.com/crossplane-contrib/provider-aws/pkg/controller/globalaccelerator/listener"
119+
"github.com/crossplane-contrib/provider-aws/pkg/controller/globalaccelerator/endpointgroup"
120+
"github.com/crossplane-contrib/provider-aws/pkg/utils/setup"
121+
)
122+
123+
// Setup athena controllers.
124+
func Setup(mgr ctrl.Manager, o controller.Options) error {
125+
return setup.SetupControllers(
126+
mgr, o,
127+
accelerator.SetupAccelerator,
128+
listener.SetupListener,
129+
endpointgroup.SetupEndpointGroup,
130+
)
131+
}
132+
```
133+
134+
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).
135+
103136
### Setup Controller
104137

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

133-
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).
134-
135166
#### Register CRD
136167

137168
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).
@@ -210,6 +241,9 @@ external name of the referenced object, you can use the following comment marker
210241
You can add the package prefix for `type` and `extractor` configurations if they
211242
live in a different Go package.
212243

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

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

314+
### Errors On Observe
315+
316+
In some situations aws api returns an error in cases where the resource does not exist.
317+
It will be noticeable when the resource never gets created but you see an error from the api
318+
which describes the object. You should see `return ok && awsErr.Code() == "ResourceNotFoundException"` in
319+
the `IsNotFound`-function of `zz_conversion.go`.
320+
321+
To tell ack which error indicates that the resource is not present, add a similar config to `generator-config.yaml`:
322+
323+
```
324+
resources:
325+
Table:
326+
fields:
327+
PointInTimeRecoveryEnabled:
328+
from:
329+
operation: UpdateContinuousBackups
330+
path: PointInTimeRecoverySpecification.PointInTimeRecoveryEnabled
331+
exceptions:
332+
errors:
333+
404:
334+
code: ResourceNotFoundException
335+
```
336+
337+
280338
### Readiness Check
281339

282340
Every managed resource needs to report its readiness. We'll do that in `postObserve`

apis/aws.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import (
5858
elbv2manualv1alpha1 "github.com/crossplane-contrib/provider-aws/apis/elbv2/manualv1alpha1"
5959
elbv2v1alpha1 "github.com/crossplane-contrib/provider-aws/apis/elbv2/v1alpha1"
6060
emrcontainersv1alpah1 "github.com/crossplane-contrib/provider-aws/apis/emrcontainers/v1alpha1"
61+
globalacceleratorv1alpha1 "github.com/crossplane-contrib/provider-aws/apis/globalaccelerator/v1alpha1"
6162
gluev1alpha1 "github.com/crossplane-contrib/provider-aws/apis/glue/v1alpha1"
6263
iamv1alpha1 "github.com/crossplane-contrib/provider-aws/apis/iam/v1alpha1"
6364
iamv1beta1 "github.com/crossplane-contrib/provider-aws/apis/iam/v1beta1"
@@ -148,6 +149,7 @@ func init() {
148149
kafkav1alpha1.SchemeBuilder.AddToScheme,
149150
transferv1alpha1.SchemeBuilder.AddToScheme,
150151
gluev1alpha1.SchemeBuilder.AddToScheme,
152+
globalacceleratorv1alpha1.SchemeBuilder.AddToScheme,
151153
mqv1alpha1.SchemeBuilder.AddToScheme,
152154
mwaav1alpha1.SchemeBuilder.AddToScheme,
153155
cloudwatchlogsv1alpha1.SchemeBuilder.AddToScheme,

apis/cognitoidentity/v1alpha1/zz_doc.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
ignore:
2+
field_paths:
3+
- "CreateAcceleratorInput.IdempotencyToken"
4+
- "CreateListenerInput.AcceleratorArn"
5+
- "CreateListenerInput.IdempotencyToken"
6+
- "CreateEndpointGroupInput.ListenerArn"
7+
- "CreateEndpointGroupInput.IdempotencyToken"
8+
resource_names:
9+
- "CustomRoutingAccelerator"
10+
- "CustomRoutingEndpointGroup"
11+
- "CustomRoutingListener"
12+
13+
resources:
14+
Accelerator:
15+
exceptions:
16+
errors:
17+
404:
18+
code: AcceleratorNotFoundException
19+
Listener:
20+
exceptions:
21+
errors:
22+
404:
23+
code: ListenerNotFoundException
24+
EndpointGroup:
25+
exceptions:
26+
errors:
27+
404:
28+
code: EndpointGroupNotFoundException
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Copyright 2021 The Crossplane Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
20+
21+
// CustomAcceleratorParameters contains the additional fields for AcceleratorParameters
22+
type CustomAcceleratorParameters struct{}
23+
24+
// CustomEndpointGroupParameters contains the additional fields for EndpointGroupParameters
25+
type CustomEndpointGroupParameters struct {
26+
// ListenerArn is the ARN for the Listener.
27+
// +immutable
28+
// +crossplane:generate:reference:type=Listener
29+
// +crossplane:generate:reference:extractor=ListenerARN()
30+
// +crossplane:generate:reference:refFieldName=ListenerArnRef
31+
// +crossplane:generate:reference:selectorFieldName=ListenerArnSelector
32+
ListenerARN *string `json:"listenerArn,omitempty"`
33+
34+
// ListenerArnRef is a reference to an ARN used to set
35+
// the ListenerArn.
36+
// +optional
37+
ListenerArnRef *xpv1.Reference `json:"listenerArnRef,omitempty"`
38+
39+
// ListenerArnSelector selects references to Listener used
40+
// to set the Arn.
41+
// +optional
42+
ListenerArnSelector *xpv1.Selector `json:"listenerArnSelector,omitempty"`
43+
}
44+
45+
// CustomListenerParameters contains the additional fields for ListenerParameters
46+
type CustomListenerParameters struct {
47+
// AcceleratorArn is the ARN for the Accelerator.
48+
// +immutable
49+
// +crossplane:generate:reference:type=Accelerator
50+
// +crossplane:generate:reference:extractor=AcceleratorARN()
51+
// +crossplane:generate:reference:refFieldName=AcceleratorArnRef
52+
// +crossplane:generate:reference:selectorFieldName=AcceleratorArnSelector
53+
AcceleratorArn *string `json:"acceleratorArn,omitempty"`
54+
55+
// AcceleratorArnRef is a reference to an ARN used to set
56+
// the AcceleratorArn.
57+
// +optional
58+
AcceleratorArnRef *xpv1.Reference `json:"acceleratorArnRef,omitempty"`
59+
60+
// AcceleratorArnSelector selects references to Accelerator used
61+
// to set the Arn.
62+
// +optional
63+
AcceleratorArnSelector *xpv1.Selector `json:"acceleratorArnSelector,omitempty"`
64+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package v1alpha1
2+
3+
import (
4+
"github.com/crossplane/crossplane-runtime/pkg/reference"
5+
"github.com/crossplane/crossplane-runtime/pkg/resource"
6+
"k8s.io/utils/pointer"
7+
)
8+
9+
// AcceleratorARN returns the status.atProvider.ARN of an Accelerator
10+
func AcceleratorARN() reference.ExtractValueFn {
11+
return func(mg resource.Managed) string {
12+
r, ok := mg.(*Accelerator)
13+
if !ok {
14+
return ""
15+
}
16+
17+
return pointer.StringDeref(r.Status.AtProvider.AcceleratorARN, "")
18+
}
19+
}
20+
21+
// ListenerARN returns the status.atProvider.ARN of an Listener
22+
func ListenerARN() reference.ExtractValueFn {
23+
return func(mg resource.Managed) string {
24+
r, ok := mg.(*Listener)
25+
if !ok {
26+
return ""
27+
}
28+
29+
return pointer.StringDeref(r.Status.AtProvider.ListenerARN, "")
30+
}
31+
}

0 commit comments

Comments
 (0)