Skip to content

Commit 510954a

Browse files
committed
wip
Signed-off-by: Carolyn Van Slyck <[email protected]>
1 parent 3ddf1f9 commit 510954a

File tree

9 files changed

+37
-30
lines changed

9 files changed

+37
-30
lines changed

pkg/cnab/bundleruntime/action.go

+14-13
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ func (r *Runtime) AddRelocation(args ActionArguments) cnabaction.OperationConfig
125125
}
126126
}
127127

128-
func (r *Runtime) Execute(ctx context.Context, args ActionArguments) error {
128+
func (r *Runtime) Execute(ctx context.Context, args ActionArguments) (storage.Run, storage.Result, error) {
129129
// Check if we've been asked to stop before executing long blocking calls
130130
select {
131131
case <-ctx.Done():
132-
return ctx.Err()
132+
return storage.Run{}, storage.Result{}, ctx.Err()
133133
default:
134134
ctx, log := tracing.StartSpan(ctx,
135135
attribute.String("action", args.Action),
@@ -140,33 +140,33 @@ func (r *Runtime) Execute(ctx context.Context, args ActionArguments) error {
140140
args.Installation.AddToTrace(ctx)
141141

142142
if args.Action == "" {
143-
return log.Error(errors.New("action is required"))
143+
return storage.Run{}, storage.Result{}, log.Error(errors.New("action is required"))
144144
}
145145

146146
b, err := r.ProcessBundle(ctx, args.BundleReference.Definition)
147147
if err != nil {
148-
return log.Error(err)
148+
return storage.Run{}, storage.Result{}, log.Error(err)
149149
}
150150

151151
currentRun, err := r.CreateRun(ctx, args, b)
152152
if err != nil {
153-
return log.Error(err)
153+
return storage.Run{}, storage.Result{}, log.Error(err)
154154
}
155155

156156
// Validate the action
157157
if _, err := b.GetAction(currentRun.Action); err != nil {
158-
return log.Error(fmt.Errorf("invalid action '%s' specified for bundle %s: %w", currentRun.Action, b.Name, err))
158+
return storage.Run{}, storage.Result{}, log.Error(fmt.Errorf("invalid action '%s' specified for bundle %s: %w", currentRun.Action, b.Name, err))
159159
}
160160

161161
creds, err := r.loadCredentials(ctx, b, args)
162162
if err != nil {
163-
return log.Error(fmt.Errorf("not load credentials: %w", err))
163+
return storage.Run{}, storage.Result{}, log.Error(fmt.Errorf("not load credentials: %w", err))
164164
}
165165

166166
log.Debugf("Using runtime driver %s\n", args.Driver)
167167
driver, err := r.newDriver(args.Driver, args)
168168
if err != nil {
169-
return log.Error(fmt.Errorf("unable to instantiate driver: %w", err))
169+
return storage.Run{}, storage.Result{}, log.Error(fmt.Errorf("unable to instantiate driver: %w", err))
170170
}
171171

172172
a := cnabaction.New(driver)
@@ -175,7 +175,7 @@ func (r *Runtime) Execute(ctx context.Context, args ActionArguments) error {
175175
if currentRun.ShouldRecord() {
176176
err = r.SaveRun(ctx, args.Installation, currentRun, cnab.StatusRunning)
177177
if err != nil {
178-
return log.Error(fmt.Errorf("could not save the pending action's status, the bundle was not executed: %w", err))
178+
return currentRun, storage.Result{}, log.Error(fmt.Errorf("could not save the pending action's status, the bundle was not executed: %w", err))
179179
}
180180
}
181181

@@ -187,19 +187,20 @@ func (r *Runtime) Execute(ctx context.Context, args ActionArguments) error {
187187
tracing.ObjectAttribute("cnab-credentials", cnabCreds))
188188
opResult, result, err := a.Run(cnabClaim, cnabCreds, r.ApplyConfig(ctx, args)...)
189189

190+
currentResult := currentRun.NewResultFrom(result)
190191
if currentRun.ShouldRecord() {
191192
if err != nil {
192193
err = r.appendFailedResult(ctx, err, currentRun)
193-
return log.Error(fmt.Errorf("failed to record that %s for installation %s failed: %w", args.Action, args.Installation.Name, err))
194+
return currentRun, currentResult, log.Error(fmt.Errorf("failed to record that %s for installation %s failed: %w", args.Action, args.Installation.Name, err))
194195
}
195-
return r.SaveOperationResult(ctx, opResult, args.Installation, currentRun, currentRun.NewResultFrom(result))
196+
return currentRun, currentResult, r.SaveOperationResult(ctx, opResult, args.Installation, currentRun, currentResult)
196197
}
197198

198199
if err != nil {
199-
return log.Error(fmt.Errorf("execution of %s for installation %s failed: %w", args.Action, args.Installation.Name, err))
200+
return currentRun, currentResult, log.Error(fmt.Errorf("execution of %s for installation %s failed: %w", args.Action, args.Installation.Name, err))
200201
}
201202

202-
return nil
203+
return currentRun, currentResult, nil
203204
}
204205
}
205206

pkg/cnab/bundleruntime/helpers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (t *TestRuntime) LoadTestBundle(bundleFile string) cnab.ExtendedBundle {
6969
return bun
7070
}
7171

72-
func (t *TestRuntime) Execute(ctx context.Context, args ActionArguments) error {
72+
func (t *TestRuntime) Execute(ctx context.Context, args ActionArguments) (storage.Run, storage.Result, error) {
7373
if args.Driver == "" {
7474
args.Driver = debugDriver
7575
}

pkg/cnab/bundleruntime/provider.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package bundleruntime
33
import (
44
"context"
55

6+
"get.porter.sh/porter/pkg/storage"
7+
68
"get.porter.sh/porter/pkg/cnab"
79
)
810

911
// CNABProvider is the interface Porter uses to communicate with the CNAB runtime
1012
type CNABProvider interface {
1113
LoadBundle(bundleFile string) (cnab.ExtendedBundle, error)
12-
Execute(ctx context.Context, arguments ActionArguments) error
14+
Execute(ctx context.Context, arguments ActionArguments) (storage.Run, storage.Result, error)
1315
}

pkg/porter/action.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,18 @@ func (p *Porter) ExecuteBundleAndDependencies(ctx context.Context, installation
9595
return err
9696
}
9797

98-
return p.CNAB.Execute(ctx, actionArgs)
98+
_, _, err = p.CNAB.Execute(ctx, actionArgs)
99+
return err
99100
}
100101
}
101102

102103
// ExecuteRootBundleOnly runs a single bundle that has already had its dependencies resolved by a workflow.
103104
// The workflow is responsible identifying the bundles to run, their order, what to pass between them, etc.
104105
// It is only intended to be used with the deps-v2 feature.
105-
func (p *Porter) ExecuteRootBundleOnly(ctx context.Context, installation storage.Installation, action BundleAction) error {
106+
func (p *Porter) ExecuteRootBundleOnly(ctx context.Context, installation storage.Installation, action BundleAction) (storage.Run, storage.Result, error) {
106107
// Callers should check for a noop action (because the installation is up-to-date, but let's check too just in case
107108
if action == nil {
108-
return nil
109+
return storage.Run{}, storage.Result{}, nil
109110
}
110111

111112
opts := action.GetOptions()
@@ -118,7 +119,7 @@ func (p *Porter) ExecuteRootBundleOnly(ctx context.Context, installation storage
118119

119120
actionArgs, err := p.BuildActionArgs(ctx, installation, action)
120121
if err != nil {
121-
return err
122+
return storage.Run{}, storage.Result{}, err
122123
}
123124

124125
return p.CNAB.Execute(ctx, actionArgs)

pkg/porter/dependencies.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func (e *dependencyExecutioner) executeDependency(ctx context.Context, dep *queu
310310

311311
var executeErrs error
312312
span.Infof("Executing dependency %s...", dep.Alias)
313-
err = e.CNAB.Execute(ctx, depArgs)
313+
_, _, err = e.CNAB.Execute(ctx, depArgs)
314314
if err != nil {
315315
executeErrs = multierror.Append(executeErrs, fmt.Errorf("error executing dependency %s: %w", dep.Alias, err))
316316

pkg/porter/reconcile.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,18 @@ func (p *Porter) ReconcileInstallationAndDependencies(ctx context.Context, opts
5959
// This is only used for install/upgrade actions triggered by applying a file
6060
// to an installation. For uninstall or invoke, you should call those directly.
6161
// This should only be used with deps-v2 feature workflows.
62-
func (p *Porter) ReconcileInstallationInWorkflow(ctx context.Context, opts ReconcileOptions) error {
62+
func (p *Porter) ReconcileInstallationInWorkflow(ctx context.Context, opts ReconcileOptions) (storage.Run, storage.Result, error) {
6363
ctx, span := tracing.StartSpan(ctx)
6464
defer span.EndSpan()
6565

6666
installation, actionOpts, err := p.reconcileInstallation(ctx, opts)
6767
if err != nil {
68-
return err
68+
return storage.Run{}, storage.Result{}, err
6969
}
7070

7171
// Nothing to do, the installation is up-to-date
7272
if actionOpts == nil {
73-
return nil
73+
return storage.Run{}, storage.Result{}, nil
7474
}
7575

7676
return p.ExecuteRootBundleOnly(ctx, installation, actionOpts)

pkg/porter/uninstall.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (p *Porter) UninstallBundle(ctx context.Context, opts UninstallOptions) err
132132
}
133133

134134
log.Infof("%s bundle", opts.GetActionVerb())
135-
err = p.CNAB.Execute(ctx, actionArgs)
135+
_, _, err = p.CNAB.Execute(ctx, actionArgs)
136136

137137
var uninstallErrs error
138138
if err != nil {

pkg/porter/workflow_engine.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,11 @@ func (t Engine) executeJob(ctx context.Context, j *storage.Job, jobs chan *stora
328328
opts := ReconcileOptions{
329329
Installation: j.Installation,
330330
}
331-
err := t.p.ReconcileInstallationInWorkflow(ctx, opts)
331+
run, result, err := t.p.ReconcileInstallationInWorkflow(ctx, opts)
332+
j.Status.LastRunID = run.ID
333+
j.Status.LastResultID = result.ID
334+
j.Status.ResultIDs = append(j.Status.ResultIDs, result.ID)
332335
if err != nil {
333-
// TODO(PEP003): Let's consider the relationship between jobs, runs and results.
334-
// How much should we duplicate on job?
335-
// How do we want to link the job to the run (e.g. should job status include runid or something?)
336336
j.Status.Status = cnab.StatusFailed
337337
j.Status.Message = err.Error()
338338
} else {

pkg/storage/workflow.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,11 @@ func (j *Job) Prepare(workflowId string, jobKey string) {
100100
}
101101

102102
type JobStatus struct {
103-
Status string `json:"status"`
104-
Message string `json:"message"`
103+
LastRunID string `json:lastRunID`
104+
LastResultID string `json:lastResultID`
105+
ResultIDs []string `json:resultIDs`
106+
Status string `json:"status"`
107+
Message string `json:"message"`
105108
}
106109

107110
func (s JobStatus) IsSucceeded() bool {

0 commit comments

Comments
 (0)