Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Update cnab-go to v0.3.0-beta1
Browse files Browse the repository at this point in the history
Signed-off-by: Radu M <root@radu.sh>
  • Loading branch information
Radu M authored and glyn committed Aug 12, 2019
1 parent b464875 commit 38d7e6e
Show file tree
Hide file tree
Showing 28 changed files with 473 additions and 254 deletions.
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Expand Up @@ -57,7 +57,7 @@

[[constraint]]
name = "github.com/deislabs/cnab-go"
version = "v0.2.1-beta1"
version = "v0.3.0-beta1"

[[override]]
name = "github.com/google/go-containerregistry"
Expand Down
11 changes: 4 additions & 7 deletions cmd/duffle/install.go
Expand Up @@ -142,7 +142,7 @@ func (i *installCmd) run() error {
c.Bundle = bun
// calculateParamValues determines if values can be changed in later actions, but we don't have
// previous values so install passes nil.
c.Parameters, err = calculateParamValues(bun, i.valuesFile, i.setParams, i.setFiles, nil)
c.Parameters, err = calculateParamValues(bun, i.valuesFile, i.setParams, i.setFiles)
if err != nil {
return err
}
Expand Down Expand Up @@ -229,10 +229,7 @@ func parseValues(file string) (map[string]interface{}, error) {
return vals, nil
}

func calculateParamValues(bun *bundle.Bundle, valuesFile string, setParams, setFilePaths []string, prevVals map[string]interface{}) (map[string]interface{}, error) {
if prevVals == nil {
prevVals = map[string]interface{}{}
}
func calculateParamValues(bun *bundle.Bundle, valuesFile string, setParams, setFilePaths []string) (map[string]interface{}, error) {
vals := map[string]interface{}{}
if valuesFile != "" {
var err error
Expand All @@ -258,7 +255,7 @@ func calculateParamValues(bun *bundle.Bundle, valuesFile string, setParams, setF
}

// Check that this is a known param
if _, ok := bun.Parameters.Fields[parts[0]]; !ok {
if _, ok := bun.Parameters[parts[0]]; !ok {
return vals, fmt.Errorf("bundle does not have a parameter named %q", parts[0])
}

Expand All @@ -272,5 +269,5 @@ func calculateParamValues(bun *bundle.Bundle, valuesFile string, setParams, setF
vals[parts[0]] = string(content)
}

return bundle.ValuesOrDefaults(vals, prevVals, bun)
return bundle.ValuesOrDefaults(vals, bun)
}
4 changes: 2 additions & 2 deletions cmd/duffle/main.go
Expand Up @@ -143,15 +143,15 @@ type driverWithRelocationMapping struct {
relMapping string
}

func (d *driverWithRelocationMapping) Run(op *driver.Operation) error {
func (d *driverWithRelocationMapping) Run(op *driver.Operation) (driver.OperationResult, error) {
// if there is a relocation mapping, ensure it is mounted and relocate the invocation image
if d.relMapping != "" {
op.Files["/cnab/app/relocation-mapping.json"] = d.relMapping

var err error
op.Image, err = d.relocateImage(op.Image)
if err != nil {
return err
return driver.OperationResult{}, err
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/duffle/run.go
Expand Up @@ -68,7 +68,7 @@ Credentials and parameters may be passed to the bundle during a target action.

// Override parameters only if some are set.
if valuesFile != "" || len(setParams) > 0 {
c.Parameters, err = calculateParamValues(c.Bundle, valuesFile, setParams, setFiles, c.Parameters)
c.Parameters, err = calculateParamValues(c.Bundle, valuesFile, setParams, setFiles)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/duffle/uninstall.go
Expand Up @@ -89,7 +89,7 @@ func (un *uninstallCmd) run() error {
if claim.Bundle == nil {
return errors.New("parameters can only be set if a bundle is provided")
}
params, err := calculateParamValues(claim.Bundle, un.valuesFile, un.setParams, []string{}, claim.Parameters)
params, err := calculateParamValues(claim.Bundle, un.valuesFile, un.setParams, []string{})
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/duffle/upgrade.go
Expand Up @@ -109,7 +109,7 @@ func (up *upgradeCmd) run() error {

// Override parameters only if some are set.
if up.valuesFile != "" || len(up.setParams) > 0 {
claim.Parameters, err = calculateParamValues(claim.Bundle, up.valuesFile, up.setParams, up.setFiles, claim.Parameters)
claim.Parameters, err = calculateParamValues(claim.Bundle, up.valuesFile, up.setParams, up.setFiles)
if err != nil {
return err
}
Expand Down
28 changes: 15 additions & 13 deletions pkg/builder/builder.go
Expand Up @@ -67,19 +67,21 @@ func (b *Builder) PrepareBuild(bldr *Builder, mfst *manifest.Manifest, appDir st
}

bf := &bundle.Bundle{
Actions: ctx.Manifest.Actions,
Credentials: ctx.Manifest.Credentials,
Custom: ctx.Manifest.Custom,
Definitions: ctx.Manifest.Definitions,
Description: ctx.Manifest.Description,
Images: ctx.Manifest.Images,
Keywords: ctx.Manifest.Keywords,
Maintainers: ctx.Manifest.Maintainers,
Name: ctx.Manifest.Name,
Outputs: ctx.Manifest.Outputs,
Parameters: ctx.Manifest.Parameters,
SchemaVersion: ctx.Manifest.SchemaVersion,
Version: ctx.Manifest.Version,
Actions: ctx.Manifest.Actions,
Credentials: ctx.Manifest.Credentials,
Custom: ctx.Manifest.Custom,
Definitions: ctx.Manifest.Definitions,
Description: ctx.Manifest.Description,
Images: ctx.Manifest.Images,
Keywords: ctx.Manifest.Keywords,
License: ctx.Manifest.License,
Maintainers: ctx.Manifest.Maintainers,
Name: ctx.Manifest.Name,
Outputs: ctx.Manifest.Outputs,
Parameters: ctx.Manifest.Parameters,
RequiredExtensions: ctx.Manifest.RequiredExtensions,
SchemaVersion: ctx.Manifest.SchemaVersion,
Version: ctx.Manifest.Version,
}

for _, imb := range imageBuilders {
Expand Down
31 changes: 20 additions & 11 deletions pkg/builder/builder_test.go
Expand Up @@ -52,12 +52,9 @@ func (tc testImage) Build(ctx context.Context, log io.WriteCloser) error {
}

func TestPrepareBuild(t *testing.T) {
outputs := &bundle.OutputsDefinition{
Fields: map[string]bundle.OutputDefinition{"output1": {}},
}
params := &bundle.ParametersDefinition{
Fields: map[string]bundle.ParameterDefinition{"param1": {}},
}
outputs := map[string]bundle.Output{"output1": {}}
params := map[string]bundle.Parameter{"param1": {}}

mfst := &manifest.Manifest{
Actions: map[string]bundle.Action{"act1": {}},
Credentials: map[string]bundle.Credential{"cred1": {}},
Expand All @@ -79,11 +76,13 @@ func TestPrepareBuild(t *testing.T) {
URL: "https://test.com",
},
},
Name: "foo",
Outputs: outputs,
Parameters: params,
SchemaVersion: "v1.0.0",
Version: "0.1.0",
Name: "foo",
Outputs: outputs,
Parameters: params,
SchemaVersion: "v1.0.0",
Version: "0.1.0",
License: "MIT",
RequiredExtensions: []string{"ext1", "ext2"},
}

components := []imagebuilder.ImageBuilder{
Expand Down Expand Up @@ -175,6 +174,16 @@ func TestPrepareBuild(t *testing.T) {
}
checksPerformed++

if b.License != mfst.License {
t.Errorf("expected licnse %v, got %v", mfst.License, b.License)
}
checksPerformed++

if !reflect.DeepEqual(b.RequiredExtensions, mfst.RequiredExtensions) {
t.Errorf("expected credentials to be %+v but was %+v", mfst.RequiredExtensions, b.RequiredExtensions)
}
checksPerformed++

// Ensure that all the fields have been checked. If the structures need to diverge in the future, this test should be modified.
mfstFields := getFields(manifest.Manifest{})
if len(mfstFields) != checksPerformed {
Expand Down
30 changes: 16 additions & 14 deletions pkg/duffle/manifest/manifest.go
Expand Up @@ -12,20 +12,22 @@ import (

// Manifest represents a duffle manifest.
type Manifest struct {
Name string `json:"name"`
Version string `json:"version"`
SchemaVersion string `json:"schemaVersion"`
Description string `json:"description,omitempty"`
Keywords []string `json:"keywords,omitempty"`
Maintainers []bundle.Maintainer `json:"maintainers,omitempty"`
InvocationImages map[string]*InvocationImage `json:"invocationImages,omitempty"`
Images map[string]bundle.Image `json:"images,omitempty"`
Actions map[string]bundle.Action `json:"actions,omitempty"`
Parameters *bundle.ParametersDefinition `json:"parameters,omitempty"`
Credentials map[string]bundle.Credential `json:"credentials,omitempty"`
Definitions definition.Definitions `json:"definitions,omitempty"`
Outputs *bundle.OutputsDefinition `json:"outputs,omitempty"`
Custom map[string]interface{} `json:"custom,omitempty"`
Name string `json:"name"`
Version string `json:"version"`
SchemaVersion string `json:"schemaVersion"`
Description string `json:"description,omitempty"`
Keywords []string `json:"keywords,omitempty"`
Maintainers []bundle.Maintainer `json:"maintainers,omitempty"`
InvocationImages map[string]*InvocationImage `json:"invocationImages,omitempty"`
Images map[string]bundle.Image `json:"images,omitempty"`
Actions map[string]bundle.Action `json:"actions,omitempty"`
Parameters map[string]bundle.Parameter `json:"parameters,omitempty"`
Credentials map[string]bundle.Credential `json:"credentials,omitempty"`
Definitions definition.Definitions `json:"definitions,omitempty"`
Outputs map[string]bundle.Output `json:"outputs,omitempty"`
Custom map[string]interface{} `json:"custom,omitempty"`
License string `json:"license,omitempty"`
RequiredExtensions []string `json:"requiredExtensions,omitempty"`
}

// InvocationImage represents an invocation image component of a CNAB bundle
Expand Down
6 changes: 3 additions & 3 deletions pkg/duffle/manifest/manifest_test.go
Expand Up @@ -63,11 +63,11 @@ func TestLoad(t *testing.T) {
t.Errorf("exp docker but was \"%v\"", img.ImageType)
}

if len(m.Parameters.Fields) != 1 {
t.Fatalf("expected 1 parameter but got %d", len(m.Parameters.Fields))
if len(m.Parameters) != 1 {
t.Fatalf("expected 1 parameter but got %d", len(m.Parameters))
}

_, ok := m.Parameters.Fields["foo"]
_, ok := m.Parameters["foo"]
if !ok {
t.Errorf("expected a parameter named foo but got %v", m.Parameters)
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/duffle/manifest/testdata/duffle.json
Expand Up @@ -23,10 +23,8 @@
}
},
"parameters": {
"fields": {
"foo": {
"definition": "foo"
}
"foo": {
"definition": "foo"
}
},
"credentials": {
Expand Down

0 comments on commit 38d7e6e

Please sign in to comment.