Skip to content

Commit

Permalink
error pulling dependency: unable to pull bundle: failed to resolve bu…
Browse files Browse the repository at this point in the history
…ndle manifest

Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com>
  • Loading branch information
schristoff committed Nov 25, 2023
1 parent 3dcfca5 commit 45751c3
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 21 deletions.
2 changes: 2 additions & 0 deletions build/testdata/bundles/wordpressv2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Dockerfile
.cnab
14 changes: 14 additions & 0 deletions build/testdata/bundles/wordpressv2/helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail

install() {
mkdir -p /cnab/app/outputs
echo "topsecret-blog" >> /cnab/app/outputs/wordpress-password
}

ping() {
echo ping
}

# Call the requested function and pass the arguments as-is
"$@"
81 changes: 81 additions & 0 deletions build/testdata/bundles/wordpressv2/porter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
schemaVersion: 1.0.1
name: wordpress
version: 0.1.4
registry: "localhost:5000"

mixins:
- exec
- helm3:
repositories:
bitnami:
url: "https://charts.bitnami.com/bitnami"

dependencies:
requires:
- name: mysql
bundle:
reference: localhost:5000/mysql
version: v0.1.0
sharing:
mode: true
group:
name: myapp
parameters:
database-name: wordpress
mysql-user: wordpress
namespace: wordpress

credentials:
- name: kubeconfig
path: /home/nonroot/.kube/config

parameters:
- name: wordpress-name
type: string
default: porter-ci-wordpress
env: WORDPRESS_NAME
- name: wordpress-password
type: string
sensitive: true
applyTo:
- install
- upgrade
- name: namespace
type: string
default: 'wordpress'

install:
- exec:
command: ./helpers.sh
arguments:
- install

upgrade:
- exec:
command: ./helpers.sh
arguments:
- install

ping:
- exec:
description: "Ping"
command: ./helpers.sh
arguments:
- ping

uninstall:
- exec:
command: echo
arguments:
- uninstalled

outputs:
- name: wordpress-password
description: "The Wordpress installation password"
type: string
default: "default-password"
applyTo:
- "install"
- "upgrade"
sensitive: true
path: /cnab/app/outputs/wordpress-password
4 changes: 4 additions & 0 deletions pkg/cnab/extended_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ func (b *ExtendedBundle) ResolveVersionv2(name string, dep v2.Dependency) (OCIRe

return ref.WithTag(tag)
}
//I think this is going to need to be smarter
if dep.Version != "" {
return ref, nil
}

return OCIReference{}, fmt.Errorf("not implemented: dependency version range specified for %s: %w", name, err)
}
Expand Down
64 changes: 43 additions & 21 deletions tests/integration/dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,9 @@ func publishMySQLBundle(ctx context.Context, p *porter.TestPorter) {

func installWordpressBundle(ctx context.Context, p *porter.TestPorter, namespace string, mysqlName string) {

_, err := p.Installations.GetInstallation(ctx, namespace, "mysql")
require.NoError(p.T(), err, "could not fetch installation mysql")

// Install the bundle that has dependencies
p.CopyDirectory(filepath.Join(p.RepoRoot, "build/testdata/bundles/wordpress"), ".", false)
err := p.CopyDirectory(filepath.Join(p.RepoRoot, "build/testdata/bundles/wordpress"), ".", false)
require.NoError(p.T(), err, "copy of build/testdata/bundles/wordpress failed")

namespace = p.RandomString(10)
installOpts := porter.NewInstallOptions()
Expand Down Expand Up @@ -254,40 +252,29 @@ func TestSharedDependencies(t *testing.T) {
p := porter.NewTestPorter(t)
p.Config.SetExperimentalFlags(experimental.FlagDependenciesV2)

pwd := p.Getwd()
bunDir, err := os.MkdirTemp("", "porter-mysqlv2-")
require.NoError(p.T(), err, "could not create temp directory at all")

defer os.RemoveAll(bunDir)

// Rebuild the bundle from a temp directory so that we don't modify the source directory
// and leave modified files around.
p.TestConfig.TestContext.AddTestDirectory(filepath.Join(p.RepoRoot, "build/testdata/bundles/mysql"), bunDir+"/mysql")
p.TestConfig.TestContext.AddTestDirectory(filepath.Join(p.RepoRoot, "build/testdata/bundles/wordpress"), bunDir+"/wordpress")
mysqldir := p.AddTestBundleDir(p.RepoRoot+"/build/testdata/bundles/mysql", false)

p.Chdir(bunDir + "/mysql")
defer p.Chdir(pwd)
defer p.Close()
wpdir := p.AddTestBundleDir(p.RepoRoot+"/build/testdata/bundles/wordpress", false)
ctx := p.SetupIntegrationTest()

namespace := p.RandomString(10)

p.Chdir(mysqldir)
publishMySQLBundle(ctx, p)

installMySQLbundle(ctx, p, namespace)

p.Chdir(bunDir + "wordpress")

//todo(schristoff): fix this srsly plz
err = p.CopyFile(bunDir+"/mysql/.cnab/bundle.json", bunDir+"/wordpress/.cnab/app/dependencies/mysql/bundle.json")
require.NoError(p.T(), err, "err copying mysql bundle.json")

installWordpressBundle(ctx, p, namespace, "mysql")
p.Chdir(wpdir)
installWordpressBundlev2(ctx, p, namespace, "mysql")

}

func installMySQLbundle(ctx context.Context, p *porter.TestPorter, namespace string) {

p.CopyDirectory(filepath.Join(p.RepoRoot, "build/testdata/bundles/mysql"), ".", false)
installOpts := porter.NewInstallOptions()
installOpts.Namespace = namespace
installOpts.CredentialIdentifiers = []string{"ci"} // Use the ci credential set, porter should remember this for later
Expand All @@ -305,3 +292,38 @@ func installMySQLbundle(ctx context.Context, p *porter.TestPorter, namespace str
mysqlinst.SetLabel("sh.porter.SharingGroup", "myapp")

}

func installWordpressBundlev2(ctx context.Context, p *porter.TestPorter, namespace string, mysqlName string) {

// Install the bundle that has dependencies
err := p.CopyDirectory(filepath.Join(p.RepoRoot, "build/testdata/bundles/wordpressv2"), ".", false)
require.NoError(p.T(), err, "copy of build/testdata/bundles/wordpressv2 failed")

namespace = p.RandomString(10)
installOpts := porter.NewInstallOptions()
installOpts.Namespace = namespace
installOpts.CredentialIdentifiers = []string{"ci"} // Use the ci credential set, porter should remember this for later
installOpts.Params = []string{
"wordpress-password=mypassword",
"namespace=" + namespace,
"mysql#namespace=" + namespace,
}

// Add a supplemental parameter set to vet dep param resolution
installOpts.ParameterSets = []string{"myparam"}
testParamSets := storage.NewParameterSet(namespace, "myparam", secrets.SourceMap{
Name: "mysql#probe-timeout",
Source: secrets.Source{
Strategy: host.SourceValue,
Hint: "2",
},
})

p.TestParameters.InsertParameterSet(ctx, testParamSets)

err = installOpts.Validate(ctx, []string{}, p.Porter)
require.NoError(p.T(), err, "validation of install opts for root bundle failed")

err = p.InstallBundle(ctx, installOpts)
require.NoError(p.T(), err, "install of root bundle failed namespace %s", namespace)
}

0 comments on commit 45751c3

Please sign in to comment.