Skip to content

Commit

Permalink
I saw testworkflow pass
Browse files Browse the repository at this point in the history
Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
  • Loading branch information
carolynvs committed Oct 24, 2022
1 parent 55d2f23 commit 03d23e4
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 101 deletions.
1 change: 1 addition & 0 deletions pkg/cnab/dependencies/v2/composite_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func (r CompositeResolver) addBundleToGraph(ctx context.Context, g *BundleGraph,

outputRequires := node.Key
if source.Dependency != "" {
// PEP(003): How do we ensure that these keys are unique in deep graphs where root + current dep key is unique?
outputRequires = MakeDependencyKey(node.Key, source.Dependency)
}
depNode.Requires = append(depNode.Requires, outputRequires)
Expand Down
8 changes: 4 additions & 4 deletions pkg/porter/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
"get.porter.sh/porter/pkg/storage"
)

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

Expand Down Expand Up @@ -94,10 +94,10 @@ func (p *Porter) ExecuteRootBundleAndDependencies(ctx context.Context, installat
}
}

// ExecuteBundleFromWorkflow runs a single bundle that has already had its dependencies resolved by a workflow.
// ExecuteRootBundleOnly runs a single bundle that has already had its dependencies resolved by a workflow.
// The workflow is responsible identifying the bundles to run, their order, what to pass between them, etc.
// It is only intended to be used with the deps-v2 feature.
func (p *Porter) ExecuteBundleFromWorkflow(ctx context.Context, installation storage.Installation, action BundleAction) error {
func (p *Porter) ExecuteRootBundleOnly(ctx context.Context, installation storage.Installation, action BundleAction) error {
opts := action.GetOptions()
ctx, span := tracing.StartSpan(ctx,
tracing.ObjectAttribute("installation", installation),
Expand Down
2 changes: 1 addition & 1 deletion pkg/porter/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (p *Porter) InstallBundle(ctx context.Context, opts InstallOptions) error {
}

// Run install using the updated installation record
return p.ExecuteRootBundleAndDependencies(ctx, i, opts)
return p.ExecuteBundleAndDependencies(ctx, i, opts)
}

// useWorkflowEngine determines if the new workflow engine or the old bundle execution code should be used.
Expand Down
2 changes: 1 addition & 1 deletion pkg/porter/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@ func (p *Porter) InvokeBundle(ctx context.Context, opts InvokeOptions) error {
return eng.RunWorkflow(ctx, w)
}

return p.ExecuteRootBundleAndDependencies(ctx, installation, opts)
return p.ExecuteBundleAndDependencies(ctx, installation, opts)
}
4 changes: 2 additions & 2 deletions pkg/porter/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (p *Porter) ReconcileInstallationAndDependencies(ctx context.Context, opts
return err
}

return p.ExecuteRootBundleAndDependencies(ctx, installation, actionOpts)
return p.ExecuteBundleAndDependencies(ctx, installation, actionOpts)
}

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

return p.ExecuteBundleFromWorkflow(ctx, installation, actionOpts)
return p.ExecuteRootBundleOnly(ctx, installation, actionOpts)
}

func (p *Porter) reconcileInstallation(ctx context.Context, opts ReconcileOptions) (storage.Installation, BundleAction, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/porter/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,5 @@ func (p *Porter) UpgradeBundle(ctx context.Context, opts *UpgradeOptions) error
return err
}

return p.ExecuteRootBundleAndDependencies(ctx, i, opts)
return p.ExecuteBundleAndDependencies(ctx, i, opts)
}
7 changes: 5 additions & 2 deletions pkg/porter/workflow_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"runtime"
"strings"

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

// Populate the dependency's credentials from the wiring
Expand Down
5 changes: 4 additions & 1 deletion pkg/storage/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ type Workflow struct {
ID string `json:"id"`

WorkflowSpec `json:"spec"`
Status WorkflowStatus `json:"status"`

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

type WorkflowSpec struct {
Expand Down
142 changes: 55 additions & 87 deletions tests/integration/testdata/workflow/mybuns.yaml
Original file line number Diff line number Diff line change
@@ -1,108 +1,76 @@
stages:
- jobs:
root:
id: ""
key: ""
action: install
installation:
schemaversion: 1.0.2
id: 01GG5FKRE1ZJJVHBJ1XFFTX1P7
installationspec:
name: mybuns
name: mybuns
namespace: dev
uninstalled: false
bundle:
repository: localhost:5000/mybuns
version: v0.1.2
custom: null
labels:
generator: porter-operator
generatorVersion: v0.2.0
thing: "1"
credentialsets:
- mybuns
credentials:
schemaVersion: ""
namespace: ""
name: ""
credentials: []
parametersets:
- mybuns
parameters:
schemaVersion: 1.0.1
namespace: dev
uninstalled: false
bundle:
repository: localhost:5000/mybuns
version: v0.1.2
custom: null
labels:
generator: porter-operator
generatorVersion: v0.2.0
thing: "1"
credentialsets:
- mybuns
credentials:
schemaVersion: ""
namespace: ""
name: ""
credentials: []
parametersets:
- mybuns
name: internal-parameter-set-01GG5VKAA5VS24CGRGSPY09DDX
parameters:
schemaVersion: 1.0.1
namespace: dev
name: internal-parameter-set-01GG5FKRE1ZJJVHBJ1XFFTX1P7
parameters:
- name: password
source:
secret: 01GG5FKRE1ZJJVHBJ1XFFTX1P7-password
status:
created: 2022-10-24T12:10:59.304959-05:00
modified: 2022-10-24T12:10:59.304959-05:00
status:
runId: ""
action: ""
resultId: ""
resultStatus: ""
created: 2022-10-24T12:10:59.26521-05:00
modified: 2022-10-24T12:10:59.26521-05:00
installed: null
uninstalled: null
bundleReference: ""
bundleVersion: ""
bundleDigest: ""
- name: password
source:
secret: 01GG5VKAA5VS24CGRGSPY09DDX-password
status:
created: 2022-10-24T15:40:27.757926-05:00
modified: 2022-10-24T15:40:27.757926-05:00
depends:
- root/db
status:
status: ""
message: ""
root/db:
id: ""
key: ""
action: install
installation:
schemaversion: 1.0.2
id: 01GG5FKRFHB2GCF6ZJ06HJZZKW
installationspec:
name: root/db
namespace: dev
uninstalled: false
bundle:
repository: localhost:5000/mydb
version: 0.1.0
tag: v0.1.0
custom: null
labels: {}
credentialsets: []
credentials:
schemaVersion: 1.0.1
namespace: ""
name: ""
credentials: []
parametersets: []
name: mybuns/db
namespace: dev
uninstalled: false
bundle:
repository: localhost:5000/mydb
version: 0.1.0
tag: v0.1.0
custom: null
labels: {}
credentialsets: []
credentials:
schemaVersion: 1.0.1
namespace: ""
name: ""
credentials: []
parametersets: []
parameters:
schemaVersion: 1.0.1
namespace: ""
name: ""
parameters:
schemaVersion: 1.0.1
namespace: dev
name: internal-parameter-set-root/db
parameters:
- name: database
source:
porter: workflow.jobs.root.bigdb
status:
created: 2022-10-24T12:10:59.313898-05:00
modified: 2022-10-24T12:10:59.313898-05:00
status:
runId: ""
action: ""
resultId: ""
resultStatus: ""
created: 2022-10-24T12:10:59.313896-05:00
modified: 2022-10-24T12:10:59.313896-05:00
installed: null
uninstalled: null
bundleReference: ""
bundleVersion: ""
bundleDigest: ""
- name: database
source:
porter: workflow.jobs.root.bigdb
status:
created: 0001-01-01T00:00:00Z
modified: 0001-01-01T00:00:00Z
depends: []
status:
status: ""
Expand Down
19 changes: 17 additions & 2 deletions tests/integration/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,22 @@ func TestWorkflow(t *testing.T) {

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

workflowContents, stderr := test.RequirePorter("installation", "apply", "mybuns.yaml", "--output=yaml", "--dry-run")
// First validate the plan for the workflow
// 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"
workflowContents, output := test.RequirePorter("installation", "apply", "mybuns.yaml", "--output=yaml", "--dry-run")
fmt.Println(output)
testhelpers.CompareGoldenFile(t, "testdata/workflow/mybuns.yaml", workflowContents)
fmt.Println(stderr)

// Run the workflow
_, output = test.RequirePorter("installation", "apply", "mybuns.yaml")
fmt.Println(output)

// TODO A workflow should be persisted, and it should match the execution plan generated first with --dry-run

// We should have 2 installations, mybuns and mydb
test.RequireInstallationExists(test.CurrentNamespace(), "mybuns")
test.RequireInstallationExists(test.CurrentNamespace(), "mybuns/db")

// TODO mydb should have a parameter that was set by the workflow, e.g. the db name
// 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
}

0 comments on commit 03d23e4

Please sign in to comment.