From 45751c3638649d470e5d04dbf0c40a14fafc7767 Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Sat, 25 Nov 2023 02:51:37 -0700 Subject: [PATCH] error pulling dependency: unable to pull bundle: failed to resolve bundle manifest Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- build/testdata/bundles/wordpressv2/.gitignore | 2 + build/testdata/bundles/wordpressv2/helpers.sh | 14 ++++ .../testdata/bundles/wordpressv2/porter.yaml | 81 +++++++++++++++++++ pkg/cnab/extended_bundle.go | 4 + tests/integration/dependencies_test.go | 64 ++++++++++----- 5 files changed, 144 insertions(+), 21 deletions(-) create mode 100644 build/testdata/bundles/wordpressv2/.gitignore create mode 100755 build/testdata/bundles/wordpressv2/helpers.sh create mode 100644 build/testdata/bundles/wordpressv2/porter.yaml diff --git a/build/testdata/bundles/wordpressv2/.gitignore b/build/testdata/bundles/wordpressv2/.gitignore new file mode 100644 index 000000000..ea5d8c03a --- /dev/null +++ b/build/testdata/bundles/wordpressv2/.gitignore @@ -0,0 +1,2 @@ +Dockerfile +.cnab diff --git a/build/testdata/bundles/wordpressv2/helpers.sh b/build/testdata/bundles/wordpressv2/helpers.sh new file mode 100755 index 000000000..c8d1b00a7 --- /dev/null +++ b/build/testdata/bundles/wordpressv2/helpers.sh @@ -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 +"$@" diff --git a/build/testdata/bundles/wordpressv2/porter.yaml b/build/testdata/bundles/wordpressv2/porter.yaml new file mode 100644 index 000000000..169fd2da7 --- /dev/null +++ b/build/testdata/bundles/wordpressv2/porter.yaml @@ -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 diff --git a/pkg/cnab/extended_bundle.go b/pkg/cnab/extended_bundle.go index 92071b711..487fcbfef 100644 --- a/pkg/cnab/extended_bundle.go +++ b/pkg/cnab/extended_bundle.go @@ -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) } diff --git a/tests/integration/dependencies_test.go b/tests/integration/dependencies_test.go index bf5811e61..e5e17d5b0 100644 --- a/tests/integration/dependencies_test.go +++ b/tests/integration/dependencies_test.go @@ -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() @@ -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 @@ -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) +}