-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(directives): wire inputs into engine
Signed-off-by: Hidde Beydals <[email protected]>
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package directives | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/xeipuuv/gojsonschema" | ||
|
||
kargoapi "github.com/akuity/kargo/api/v1alpha1" | ||
) | ||
|
||
func init() { | ||
builtins.RegisterPromotionStepRunner(newOutputsComposer(), nil) | ||
} | ||
|
||
// outputsComposer is an implementation of the PromotionStepRunner interface that | ||
// allows composing outputs from previous steps into new outputs. | ||
type outputsComposer struct { | ||
schemaLoader gojsonschema.JSONLoader | ||
} | ||
|
||
// newOutputsComposer returns an implementation of the PromotionStepRunner | ||
// interface that composes outputs from previous steps into new outputs. | ||
func newOutputsComposer() PromotionStepRunner { | ||
r := &outputsComposer{} | ||
r.schemaLoader = getConfigSchemaLoader(r.Name()) | ||
return r | ||
} | ||
|
||
// Name implements the PromotionStepRunner interface. | ||
func (c *outputsComposer) Name() string { | ||
return "compose-outputs" | ||
} | ||
|
||
// RunPromotionStep implements the PromotionStepRunner interface. | ||
func (c *outputsComposer) RunPromotionStep( | ||
ctx context.Context, | ||
stepCtx *PromotionStepContext, | ||
) (PromotionStepResult, error) { | ||
// Validate the configuration against the JSON Schema. | ||
if err := validate(c.schemaLoader, gojsonschema.NewGoLoader(stepCtx.Config), c.Name()); err != nil { | ||
return PromotionStepResult{Status: kargoapi.PromotionPhaseErrored}, err | ||
} | ||
|
||
// Convert the configuration into a typed object. | ||
cfg, err := ConfigToStruct[ComposeOutputs](stepCtx.Config) | ||
if err != nil { | ||
return PromotionStepResult{Status: kargoapi.PromotionPhaseErrored}, | ||
fmt.Errorf("could not convert config into %s config: %w", c.Name(), err) | ||
} | ||
|
||
return c.runPromotionStep(ctx, stepCtx, cfg) | ||
} | ||
|
||
func (c *outputsComposer) runPromotionStep( | ||
ctx context.Context, | ||
stepCtx *PromotionStepContext, | ||
cfg ComposeOutputs, | ||
) (PromotionStepResult, error) { | ||
for newKey, f := range cfg.Fields { | ||
stepState, ok := stepCtx.SharedState[f.FromStep] | ||
if !ok { | ||
return PromotionStepResult{Status: kargoapi.PromotionPhaseFailed}, | ||
fmt.Errorf("unable to compose output %q from step %q: step not found", newKey, f.FromStep) | ||
} | ||
|
||
|
||
} | ||
return PromotionStepResult{Status: kargoapi.PromotionPhaseSucceeded}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters