Skip to content

Commit 8baf090

Browse files
authored
Generate Region() method for resourceIdentifiers (#309)
Follow up to aws-controllers-k8s/runtime#79 This patch modifies the code-generator to generate a `Region` function so that a resource can also satisfy the `Identifiers` interface. This the patch also extends the `setStatusDefaults` so that it correctly populates the `status.ResourceMetadata.Region` with the aws region in which it is created/managed Description of changes: - Add `Region()` method to resourceIdentifiers template. - Modifies `setStatusDefaults` to be able to set the a default region. - Update `runtime_test.go` By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 49bcb4d commit 8baf090

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

pkg/generate/ack/runtime_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ func (ids *fakeIdentifiers) OwnerAccountID() *ackv1alpha1.AWSAccountID {
4646
return &owner
4747
}
4848

49+
func (ids *fakeIdentifiers) Region() *ackv1alpha1.AWSRegion {
50+
region := ackv1alpha1.AWSRegion("us-west-2")
51+
return &region
52+
}
53+
4954
type fakeDescriptor struct{}
5055

5156
func (fd *fakeDescriptor) GroupKind() *metav1.GroupKind {

templates/pkg/resource/identifiers.go.tpl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,12 @@ func (ri *resourceIdentifiers) OwnerAccountID() *ackv1alpha1.AWSAccountID {
3131
}
3232
return nil
3333
}
34+
35+
// Region returns the AWS region in which the resource exists, or
36+
// nil if this information is not known.
37+
func (ri *resourceIdentifiers) Region() *ackv1alpha1.AWSRegion {
38+
if ri.meta != nil {
39+
return ri.meta.Region
40+
}
41+
return nil
42+
}

templates/pkg/resource/sdk.go.tpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ func (rm *resourceManager) setStatusDefaults (
182182
if ko.Status.ACKResourceMetadata == nil {
183183
ko.Status.ACKResourceMetadata = &ackv1alpha1.ResourceMetadata{}
184184
}
185+
if ko.Status.ACKResourceMetadata.Region == nil {
186+
ko.Status.ACKResourceMetadata.Region = &rm.awsRegion
187+
}
185188
if ko.Status.ACKResourceMetadata.OwnerAccountID == nil {
186189
ko.Status.ACKResourceMetadata.OwnerAccountID = &rm.awsAccountID
187190
}

0 commit comments

Comments
 (0)