diff --git a/controllers/apps/transformer_component_ownership.go b/controllers/apps/transformer_component_ownership.go index e8bea82d241..247ad27f965 100644 --- a/controllers/apps/transformer_component_ownership.go +++ b/controllers/apps/transformer_component_ownership.go @@ -112,3 +112,11 @@ func errPrematureStopWithSetCompOwnership(comp *appsv1alpha1.Component, dag *gra } return graph.ErrPrematureStop } + +// errWithSetCompOwnership is a helper function that sets component ownership before returns err +// TODO: refactor to set ownership information when creating each object, instead of setting it uniformly. +func errWithSetCompOwnership(comp *appsv1alpha1.Component, dag *graph.DAG, cli client.Reader, err error) error { + graphCli, _ := cli.(model.GraphClient) + _ = setCompOwnership(comp, dag, graphCli) + return err +} diff --git a/controllers/apps/transformer_component_vars.go b/controllers/apps/transformer_component_vars.go index 546cfcfdadd..6df233ce016 100644 --- a/controllers/apps/transformer_component_vars.go +++ b/controllers/apps/transformer_component_vars.go @@ -62,7 +62,7 @@ func (t *componentVarsTransformer) Transform(ctx graph.TransformContext, dag *gr legacy, err := generatedComponent4LegacyCluster(transCtx) if err != nil { - return err + return errWithSetCompOwnership(transCtx.Component, dag, graphCli, err) } var templateVars map[string]any @@ -75,14 +75,17 @@ func (t *componentVarsTransformer) Transform(ctx graph.TransformContext, dag *gr synthesizedComp, transCtx.CompDef.Spec.Vars) } if err != nil { - return err + return errWithSetCompOwnership(transCtx.Component, dag, graphCli, err) } // pass all direct value env vars through CM envVars2, envData := buildEnvVarsNData(synthesizedComp, envVars, legacy) setTemplateNEnvVars(synthesizedComp, templateVars, envVars2, legacy) - return createOrUpdateEnvConfigMap(ctx, dag, envData) + if err := createOrUpdateEnvConfigMap(ctx, dag, envData); err != nil { + return errWithSetCompOwnership(transCtx.Component, dag, graphCli, err) + } + return nil } // generatedComponent4LegacyCluster checks whether the cluster to which this component belongs was created before 0.8.