@@ -114,17 +114,11 @@ func (f *Function) RunFunction(ctx context.Context, req *fnv1beta1.RunFunctionRe
114
114
}
115
115
116
116
if input .Environment != nil {
117
- // Run all patches that are from the (observed) XR to the environment.
118
- if err := RenderToEnvironmentPatches (env , oxr .Resource , input .Environment .Patches ); err != nil {
117
+ // Run all patches that are from the (observed) XR to the environment or from the environment to the (desired) XR .
118
+ if err := RenderEnvironmentPatches (env , oxr . Resource , dxr .Resource , input .Environment .Patches ); err != nil {
119
119
response .Fatal (rsp , errors .Wrapf (err , "cannot render ToEnvironment patches from the composite resource" ))
120
120
return rsp , nil
121
121
}
122
-
123
- // Run all patches that are from the environment to the (desired) XR.
124
- if err := RenderFromEnvironmentPatches (dxr .Resource , env , input .Environment .Patches ); err != nil {
125
- response .Fatal (rsp , errors .Wrapf (err , "cannot render FromEnvironment patches to the composite resource" ))
126
- return rsp , nil
127
- }
128
122
}
129
123
130
124
// Increment this if you emit a warning result.
@@ -196,58 +190,19 @@ func (f *Function) RunFunction(ctx context.Context, req *fnv1beta1.RunFunctionRe
196
190
log .Debug ("Found corresponding observed resource" ,
197
191
"ready" , ready ,
198
192
"name" , ocd .Resource .GetName ())
199
-
200
- // TODO(negz): Should failures to patch the XR be terminal? It could
201
- // indicate a required patch failed. A required patch means roughly
202
- // "this patch has to succeed before you mutate the resource". This
203
- // is useful to make sure we never create a composed resource in the
204
- // wrong state. It's less clear how useful it is for the XR, given
205
- // we'll only ever be updating it, not creating it.
206
-
207
- // We want to patch the XR from observed composed resources, not
208
- // from desired state. This is because folks will typically be
209
- // patching from a field that is set once the observed resource is
210
- // applied such as its status.
211
- if err := RenderToCompositePatches (dxr .Resource , ocd .Resource , t .Patches ); err != nil {
212
- response .Warning (rsp , errors .Wrapf (err , "cannot render ToComposite patches for composed resource %q" , t .Name ))
213
- log .Info ("Cannot render ToComposite patches for composed resource" , "warning" , err )
214
- warnings ++
215
- }
216
-
217
- // TODO(negz): Same as above, but for the Environment. What does it
218
- // mean for a required patch to the environment to fail? Should it
219
- // be terminal?
220
-
221
- // Run all patches that are from the (observed) composed resource to
222
- // the environment.
223
- if err := RenderToEnvironmentPatches (env , ocd .Resource , t .Patches ); err != nil {
224
- response .Warning (rsp , errors .Wrapf (err , "cannot render ToEnvironment patches for composed resource %q" , t .Name ))
225
- log .Info ("Cannot render ToEnvironment patches for composed resource" , "warning" , err )
226
- warnings ++
227
- }
228
193
}
229
194
230
- // If either of the below renderings return an error, most likely a
231
- // required FromComposite or FromEnvironment patch failed. A required
232
- // patch means roughly "this patch has to succeed before you mutate the
233
- // resource." This is useful to make sure we never create a composed
234
- // resource in the wrong state. To that end, we don't want to add this
235
- // resource to our accumulated desired state.
236
- if err := RenderFromCompositePatches (dcd .Resource , oxr .Resource , t .Patches ); err != nil {
237
- response .Warning (rsp , errors .Wrapf (err , "cannot render FromComposite patches for composed resource %q" , t .Name ))
238
- log .Info ("Cannot render FromComposite patches for composed resource" , "warning" , err )
195
+ errs , store := RenderComposedPatches (ocd .Resource , dcd .Resource , oxr .Resource , dxr .Resource , env , t .Patches )
196
+ for _ , err := range errs {
197
+ response .Warning (rsp , errors .Wrapf (err , "cannot render patches for composed resource %q" , t .Name ))
198
+ log .Info ("Cannot render patches for composed resource" , "warning" , err )
239
199
warnings ++
240
- continue
241
- }
242
- if err := RenderFromEnvironmentPatches (dcd .Resource , env , t .Patches ); err != nil {
243
- response .Warning (rsp , errors .Wrapf (err , "cannot render FromEnvironment patches for composed resource %q" , t .Name ))
244
- log .Info ("Cannot render FromEnvironment patches for composed resource" , "warning" , err )
245
- warnings ++
246
- continue
247
200
}
248
201
249
- // Add or replace our desired resource.
250
- desired [resource .Name (t .Name )] = dcd
202
+ if store {
203
+ // Add or replace our desired resource.
204
+ desired [resource .Name (t .Name )] = dcd
205
+ }
251
206
}
252
207
253
208
if err := response .SetDesiredCompositeResource (rsp , dxr ); err != nil {
0 commit comments