Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependencies V2 Playground #2099

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d3d11c9
Convert a depsv2 porter.yaml into bundle.json
carolynvs Aug 31, 2022
9b1a5e5
Remove name field from CNAB dependency representation in bundle.json
carolynvs Feb 5, 2023
ad6f58b
Consolidate testdata so we don't have a bunch of similar bundles
carolynvs Feb 2, 2023
d476874
wip: stub structs and logic for a bundle workflow
carolynvs Sep 11, 2022
8610bfa
wip
carolynvs Dec 24, 2022
701d725
wip: test passes with stuff commented out because dry-run prints the …
carolynvs Dec 24, 2022
54251e3
yes we should inject dependency defs into a bundle
carolynvs Feb 12, 2023
aae9178
Manually hydrate deps name in cnab representation of depsv2
carolynvs Feb 12, 2023
a9702df
make vet and lint happy
carolynvs Feb 12, 2023
1424fad
Fix schema test to work with beefier mybuns testdata
carolynvs Feb 12, 2023
2d33418
HACK: DO NOT MERGE: Optionally load bundle dependency.json until we f…
carolynvs Feb 12, 2023
44f76d7
laptop sync
carolynvs Feb 13, 2023
4e111db
wip: made better testdata but now I want the workflow dump to look right
carolynvs Feb 15, 2023
cdeede0
Add DisplayWorkflow structure
carolynvs Feb 15, 2023
6449cd9
laptop sync
carolynvs Feb 16, 2023
f16161d
do not keep without editing
carolynvs Feb 16, 2023
74a2381
Add imported workflow testdata
carolynvs Feb 22, 2023
bbfd048
laptop sync
carolynvs Feb 24, 2023
d95a8f6
Fix display workflow tests to use stable data
carolynvs Feb 28, 2023
b5988e3
this commit will go away when I rebase on depsv2 because the test dat…
carolynvs Feb 28, 2023
4271af3
wip
carolynvs Mar 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/porter/installations.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ You can use the show command to create the initial file:
"Force the bundle to be executed when no changes are detected.")
f.BoolVar(&opts.DryRun, "dry-run", false,
"Evaluate if the bundle would be executed based on the changes in the file.")
f.StringVarP(&opts.RawFormat, "output", "o", "plaintext",
"Specify an output format. Allowed values: plaintext, json, yaml")

return &cmd
}

Expand Down
1 change: 1 addition & 0 deletions docs/content/cli/installations_apply.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ porter installations apply FILE [flags]
--force Force the bundle to be executed when no changes are detected.
-h, --help help for apply
-n, --namespace string Namespace in which the installation is defined. Defaults to the namespace defined in the file.
-o, --output string Specify an output format. Allowed values: plaintext, json, yaml (default "plaintext")
```

### Options inherited from parent commands
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ require (
github.com/spf13/viper v1.14.0
github.com/stretchr/testify v1.8.1
github.com/xeipuuv/gojsonschema v1.2.0
github.com/yourbasic/graph v0.0.0-20210606180040-8ecfec1c2869
go.mongodb.org/mongo-driver v1.11.1
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.37.0
go.opentelemetry.io/otel v1.12.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,8 @@ github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMx
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
github.com/yourbasic/graph v0.0.0-20210606180040-8ecfec1c2869 h1:7v7L5lsfw4w8iqBBXETukHo4IPltmD+mWoLRYUmeGN8=
github.com/yourbasic/graph v0.0.0-20210606180040-8ecfec1c2869/go.mod h1:Rfzr+sqaDreiCaoQbFCu3sTXxeFq/9kXRuyOoSlGQHE=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
4 changes: 4 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func BuildPorter() {
mgx.Must(releases.BuildAll(PKG, "porter", "bin"))
}

func RestartRegistry() {
mgx.Must(docker.RestartDockerRegistry())
}

func copySchema() {
// Copy the porter manifest schema into our templates directory with the other schema
// We can't use symbolic links because that doesn't work on windows
Expand Down
File renamed without changes.
File renamed without changes.
93 changes: 81 additions & 12 deletions pkg/cnab/config-adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
"strings"

"get.porter.sh/porter/pkg/cnab"
depsv1 "get.porter.sh/porter/pkg/cnab/dependencies/v1"
depsv1ext "get.porter.sh/porter/pkg/cnab/extensions/dependencies/v1"
depsv2ext "get.porter.sh/porter/pkg/cnab/extensions/dependencies/v2"
"get.porter.sh/porter/pkg/config"
"get.porter.sh/porter/pkg/experimental"
"get.porter.sh/porter/pkg/manifest"
Expand Down Expand Up @@ -414,33 +415,33 @@ func (c *ManifestConverter) generateDependencies() (interface{}, string, error)

// Check if they are using v1 of the dependencies spec or v2
if c.config.IsFeatureEnabled(experimental.FlagDependenciesV2) {
panic("the dependencies-v2 experimental flag was specified but is not yet implemented")
// Ok we are using v2!
deps, err := c.generateDependenciesV2()
return deps, cnab.DependenciesV2ExtensionKey, err
}

deps, err := c.generateDependenciesV1()
if err != nil {
return nil, "", err
}
// Default to using v1 of deps
deps := c.generateDependenciesV1()
return deps, cnab.DependenciesV1ExtensionKey, nil
}

func (c *ManifestConverter) generateDependenciesV1() (*depsv1.Dependencies, error) {
func (c *ManifestConverter) generateDependenciesV1() *depsv1ext.Dependencies {
if len(c.Manifest.Dependencies.Requires) == 0 {
return nil, nil
return nil
}

deps := &depsv1.Dependencies{
deps := &depsv1ext.Dependencies{
Sequence: make([]string, 0, len(c.Manifest.Dependencies.Requires)),
Requires: make(map[string]depsv1.Dependency, len(c.Manifest.Dependencies.Requires)),
Requires: make(map[string]depsv1ext.Dependency, len(c.Manifest.Dependencies.Requires)),
}

for _, dep := range c.Manifest.Dependencies.Requires {
dependencyRef := depsv1.Dependency{
dependencyRef := depsv1ext.Dependency{
Name: dep.Name,
Bundle: dep.Bundle.Reference,
}
if len(dep.Bundle.Version) > 0 {
dependencyRef.Version = &depsv1.DependencyVersion{
dependencyRef.Version = &depsv1ext.DependencyVersion{
Ranges: []string{dep.Bundle.Version},
}

Expand All @@ -454,6 +455,72 @@ func (c *ManifestConverter) generateDependenciesV1() (*depsv1.Dependencies, erro
deps.Requires[dep.Name] = dependencyRef
}

return deps
}

func (c *ManifestConverter) generateDependenciesV2() (*depsv2ext.Dependencies, error) {
deps := &depsv2ext.Dependencies{
Requires: make(map[string]depsv2ext.Dependency, len(c.Manifest.Dependencies.Requires)),
}

for _, dep := range c.Manifest.Dependencies.Requires {
dependencyRef := depsv2ext.Dependency{
Name: dep.Name,
Bundle: dep.Bundle.Reference,
Version: dep.Bundle.Version,
}

if dep.Bundle.Interface != nil {
if dep.Bundle.Interface.Reference != "" {
dependencyRef.Interface.Reference = dep.Bundle.Interface.Reference
}
// Porter doesn't let you embed a random bundle.json document into your porter.yaml
// While the CNAB spec lets the document be anything, we constrain the interface to a porter representation of the bundle's parameters, credentials and outputs.
if dep.Bundle.Interface.Document != nil {
// TODO(PEP003): Convert the parameters, credentials and outputs defined on manifest.BundleInterfaceDocument and create an (incomplete) bundle.json from it
// See https://github.com/getporter/porter/issues/2548
panic("conversion of an embedded bundle interface document for a dependency is not implemented")
}
}

if dep.Installation != nil {
dependencyRef.Installation = &depsv2ext.DependencyInstallation{
Labels: dep.Installation.Labels,
}
if dep.Installation.Criteria != nil {
dependencyRef.Installation.Criteria = &depsv2ext.InstallationCriteria{
MatchInterface: dep.Installation.Criteria.MatchInterface,
MatchNamespace: dep.Installation.Criteria.MatchNamespace,
IgnoreLabels: dep.Installation.Criteria.IgnoreLabels,
}
}
}

if len(dep.Parameters) > 0 {
dependencyRef.Parameters = make(map[string]depsv2ext.DependencySource, len(dep.Parameters))
for param, source := range dep.Parameters {
ds, err := depsv2ext.ParseDependencySource(source)
if err != nil {
return nil, fmt.Errorf("invalid parameter wiring specified for dependency %s: %w", dep.Name, err)
}
dependencyRef.Parameters[param] = ds
}
}

if len(dep.Credentials) > 0 {
dependencyRef.Credentials = make(map[string]depsv2ext.DependencySource, len(dep.Credentials))
for cred, source := range dep.Credentials {
ds, err := depsv2ext.ParseDependencySource(source)
if err != nil {
return nil, fmt.Errorf("invalid credential wiring specified for dependency %s: %w", dep.Name, err)
}
dependencyRef.Credentials[cred] = ds
}
}

deps.Requires[dep.Name] = dependencyRef
}

return deps, nil
}

Expand Down Expand Up @@ -643,6 +710,8 @@ func (c *ManifestConverter) generateRequiredExtensions(b cnab.ExtendedBundle) []
// Add the appropriate dependencies key if applicable
if b.HasDependenciesV1() {
requiredExtensions = append(requiredExtensions, cnab.DependenciesV1ExtensionKey)
} else if b.HasDependenciesV2() {
requiredExtensions = append(requiredExtensions, cnab.DependenciesV2ExtensionKey)
}

// Add the appropriate parameter sources key if applicable
Expand Down
Loading