-
Notifications
You must be signed in to change notification settings - Fork 213
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
Fix dependencies v1 definition and conversion #2232
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
"get.porter.sh/porter/pkg/manifest" | ||
"get.porter.sh/porter/pkg/mixin" | ||
"get.porter.sh/porter/pkg/tracing" | ||
"github.com/Masterminds/semver/v3" | ||
"github.com/cnabio/cnab-go/bundle" | ||
"github.com/cnabio/cnab-go/bundle/definition" | ||
) | ||
|
@@ -71,7 +72,11 @@ func (c *ManifestConverter) ToBundle(ctx context.Context) (cnab.ExtendedBundle, | |
b.Outputs = c.generateBundleOutputs(ctx, &b.Definitions) | ||
b.Credentials = c.generateBundleCredentials() | ||
b.Images = c.generateBundleImages() | ||
b.Custom = c.generateCustomExtensions(&b) | ||
custom, err := c.generateCustomExtensions(&b) | ||
if err != nil { | ||
return cnab.ExtendedBundle{}, err | ||
} | ||
b.Custom = custom | ||
b.RequiredExtensions = c.generateRequiredExtensions(b) | ||
|
||
b.Custom[config.CustomPorterKey] = stamp | ||
|
@@ -401,10 +406,9 @@ func (c *ManifestConverter) generateBundleImages() map[string]bundle.Image { | |
return images | ||
} | ||
|
||
func (c *ManifestConverter) generateDependencies() *cnab.Dependencies { | ||
|
||
func (c *ManifestConverter) generateDependencies() (*cnab.Dependencies, error) { | ||
if len(c.Manifest.Dependencies.RequiredDependencies) == 0 { | ||
return nil | ||
return nil, nil | ||
} | ||
|
||
deps := &cnab.Dependencies{ | ||
|
@@ -421,12 +425,18 @@ func (c *ManifestConverter) generateDependencies() *cnab.Dependencies { | |
dependencyRef.Version = &cnab.DependencyVersion{ | ||
Ranges: []string{dep.Bundle.Version}, | ||
} | ||
|
||
// If we can detect that prereleases are used in the version, then set AllowPrereleases to true | ||
v, err := semver.NewVersion(dep.Bundle.Version) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we return the error here if it's not nil? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, because we are just parsing the value to see if we can detect the use of a prerelease value. If they are using a semver constrain, the value isn't parsable as a singular version. If we want to validate values from the porter.yaml, it should be in the Manifest.Validate function. In general though we aren't going to do that for deps since not all tags are semver values. |
||
if err == nil { | ||
dependencyRef.Version.AllowPrereleases = v.Prerelease() != "" | ||
} | ||
} | ||
deps.Sequence = append(deps.Sequence, dep.Name) | ||
deps.Requires[dep.Name] = dependencyRef | ||
} | ||
|
||
return deps | ||
return deps, nil | ||
} | ||
|
||
func (c *ManifestConverter) generateParameterSources(b *cnab.ExtendedBundle) cnab.ParameterSources { | ||
|
@@ -576,7 +586,7 @@ func toFloat(v float64) *float64 { | |
return &v | ||
} | ||
|
||
func (c *ManifestConverter) generateCustomExtensions(b *cnab.ExtendedBundle) map[string]interface{} { | ||
func (c *ManifestConverter) generateCustomExtensions(b *cnab.ExtendedBundle) (map[string]interface{}, error) { | ||
customExtensions := map[string]interface{}{ | ||
cnab.FileParameterExtensionKey: struct{}{}, | ||
} | ||
|
@@ -587,7 +597,10 @@ func (c *ManifestConverter) generateCustomExtensions(b *cnab.ExtendedBundle) map | |
} | ||
|
||
// Add the dependency extension | ||
deps := c.generateDependencies() | ||
deps, err := c.generateDependencies() | ||
if err != nil { | ||
return nil, err | ||
} | ||
if deps != nil && len(deps.Requires) > 0 { | ||
customExtensions[cnab.DependenciesExtensionKey] = deps | ||
} | ||
|
@@ -603,7 +616,7 @@ func (c *ManifestConverter) generateCustomExtensions(b *cnab.ExtendedBundle) map | |
customExtensions[lookupExtensionKey(ext.Name)] = ext.Config | ||
} | ||
|
||
return customExtensions | ||
return customExtensions, nil | ||
} | ||
|
||
func (c *ManifestConverter) generateRequiredExtensions(b cnab.ExtendedBundle) []string { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'm missing something, I can't find where this function is returning an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry the I was chopping up #2099 into refactorings and while that larger PR needs to return an error this exact change here doesn't use it yet. Are you okay with me keeping that in place here so that I don't need to redo both PRs to shuffle when we introduce that change? I promise we will be returning errors by the time I finish splitting up that big PR. 😀