Skip to content

Commit

Permalink
chore(directives): wire inputs into engine
Browse files Browse the repository at this point in the history
Signed-off-by: Hidde Beydals <[email protected]>
  • Loading branch information
hiddeco committed Dec 13, 2024
1 parent e6610db commit 620f666
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/controller/promotions/promotions.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ func (r *reconciler) promote(
Kind: step.Uses,
Alias: step.As,
Retry: step.Retry,
Inputs: step.Inputs,

Check warning on line 474 in internal/controller/promotions/promotions.go

View check run for this annotation

Codecov / codecov/patch

internal/controller/promotions/promotions.go#L474

Added line #L474 was not covered by tests
Config: step.Config.Raw,
}
}
Expand Down
14 changes: 14 additions & 0 deletions internal/directives/promotions.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ type PromotionStep struct {
Alias string
// Retry is the retry configuration for the PromotionStep.
Retry *kargoapi.PromotionStepRetry
// Inputs is a list of inputs to be made available to the Config of this step.
Inputs []kargoapi.PromotionStepInput
// Config is an opaque JSON to be passed to the PromotionStepRunner executing
// this step.
Config []byte
Expand Down Expand Up @@ -144,6 +146,8 @@ func (s *PromotionStep) GetConfig(
return nil, err
}

inputs := s.GetInputs()

evaledCfgJSON, err := expressions.EvaluateJSONTemplate(
s.Config,
map[string]any{
Expand All @@ -153,6 +157,7 @@ func (s *PromotionStep) GetConfig(
"stage": promoCtx.Stage,
},
"vars": vars,
"inputs": inputs,
"secrets": promoCtx.Secrets,
"outputs": state,
},
Expand Down Expand Up @@ -212,6 +217,15 @@ func (s *PromotionStep) GetVars(promoCtx PromotionContext) (map[string]any, erro
return vars, nil
}

// GetInputs returns the inputs of the PromotionStep as a map.
func (s *PromotionStep) GetInputs() map[string]any {
inputs := make(map[string]any, len(s.Inputs))
for _, i := range s.Inputs {
inputs[i.Name] = i.Value
}

Check warning on line 225 in internal/directives/promotions.go

View check run for this annotation

Codecov / codecov/patch

internal/directives/promotions.go#L224-L225

Added lines #L224 - L225 were not covered by tests
return inputs
}

// PromotionResult is the result of a user-defined promotion process executed by
// the Engine. It aggregates the status and output of the individual
// PromotionStepResults returned by the PromotionStepRunner executing each
Expand Down

0 comments on commit 620f666

Please sign in to comment.