@@ -8,10 +8,13 @@ import (
88 "path/filepath"
99 "time"
1010
11+ "github.com/krateoplatformops/unstructured-runtime/pkg/tools/unstructured/condition"
12+
1113 xcontext "github.com/krateoplatformops/unstructured-runtime/pkg/context"
1214
1315 "github.com/krateoplatformops/composition-dynamic-controller/internal/chartinspector"
1416 compositionMeta "github.com/krateoplatformops/composition-dynamic-controller/internal/meta"
17+ unstructuredtools "github.com/krateoplatformops/unstructured-runtime/pkg/tools/unstructured"
1518
1619 "github.com/krateoplatformops/composition-dynamic-controller/internal/helmclient"
1720 "github.com/krateoplatformops/composition-dynamic-controller/internal/helmclient/tracer"
@@ -200,12 +203,28 @@ func (h *handler) Observe(ctx context.Context, mg *unstructured.Unstructured) (c
200203 CompositionDefintionGVR : pkg .CompositionDefinitionInfo .GVR ,
201204 })
202205 if err != nil {
206+ retErr := fmt .Errorf ("generating RBAC using chart-inspector: %w" , err )
207+ condition := condition .Unavailable ()
208+ condition .Message = retErr .Error ()
209+ unstructuredtools .SetConditions (mg , condition )
210+ _ , err = tools .UpdateStatus (ctx , mg , updateOpts )
211+ if err != nil {
212+ return controller.ExternalObservation {}, fmt .Errorf ("updating status after failure: %w" , err )
213+ }
203214 return controller.ExternalObservation {}, fmt .Errorf ("generating RBAC using chart-inspector: %w" , err )
204215 }
205216 rbInstaller := rbac .NewRBACInstaller (dyn )
206217 err = rbInstaller .ApplyRBAC (generated )
207218 if err != nil {
208- return controller.ExternalObservation {}, fmt .Errorf ("installing rbac: %w" , err )
219+ retErr := fmt .Errorf ("applying rbac: %w" , err )
220+ condition := condition .Unavailable ()
221+ condition .Message = retErr .Error ()
222+ unstructuredtools .SetConditions (mg , condition )
223+ _ , err = tools .UpdateStatus (ctx , mg , updateOpts )
224+ if err != nil {
225+ return controller.ExternalObservation {}, fmt .Errorf ("updating status after failure: %w" , err )
226+ }
227+ return controller.ExternalObservation {}, retErr
209228 }
210229
211230 tracer := tracer .NewTracer (ctx , meta .IsVerbose (mg ))
@@ -238,7 +257,15 @@ func (h *handler) Observe(ctx context.Context, mg *unstructured.Unstructured) (c
238257
239258 upgradedRel , err := helmchart .Update (ctx , opts )
240259 if err != nil {
241- return controller.ExternalObservation {}, err
260+ retErr := fmt .Errorf ("updating helm chart: %w" , err )
261+ condition := condition .Unavailable ()
262+ condition .Message = retErr .Error ()
263+ unstructuredtools .SetConditions (mg , condition )
264+ _ , err = tools .UpdateStatus (ctx , mg , updateOpts )
265+ if err != nil {
266+ return controller.ExternalObservation {}, fmt .Errorf ("updating status after failure: %w" , err )
267+ }
268+ return controller.ExternalObservation {}, retErr
242269 }
243270
244271 _ , digest , err := helmchart .GetResourcesRefFromRelease (upgradedRel , mg .GetNamespace (), clientset )
0 commit comments