Skip to content

Commit 0ecfda5

Browse files
committed
feat: rm.IsSynced returns requeueError when false
This changes introduce a new field in generator.yaml SyncedConfig, which lets us define custom reuqueue duration. If it is not defined, the duration will default to the DefaultSyncPeriod
1 parent ed3e8af commit 0ecfda5

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

pkg/config/resource.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ type SyncedCondition struct {
152152
Path *string `json:"path"`
153153
// In contains a list of possible values `Path` should be equal to.
154154
In []string `json:"in"`
155+
// RequeueError custom SyncPeriod in seconds
156+
RequeueTime *int `json:"requeueTime,omitempty`
155157
}
156158

157159
// HooksConfig instructs the code generator how to inject custom callback hooks

pkg/generate/code/synced.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,17 @@ func ResourceIsSynced(
7575
msg := fmt.Sprintf("cannot find top level field of path '%s': %v", *condCfg.Path, err)
7676
panic(msg)
7777
}
78+
notSyncedErr := ""
79+
if condCfg.RequeueTime != nil {
80+
notSyncedErr = fmt.Sprintf("ackrequeue.NeededAfter(fmt.Errorf(\"requeing until resource status is %v\"), time.Duration(%d)*time.Second)", condCfg.In, *condCfg.RequeueTime)
81+
} else {
82+
notSyncedErr = fmt.Sprintf("ackrequeue.Needed(fmt.Errorf(\"requeing until resource status is %v\"))", condCfg.In)
83+
}
7884
candidatesVarName := fmt.Sprintf("%sCandidates", field.Names.CamelLower)
7985
if fp.Size() == 2 {
80-
out += scalarFieldEqual(resVarName, candidatesVarName, field.ShapeRef.GoTypeElem(), condCfg)
86+
out += scalarFieldEqual(resVarName, candidatesVarName, field.ShapeRef.GoTypeElem(), condCfg, notSyncedErr)
8187
} else {
82-
out += fieldPathSafeEqual(resVarName, candidatesVarName, field, condCfg)
88+
out += fieldPathSafeEqual(resVarName, candidatesVarName, field, condCfg, notSyncedErr)
8389
}
8490
}
8591

@@ -118,6 +124,7 @@ func scalarFieldEqual(
118124
candidatesVarName string,
119125
goType string,
120126
condCfg ackgenconfig.SyncedCondition,
127+
notSyncedErr string,
121128
) string {
122129
out := ""
123130
fieldPath := fmt.Sprintf("%s.%s", resVarName, *condCfg.Path)
@@ -156,7 +163,7 @@ func scalarFieldEqual(
156163
)
157164

158165
// return false, nil
159-
out += "\t\treturn false, nil\n"
166+
out += fmt.Sprintf("\t\treturn false, %s\n", notSyncedErr)
160167
// }
161168
out += "\t}\n"
162169
return out
@@ -168,6 +175,7 @@ func fieldPathSafeEqual(
168175
candidatesVarName string,
169176
field *model.Field,
170177
condCfg ackgenconfig.SyncedCondition,
178+
notSyncedErr string,
171179
) string {
172180
out := ""
173181
rootPath := fmt.Sprintf("%s.%s", resVarName, strings.Split(*condCfg.Path, ".")[0])
@@ -187,11 +195,11 @@ func fieldPathSafeEqual(
187195
// if r.ko.Spec.ProvisionedThroughput == nil
188196
out += fmt.Sprintf("\tif %s == nil {\n", subFieldPath)
189197
// return false, nil
190-
out += "\t\treturn false, nil\n"
198+
out += fmt.Sprintf("\t\treturn false, %s\n", notSyncedErr)
191199
// }
192200
out += "\t}\n"
193201
}
194-
out += scalarFieldEqual(resVarName, candidatesVarName, shapes[len(shapes)-1].GoTypeElem(), condCfg)
202+
out += scalarFieldEqual(resVarName, candidatesVarName, shapes[len(shapes)-1].GoTypeElem(), condCfg, notSyncedErr)
195203
return out
196204
}
197205

0 commit comments

Comments
 (0)