Skip to content

Commit

Permalink
chore: set component ownership when resolve component vars error (#7840)
Browse files Browse the repository at this point in the history
(cherry picked from commit 081cc62)
  • Loading branch information
Y-Rookie committed Jul 19, 2024
1 parent 8160c3b commit 9ce76de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 8 additions & 0 deletions controllers/apps/transformer_component_ownership.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
9 changes: 6 additions & 3 deletions controllers/apps/transformer_component_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit 9ce76de

Please sign in to comment.