Skip to content

Commit 0e5ae97

Browse files
authored
Merge pull request #544 from TiberiuGC/feature/allow-cyclic-references
Allow skipping state validations for resources that support cyclic references
2 parents 3385813 + 8213a7d commit 0e5ae97

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

pkg/config/field.go

+14
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,20 @@ type ReferencesConfig struct {
354354
// Resource mentions the K8s resource which is read to resolve the
355355
// reference
356356
Resource string `json:"resource"`
357+
// SkipResourceStateValidations if true, skips state validations performed during
358+
// ResolveReferences step, that ensure the referenced resource exists in AWS and is synced.
359+
// This is needed when multiple resources reference each other in a cyclic manner,
360+
// as otherwise they will never sync due to circular ResourceReferenceNotSynced errors.
361+
//
362+
// see: https://github.com/aws-controllers-k8s/community/issues/2119
363+
//
364+
// N.B. when setting this field to true, the developer is responsible to amend the sdkCreate
365+
// and/or sdkUpdate functions of the referencing resource, in order to correctly wait on the
366+
// desired state of the referenced resource, before SDK API calls that require the latter.
367+
// In the future, we could consider generating this logic, but for now this is a niche use case.
368+
//
369+
// see: https://github.com/aws-controllers-k8s/ec2-controller/blob/main/pkg/resource/security_group/sdk.go
370+
SkipResourceStateValidations bool `json:"skip_resource_state_validations"`
357371
// Path refers to the the path of field which should be copied
358372
// to resolve the reference
359373
Path string `json:"path"`

templates/pkg/resource/references_read_referenced_resource.go.tpl

+10-5
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,8 @@ func getReferencedResourceState_{{ .FieldConfig.References.Resource }}(
2828
if err != nil {
2929
return err
3030
}
31-
var refResourceSynced, refResourceTerminal bool
31+
var refResourceTerminal bool
3232
for _, cond := range obj.Status.Conditions {
33-
if cond.Type == ackv1alpha1.ConditionTypeResourceSynced &&
34-
cond.Status == corev1.ConditionTrue {
35-
refResourceSynced = true
36-
}
3733
if cond.Type == ackv1alpha1.ConditionTypeTerminal &&
3834
cond.Status == corev1.ConditionTrue {
3935
return ackerr.ResourceReferenceTerminalFor(
@@ -46,6 +42,14 @@ func getReferencedResourceState_{{ .FieldConfig.References.Resource }}(
4642
"{{ .FieldConfig.References.Resource }}",
4743
namespace, name)
4844
}
45+
{{if not .FieldConfig.References.SkipResourceStateValidations -}}
46+
var refResourceSynced bool
47+
for _, cond := range obj.Status.Conditions {
48+
if cond.Type == ackv1alpha1.ConditionTypeResourceSynced &&
49+
cond.Status == corev1.ConditionTrue {
50+
refResourceSynced = true
51+
}
52+
}
4953
if !refResourceSynced {
5054
return ackerr.ResourceReferenceNotSyncedFor(
5155
"{{ .FieldConfig.References.Resource }}",
@@ -57,6 +61,7 @@ func getReferencedResourceState_{{ .FieldConfig.References.Resource }}(
5761
namespace, name,
5862
"{{ .FieldConfig.References.Path }}")
5963
}
64+
{{- end}}
6065
return nil
6166
}
6267
{{- end -}}

0 commit comments

Comments
 (0)