Skip to content

Commit 5e27da3

Browse files
authored
Merge pull request #458 from MisterMX/feat/isuptodate-context
feat(crossplane): Add context to isUpToDate and return diff
2 parents e0dc6c3 + 4b7c1ed commit 5e27da3

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

templates/crossplane/pkg/controller.go.tpl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,14 @@ func (e *external) Observe(ctx context.Context, mg cpresource.Managed) (managed.
104104
}
105105
Generate{{ .CRD.Names.Camel }}(resp).Status.AtProvider.DeepCopyInto(&cr.Status.AtProvider)
106106

107-
upToDate, err := e.isUpToDate(cr, resp)
107+
upToDate, diff, err := e.isUpToDate(ctx, cr, resp)
108108
if err != nil {
109109
return managed.ExternalObservation{}, errors.Wrap(err, "isUpToDate check failed")
110110
}
111111
return e.postObserve(ctx, cr, resp, managed.ExternalObservation{
112112
ResourceExists: true,
113113
ResourceUpToDate: upToDate,
114+
Diff: diff,
114115
ResourceLateInitialized: !cmp.Equal(&cr.Spec.ForProvider, currentSpec),
115116
}, nil)
116117
{{- else }}
@@ -228,18 +229,18 @@ type external struct {
228229
preObserve func(context.Context, *svcapitypes.{{ .CRD.Names.Camel }}, *svcsdk.{{ .CRD.Ops.ReadOne.InputRef.Shape.ShapeName }}) error
229230
postObserve func(context.Context, *svcapitypes.{{ .CRD.Names.Camel }}, *svcsdk.{{ .CRD.Ops.ReadOne.OutputRef.Shape.ShapeName }}, managed.ExternalObservation, error) (managed.ExternalObservation, error)
230231
lateInitialize func(*svcapitypes.{{ .CRD.Names.Camel }}Parameters, *svcsdk.{{ .CRD.Ops.ReadOne.OutputRef.Shape.ShapeName }}) error
231-
isUpToDate func(*svcapitypes.{{ .CRD.Names.Camel }}, *svcsdk.{{ .CRD.Ops.ReadOne.OutputRef.Shape.ShapeName }}) (bool, error)
232+
isUpToDate func(context.Context, *svcapitypes.{{ .CRD.Names.Camel }}, *svcsdk.{{ .CRD.Ops.ReadOne.OutputRef.Shape.ShapeName }}) (bool, string, error)
232233
{{- else if .CRD.Ops.GetAttributes }}
233234
preObserve func(context.Context, *svcapitypes.{{ .CRD.Names.Camel }}, *svcsdk.{{ .CRD.Ops.GetAttributes.InputRef.Shape.ShapeName }}) error
234235
postObserve func(context.Context, *svcapitypes.{{ .CRD.Names.Camel }}, *svcsdk.{{ .CRD.Ops.GetAttributes.OutputRef.Shape.ShapeName }}, managed.ExternalObservation, error) (managed.ExternalObservation, error)
235236
lateInitialize func(*svcapitypes.{{ .CRD.Names.Camel }}Parameters, *svcsdk.{{ .CRD.Ops.GetAttributes.OutputRef.Shape.ShapeName }}) error
236-
isUpToDate func(*svcapitypes.{{ .CRD.Names.Camel }}, *svcsdk.{{ .CRD.Ops.GetAttributes.OutputRef.Shape.ShapeName }}) (bool, error)
237+
isUpToDate func(context.Context, *svcapitypes.{{ .CRD.Names.Camel }}, *svcsdk.{{ .CRD.Ops.GetAttributes.OutputRef.Shape.ShapeName }}) (bool, string, error)
237238
{{- else if .CRD.Ops.ReadMany }}
238239
preObserve func(context.Context, *svcapitypes.{{ .CRD.Names.Camel }}, *svcsdk.{{ .CRD.Ops.ReadMany.InputRef.Shape.ShapeName }}) error
239240
postObserve func(context.Context, *svcapitypes.{{ .CRD.Names.Camel }}, *svcsdk.{{ .CRD.Ops.ReadMany.OutputRef.Shape.ShapeName }}, managed.ExternalObservation, error) (managed.ExternalObservation, error)
240241
filterList func(*svcapitypes.{{ .CRD.Names.Camel }}, *svcsdk.{{ .CRD.Ops.ReadMany.OutputRef.Shape.ShapeName }}) *svcsdk.{{ .CRD.Ops.ReadMany.OutputRef.Shape.ShapeName }}
241242
lateInitialize func(*svcapitypes.{{ .CRD.Names.Camel }}Parameters, *svcsdk.{{ .CRD.Ops.ReadMany.OutputRef.Shape.ShapeName }}) error
242-
isUpToDate func(*svcapitypes.{{ .CRD.Names.Camel }}, *svcsdk.{{ .CRD.Ops.ReadMany.OutputRef.Shape.ShapeName }}) (bool, error)
243+
isUpToDate func(context.Context, *svcapitypes.{{ .CRD.Names.Camel }}, *svcsdk.{{ .CRD.Ops.ReadMany.OutputRef.Shape.ShapeName }}) (bool, string, error)
243244
{{- else }}
244245
observe func(context.Context, cpresource.Managed) (managed.ExternalObservation, error)
245246
{{- end }}
@@ -270,8 +271,8 @@ func nopPostObserve(_ context.Context, _ *svcapitypes.{{ .CRD.Names.Camel }}, _
270271
func nopLateInitialize(*svcapitypes.{{ .CRD.Names.Camel }}Parameters, *svcsdk.{{ .CRD.Ops.ReadOne.OutputRef.Shape.ShapeName }}) error {
271272
return nil
272273
}
273-
func alwaysUpToDate(*svcapitypes.{{ .CRD.Names.Camel }}, *svcsdk.{{ .CRD.Ops.ReadOne.OutputRef.Shape.ShapeName }}) (bool, error) {
274-
return true, nil
274+
func alwaysUpToDate(context.Context, *svcapitypes.{{ .CRD.Names.Camel }}, *svcsdk.{{ .CRD.Ops.ReadOne.OutputRef.Shape.ShapeName }}) (bool, string, error) {
275+
return true, "", nil
275276
}
276277
{{- else if .CRD.Ops.GetAttributes }}
277278
func nopPreObserve(context.Context, *svcapitypes.{{ .CRD.Names.Camel }}, *svcsdk.{{ .CRD.Ops.GetAttributes.InputRef.Shape.ShapeName }}) error {
@@ -284,8 +285,8 @@ func nopPostObserve(_ context.Context, _ *svcapitypes.{{ .CRD.Names.Camel }}, _
284285
func nopLateInitialize(*svcapitypes.{{ .CRD.Names.Camel }}Parameters, *svcsdk.{{ .CRD.Ops.GetAttributes.OutputRef.Shape.ShapeName }}) error {
285286
return nil
286287
}
287-
func alwaysUpToDate(*svcapitypes.{{ .CRD.Names.Camel }}, *svcsdk.{{ .CRD.Ops.GetAttributes.OutputRef.Shape.ShapeName }}) (bool, error) {
288-
return true, nil
288+
func alwaysUpToDate(context.Context, *svcapitypes.{{ .CRD.Names.Camel }}, *svcsdk.{{ .CRD.Ops.GetAttributes.OutputRef.Shape.ShapeName }}) (bool, string, error) {
289+
return true, "", nil
289290
}
290291
{{- else if .CRD.Ops.ReadMany }}
291292
func nopPreObserve(context.Context, *svcapitypes.{{ .CRD.Names.Camel }}, *svcsdk.{{ .CRD.Ops.ReadMany.InputRef.Shape.ShapeName }}) error {
@@ -301,8 +302,8 @@ func nopFilterList(_ *svcapitypes.{{ .CRD.Names.Camel }}, list *svcsdk.{{ .CRD.O
301302
func nopLateInitialize(*svcapitypes.{{ .CRD.Names.Camel }}Parameters, *svcsdk.{{ .CRD.Ops.ReadMany.OutputRef.Shape.ShapeName }}) error {
302303
return nil
303304
}
304-
func alwaysUpToDate(*svcapitypes.{{ .CRD.Names.Camel }}, *svcsdk.{{ .CRD.Ops.ReadMany.OutputRef.Shape.ShapeName }}) (bool, error) {
305-
return true, nil
305+
func alwaysUpToDate(context.Context, *svcapitypes.{{ .CRD.Names.Camel }}, *svcsdk.{{ .CRD.Ops.ReadMany.OutputRef.Shape.ShapeName }}) (bool, string, error) {
306+
return true, "", nil
306307
}
307308
{{ else }}
308309
func nopObserve(context.Context, cpresource.Managed) (managed.ExternalObservation, error) {

0 commit comments

Comments
 (0)