Skip to content

Commit 03d23e4

Browse files
committed
I saw testworkflow pass
Signed-off-by: Carolyn Van Slyck <[email protected]>
1 parent 55d2f23 commit 03d23e4

File tree

10 files changed

+91
-101
lines changed

10 files changed

+91
-101
lines changed

pkg/cnab/dependencies/v2/composite_resolver.go

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ func (r CompositeResolver) addBundleToGraph(ctx context.Context, g *BundleGraph,
122122

123123
outputRequires := node.Key
124124
if source.Dependency != "" {
125+
// PEP(003): How do we ensure that these keys are unique in deep graphs where root + current dep key is unique?
125126
outputRequires = MakeDependencyKey(node.Key, source.Dependency)
126127
}
127128
depNode.Requires = append(depNode.Requires, outputRequires)

pkg/porter/action.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import (
1313
"get.porter.sh/porter/pkg/storage"
1414
)
1515

16-
// ExecuteRootBundleAndDependencies runs a specified action for a root bundle.
16+
// ExecuteBundleAndDependencies runs a specified action for a root bundle.
1717
// The bundle should be a root bundle, and if there are dependencies, they will also be executed as appropriate.
1818
// Supported actions are: install, upgrade, invoke.
1919
// The uninstall action works in reverse, so it's implemented separately.
2020
// Dependencies are resolved and executed differently depending on whether the deps-v2 feature is enabled (workflow).
21-
func (p *Porter) ExecuteRootBundleAndDependencies(ctx context.Context, installation storage.Installation, action BundleAction) error {
21+
func (p *Porter) ExecuteBundleAndDependencies(ctx context.Context, installation storage.Installation, action BundleAction) error {
2222
opts := action.GetOptions()
2323
bundleRef := opts.bundleRef
2424

@@ -94,10 +94,10 @@ func (p *Porter) ExecuteRootBundleAndDependencies(ctx context.Context, installat
9494
}
9595
}
9696

97-
// ExecuteBundleFromWorkflow runs a single bundle that has already had its dependencies resolved by a workflow.
97+
// ExecuteRootBundleOnly runs a single bundle that has already had its dependencies resolved by a workflow.
9898
// The workflow is responsible identifying the bundles to run, their order, what to pass between them, etc.
9999
// It is only intended to be used with the deps-v2 feature.
100-
func (p *Porter) ExecuteBundleFromWorkflow(ctx context.Context, installation storage.Installation, action BundleAction) error {
100+
func (p *Porter) ExecuteRootBundleOnly(ctx context.Context, installation storage.Installation, action BundleAction) error {
101101
opts := action.GetOptions()
102102
ctx, span := tracing.StartSpan(ctx,
103103
tracing.ObjectAttribute("installation", installation),

pkg/porter/install.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (p *Porter) InstallBundle(ctx context.Context, opts InstallOptions) error {
120120
}
121121

122122
// Run install using the updated installation record
123-
return p.ExecuteRootBundleAndDependencies(ctx, i, opts)
123+
return p.ExecuteBundleAndDependencies(ctx, i, opts)
124124
}
125125

126126
// useWorkflowEngine determines if the new workflow engine or the old bundle execution code should be used.

pkg/porter/invoke.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,5 @@ func (p *Porter) InvokeBundle(ctx context.Context, opts InvokeOptions) error {
9494
return eng.RunWorkflow(ctx, w)
9595
}
9696

97-
return p.ExecuteRootBundleAndDependencies(ctx, installation, opts)
97+
return p.ExecuteBundleAndDependencies(ctx, installation, opts)
9898
}

pkg/porter/reconcile.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (p *Porter) ReconcileInstallationAndDependencies(ctx context.Context, opts
4949
return err
5050
}
5151

52-
return p.ExecuteRootBundleAndDependencies(ctx, installation, actionOpts)
52+
return p.ExecuteBundleAndDependencies(ctx, installation, actionOpts)
5353
}
5454

5555
// ReconcileInstallationInWorkflow compares the desired state of an installation
@@ -68,7 +68,7 @@ func (p *Porter) ReconcileInstallationInWorkflow(ctx context.Context, opts Recon
6868
return err
6969
}
7070

71-
return p.ExecuteBundleFromWorkflow(ctx, installation, actionOpts)
71+
return p.ExecuteRootBundleOnly(ctx, installation, actionOpts)
7272
}
7373

7474
func (p *Porter) reconcileInstallation(ctx context.Context, opts ReconcileOptions) (storage.Installation, BundleAction, error) {

pkg/porter/upgrade.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,5 @@ func (p *Porter) UpgradeBundle(ctx context.Context, opts *UpgradeOptions) error
123123
return err
124124
}
125125

126-
return p.ExecuteRootBundleAndDependencies(ctx, i, opts)
126+
return p.ExecuteBundleAndDependencies(ctx, i, opts)
127127
}

pkg/porter/workflow_engine.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"runtime"
7+
"strings"
78

89
"get.porter.sh/porter/pkg/cnab"
910
depsv2 "get.porter.sh/porter/pkg/cnab/dependencies/v2"
@@ -83,8 +84,10 @@ func (t Engine) CreateWorkflow(ctx context.Context, opts CreateWorkflowOptions)
8384
// I think we discussed this in a meeting? go look for notes or suggestions
8485
inst = storage.InstallationSpec{
8586
Namespace: t.namespace,
86-
Name: tn.Key,
87-
Bundle: storage.NewOCIReferenceParts(tn.Reference.Reference),
87+
// TODO(PEP003): can we fix the key so that it uses something real from the installation and not root for the root key name?
88+
Name: strings.Replace(tn.Key, "root/", opts.Installation.Name+"/", 1),
89+
Bundle: storage.NewOCIReferenceParts(tn.Reference.Reference),
90+
// PEP(003): Add labels so that we know who is the parent installation
8891
}
8992

9093
// Populate the dependency's credentials from the wiring

pkg/storage/workflow.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ type Workflow struct {
1414
ID string `json:"id"`
1515

1616
WorkflowSpec `json:"spec"`
17-
Status WorkflowStatus `json:"status"`
17+
18+
// TODO(PEP003): When we wrap this in a DisplayWorkflow, override marshal so that we don't marshal an ID or status when empty
19+
// i.e. if we do a dry run, we shouldn't get out an empty id or status
20+
Status WorkflowStatus `json:"status"`
1821
}
1922

2023
type WorkflowSpec struct {

tests/integration/testdata/workflow/mybuns.yaml

+55-87
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,76 @@
11
stages:
22
- jobs:
33
root:
4-
id: ""
54
key: ""
65
action: install
76
installation:
8-
schemaversion: 1.0.2
9-
id: 01GG5FKRE1ZJJVHBJ1XFFTX1P7
10-
installationspec:
11-
name: mybuns
7+
name: mybuns
8+
namespace: dev
9+
uninstalled: false
10+
bundle:
11+
repository: localhost:5000/mybuns
12+
version: v0.1.2
13+
custom: null
14+
labels:
15+
generator: porter-operator
16+
generatorVersion: v0.2.0
17+
thing: "1"
18+
credentialsets:
19+
- mybuns
20+
credentials:
21+
schemaVersion: ""
22+
namespace: ""
23+
name: ""
24+
credentials: []
25+
parametersets:
26+
- mybuns
27+
parameters:
28+
schemaVersion: 1.0.1
1229
namespace: dev
13-
uninstalled: false
14-
bundle:
15-
repository: localhost:5000/mybuns
16-
version: v0.1.2
17-
custom: null
18-
labels:
19-
generator: porter-operator
20-
generatorVersion: v0.2.0
21-
thing: "1"
22-
credentialsets:
23-
- mybuns
24-
credentials:
25-
schemaVersion: ""
26-
namespace: ""
27-
name: ""
28-
credentials: []
29-
parametersets:
30-
- mybuns
30+
name: internal-parameter-set-01GG5VKAA5VS24CGRGSPY09DDX
3131
parameters:
32-
schemaVersion: 1.0.1
33-
namespace: dev
34-
name: internal-parameter-set-01GG5FKRE1ZJJVHBJ1XFFTX1P7
35-
parameters:
36-
- name: password
37-
source:
38-
secret: 01GG5FKRE1ZJJVHBJ1XFFTX1P7-password
39-
status:
40-
created: 2022-10-24T12:10:59.304959-05:00
41-
modified: 2022-10-24T12:10:59.304959-05:00
42-
status:
43-
runId: ""
44-
action: ""
45-
resultId: ""
46-
resultStatus: ""
47-
created: 2022-10-24T12:10:59.26521-05:00
48-
modified: 2022-10-24T12:10:59.26521-05:00
49-
installed: null
50-
uninstalled: null
51-
bundleReference: ""
52-
bundleVersion: ""
53-
bundleDigest: ""
32+
- name: password
33+
source:
34+
secret: 01GG5VKAA5VS24CGRGSPY09DDX-password
35+
status:
36+
created: 2022-10-24T15:40:27.757926-05:00
37+
modified: 2022-10-24T15:40:27.757926-05:00
5438
depends:
5539
- root/db
5640
status:
5741
status: ""
5842
message: ""
5943
root/db:
60-
id: ""
6144
key: ""
6245
action: install
6346
installation:
64-
schemaversion: 1.0.2
65-
id: 01GG5FKRFHB2GCF6ZJ06HJZZKW
66-
installationspec:
67-
name: root/db
68-
namespace: dev
69-
uninstalled: false
70-
bundle:
71-
repository: localhost:5000/mydb
72-
version: 0.1.0
73-
tag: v0.1.0
74-
custom: null
75-
labels: {}
76-
credentialsets: []
77-
credentials:
78-
schemaVersion: 1.0.1
79-
namespace: ""
80-
name: ""
81-
credentials: []
82-
parametersets: []
47+
name: mybuns/db
48+
namespace: dev
49+
uninstalled: false
50+
bundle:
51+
repository: localhost:5000/mydb
52+
version: 0.1.0
53+
tag: v0.1.0
54+
custom: null
55+
labels: {}
56+
credentialsets: []
57+
credentials:
58+
schemaVersion: 1.0.1
59+
namespace: ""
60+
name: ""
61+
credentials: []
62+
parametersets: []
63+
parameters:
64+
schemaVersion: 1.0.1
65+
namespace: ""
66+
name: ""
8367
parameters:
84-
schemaVersion: 1.0.1
85-
namespace: dev
86-
name: internal-parameter-set-root/db
87-
parameters:
88-
- name: database
89-
source:
90-
porter: workflow.jobs.root.bigdb
91-
status:
92-
created: 2022-10-24T12:10:59.313898-05:00
93-
modified: 2022-10-24T12:10:59.313898-05:00
94-
status:
95-
runId: ""
96-
action: ""
97-
resultId: ""
98-
resultStatus: ""
99-
created: 2022-10-24T12:10:59.313896-05:00
100-
modified: 2022-10-24T12:10:59.313896-05:00
101-
installed: null
102-
uninstalled: null
103-
bundleReference: ""
104-
bundleVersion: ""
105-
bundleDigest: ""
68+
- name: database
69+
source:
70+
porter: workflow.jobs.root.bigdb
71+
status:
72+
created: 0001-01-01T00:00:00Z
73+
modified: 0001-01-01T00:00:00Z
10674
depends: []
10775
status:
10876
status: ""

tests/integration/workflow_test.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,22 @@ func TestWorkflow(t *testing.T) {
1919

2020
test.TestContext.AddTestFileFromRoot("tests/testdata/installations/mybuns.yaml", "mybuns.yaml")
2121

22-
workflowContents, stderr := test.RequirePorter("installation", "apply", "mybuns.yaml", "--output=yaml", "--dry-run")
22+
// First validate the plan for the workflow
23+
// TODO(PEP003): Do we want to use different terms/commands for generating a workflow? This pretty much associates --dry-run with "print out your workflow"
24+
workflowContents, output := test.RequirePorter("installation", "apply", "mybuns.yaml", "--output=yaml", "--dry-run")
25+
fmt.Println(output)
2326
testhelpers.CompareGoldenFile(t, "testdata/workflow/mybuns.yaml", workflowContents)
24-
fmt.Println(stderr)
27+
28+
// Run the workflow
29+
_, output = test.RequirePorter("installation", "apply", "mybuns.yaml")
30+
fmt.Println(output)
31+
32+
// TODO A workflow should be persisted, and it should match the execution plan generated first with --dry-run
33+
34+
// We should have 2 installations, mybuns and mydb
35+
test.RequireInstallationExists(test.CurrentNamespace(), "mybuns")
36+
test.RequireInstallationExists(test.CurrentNamespace(), "mybuns/db")
37+
38+
// TODO mydb should have a parameter that was set by the workflow, e.g. the db name
39+
// TODO mybuns should have used an output from mydb that we saved as a root bundle output so that we can validate that it was used properly
2540
}

0 commit comments

Comments
 (0)