pulumi/tests/integration
Abhinav Gupta 33b5ad6527
feat(go/host): Support vendored dependencies
The Go language host cannot resolve dependencies or plugins if a Pulumi
program vendors its dependencies.

BACKGROUND

The GetRequiredPlugins and GetProgramDependencies methods of the Go
language host rely on the following two commands:

    go list -m -mod=mod all
    go list -m -mod=mod ...
    # '...' means current module and its descendants

GetRequiredPlugins additionally searches the source directories for each
returned module for pulumi-plugin.json files at a pre-determined paths.

    $module/pulumi-plugin.json
    $module/go/pulumi-plugin.json
    $module/go/*/pulumi-plugin.json

This works for most Pulumi programs, except those that vendor private
dependencies with 'go mod vendor'.
For those programs, the above commands fail because -mod=mod forces them
to run in module mode, and their private dependencies are not accessible
in module mode (because they are not exposed publicly).

We use the -mod=mod flag to force 'go list' to run in module mode
because otherwise, it will automatically use vendor mode if a vendor
directory is present. However, in vendor mode, the two 'go list'
commands above are not supported.
The following links add more context on why, but in short:
vendor does not have enough information for the general 'go list'.

- https://stackoverflow.com/a/60660593,
- https://github.com/golang/go/issues/35589#issuecomment-554488544

In short,

- list all with -mod=mod fails because the dependency is private
- list without -mod=mod will use vendor mode
- vendor mode doesn't support the listing all

SOLUTION

Drop the -mod=mod flag so that 'go list' can decide whether to run in
module mode or vendor mode.
However, instead of running it with 'all' or '...',
pass in a list of dependencies extracted from the go.mod.

    go list -m import/path1 import/path2 # ...

This operation is completely offline in vendor mode
so it can list information about private dependencies too.

This alone isn't enough though because in vendor mode,
the JSON output does not include the module root directory.
E.g.

    % go list -mod=vendor -json -m github.com/pulumi/pulumi/sdk/v3
    {
            "Path": "github.com/pulumi/pulumi/sdk/v3",
            "Version": "v3.55.0",
            "GoVersion": "1.18"
    }

    # Versus

    % go list -mod=mod -json -m github.com/pulumi/pulumi/sdk/v3
    {
            "Path": "github.com/pulumi/pulumi/sdk/v3",
            "Version": "v3.55.0",
            "Time": "2023-02-14T11:04:22Z",
            "Dir": "[...]/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.55.0",
            "GoMod": "[...]/go/pkg/mod/cache/download/github.com/pulumi/pulumi/sdk/v3/@v/v3.55.0.mod",
            "GoVersion": "1.18"
    }

Therefore, we have to manually calculate the path for each module root.
That's easy enough: vendor/$importPath.

Lastly, since GetProgramDependencies only needs a dependency list,
it now extracts information from the go.mod without calling 'go list'.

TESTING

Adds a variant of the test added in #12715 that verifies the
functionality with vendoring. It removes the sources for the
dependencies to simulate private dependencies. The new test fails
without the accompanying change.

The fix was further manually verified against the reproduction included
in #12526.

    % cd go-output
    % pulumi plugin rm -a -y
    % pulumi preview
    Previewing update (abhinav):
    Downloading plugin: 15.19 MiB / 15.19 MiB [=========================] 100.00% 0s
                                                                                    [resource plugin random-4.8.2] installing
         Type                      Name               Plan
     +   pulumi:pulumi:Stack       go-output-abhinav  create
     +   └─ random:index:RandomId  rrr                create

    Resources:
        + 2 to create

    % pulumi plugin ls
    NAME    KIND      VERSION  SIZE   INSTALLED       LAST USED
    random  resource  4.8.2    33 MB  26 seconds ago  26 seconds ago

    TOTAL plugin cache size: 33 MB

Note that the version of random (4.8.2) is what's specified in the
go.mod, not the latest release (v4.12.1).

    % grep pulumi-random go.mod
            github.com/pulumi/pulumi-random/sdk/v4 v4.8.2

With the plugin downloaded, I ran this again without an internet
connection.

    % pulumi preview
    Previewing update (abhinav):
         Type                      Name               Plan
     +   pulumi:pulumi:Stack       go-output-abhinav  create
     +   └─ random:index:RandomId  rrr                create

    Resources:
        + 2 to create

This means that if the dependencies are vendored, and the plugin is
already available, we won't make additional network requests, which also
addresses #7089.

Resolves #12526
Resolves #7089
2023-04-24 09:49:16 -07:00
..
about Bump go-git to v5.6.0 to remove cgo dependency fixing 2023-02-28 16:01:31 -08:00
aliases all: Reformat with gofumpt 2023-03-03 09:00:24 -08:00
cloud_secrets_provider Enable full strict mode. (#3218) 2019-09-11 16:21:35 -07:00
component_provider_schema Add RunPlugin support for python 2023-03-06 21:35:39 +00:00
config_basic Bump go-git to v5.6.0 to remove cgo dependency fixing 2023-02-28 16:01:31 -08:00
config_capture_e2e/nodejs Changing build.proj to run all languages and tests on windows 2020-01-27 21:16:37 +02:00
config_secrets_warn Bump go-git to v5.6.0 to remove cgo dependency fixing 2023-02-28 16:01:31 -08:00
construct_component Add RunPlugin support for python 2023-03-06 21:35:39 +00:00
construct_component_error_apply Update @types/node version in tests 2023-02-07 14:20:27 +00:00
construct_component_methods [sdk/go] Track rehydrated components as dependencies 2023-03-24 13:49:10 -07:00
construct_component_methods_errors Add RunPlugin support for python 2023-03-06 21:35:39 +00:00
construct_component_methods_resources Add RunPlugin support for python 2023-03-06 21:35:39 +00:00
construct_component_methods_unknown Add RunPlugin support for python 2023-03-06 21:35:39 +00:00
construct_component_output_values Add RunPlugin support for python 2023-03-06 21:35:39 +00:00
construct_component_plain Add RunPlugin support for python 2023-03-06 21:35:39 +00:00
construct_component_provider Add RunPlugin support for python 2023-03-06 21:35:39 +00:00
construct_component_provider_propagation test: Add failing test case for #12593 2023-04-13 18:12:18 -07:00
construct_component_resource_options sdk/go: Propagate more resource options from provider.Construct 2023-04-21 10:58:59 -07:00
construct_component_slow Update @types/node version in tests 2023-02-07 14:20:27 +00:00
construct_component_unknown Add RunPlugin support for python 2023-03-06 21:35:39 +00:00
construct_nested_component/go all: Reformat with gofumpt 2023-03-03 09:00:24 -08:00
custom_timeouts Rename "Smoke" test to "Acceptance" tests 2023-01-30 15:38:37 -05:00
delete_before_create Rename "Smoke" test to "Acceptance" tests 2023-01-30 15:38:37 -05:00
deleted_with all: Reformat with gofumpt 2023-03-03 09:00:24 -08:00
dependency_steps Rename "Smoke" test to "Acceptance" tests 2023-01-30 15:38:37 -05:00
double_pending_delete Rename "Smoke" test to "Acceptance" tests 2023-01-30 15:38:37 -05:00
duplicate_urns Rename "Smoke" test to "Acceptance" tests 2023-01-30 15:38:37 -05:00
dynamic Pass PULUMI_CONFIG through to provider plugins 2023-04-05 10:17:18 +01:00
ee_perf Use prefered `new pulumi.Config()` form 2019-01-31 16:11:57 -08:00
empty Bump go-git to v5.6.0 to remove cgo dependency fixing 2023-02-28 16:01:31 -08:00
enums [sdk/python] Fix enum test for python 11 behavior change 2023-03-22 07:23:46 -07:00
exclude_protected Implement the --exclude-protected feature (#8359) 2021-11-15 11:45:14 -08:00
explicit_provider Enable full strict mode. (#3218) 2019-09-11 16:21:35 -07:00
gather_plugin all: Reformat with gofumpt 2023-03-03 09:00:24 -08:00
get_created Enable full strict mode. (#3218) 2019-09-11 16:21:35 -07:00
get_resource all: Reformat with gofumpt 2023-03-03 09:00:24 -08:00
go Bump go-git to v5.6.0 to remove cgo dependency fixing 2023-02-28 16:01:31 -08:00
invalid_package_json Enable full strict mode. (#3218) 2019-09-11 16:21:35 -07:00
large_resource Bump go-git to v5.6.0 to remove cgo dependency fixing 2023-02-28 16:01:31 -08:00
nodejs Merge #12318 #12319 2023-04-12 13:57:36 +00:00
partial_state Rename "Smoke" test to "Acceptance" tests 2023-01-30 15:38:37 -05:00
partial_values Propagate inputs to outputs during preview. (#3327) 2019-11-11 12:09:34 -08:00
policy unused: Remove unused functions and types 2023-01-12 09:55:34 -08:00
printf Bump go-git to v5.6.0 to remove cgo dependency fixing 2023-02-28 16:01:31 -08:00
project_main Bump go-git to v5.6.0 to remove cgo dependency fixing 2023-02-28 16:01:31 -08:00
project_main_abs Enable absolute and relative parent paths for pulumi main (#6734) 2021-04-08 21:39:52 -07:00
project_main_parent/foo Enable absolute and relative parent paths for pulumi main (#6734) 2021-04-08 21:39:52 -07:00
protect_resources Rename "Smoke" test to "Acceptance" tests 2023-01-30 15:38:37 -05:00
provider_secret_config Enable full strict mode. (#3218) 2019-09-11 16:21:35 -07:00
python fix: handle exception for main not found in python (#10617) 2022-09-07 08:42:38 -07:00
python_await [sdk/python] - Await all async tasks (#6606) 2021-03-30 10:56:17 -07:00
query Rename "Smoke" test to "Acceptance" tests 2023-01-30 15:38:37 -05:00
read Rename "Smoke" test to "Acceptance" tests 2023-01-30 15:38:37 -05:00
recreate_resource_check Rename "Smoke" test to "Acceptance" tests 2023-01-30 15:38:37 -05:00
refresh/go Bump go-git to v5.6.0 to remove cgo dependency fixing 2023-02-28 16:01:31 -08:00
resource_refs_get_resource all: Reformat with gofumpt 2023-03-03 09:00:24 -08:00
rotate_passphrase Bump go-git to v5.6.0 to remove cgo dependency fixing 2023-02-28 16:01:31 -08:00
secret_outputs [sdk/python] Fix secret regression (#5496) 2020-10-01 14:57:51 -07:00
single_resource Suppress JSON outputs in preview correctly (#2771) 2019-05-25 12:10:38 +02:00
stack_bad_parenting Consistent dependencies (#2517) 2019-03-05 20:34:51 -08:00
stack_dependencies Remove existing lock files 2018-11-12 15:33:58 -08:00
stack_outputs Remove dotnet 2022-12-13 16:13:53 +00:00
stack_parenting Consistent dependencies (#2517) 2019-03-05 20:34:51 -08:00
stack_project_name Actually fix the naming test (#10554) 2022-08-31 20:52:23 +01:00
stack_reference all: Reformat with gofumpt 2023-03-03 09:00:24 -08:00
stack_reference_multi/python Regression tests for StackReference in the Python SDK (#3913) 2020-02-17 10:40:46 -08:00
stack_reference_secrets/nodejs Remove dotnet 2022-12-13 16:13:53 +00:00
steps Rename "Smoke" test to "Acceptance" tests 2023-01-30 15:38:37 -05:00
targets all: Reformat with gofumpt 2023-03-03 09:00:24 -08:00
transformations Rename "Smoke" test to "Acceptance" tests 2023-01-30 15:38:37 -05:00
tsconfig Add tsconfig option to specify tsconfig path (#8452) 2021-11-22 11:42:39 -08:00
types Rename "Smoke" test to "Acceptance" tests 2023-01-30 15:38:37 -05:00
unsafe_snapshot_tests/bad_resource Update tests/integration/unsafe_snapshot_tests/bad_resource/resource.ts 2022-09-15 08:00:36 -07:00
.gitignore ci: Enable async component builds 2022-09-14 10:06:05 -07:00
appdash_test.go all: Reformat with gofumpt 2023-03-03 09:00:24 -08:00
component_setup.sh Engine and Golang support for shimless providers 2022-11-14 11:25:41 +00:00
integration_acceptance_test.go Rename "Smoke" test to "Acceptance" tests 2023-01-30 15:38:37 -05:00
integration_go_acceptance_test.go all: Reformat with gofumpt 2023-03-03 09:00:24 -08:00
integration_go_test.go feat(go/host): Support vendored dependencies 2023-04-24 09:49:16 -07:00
integration_nodejs_acceptance_test.go all: Reformat with gofumpt 2023-03-03 09:00:24 -08:00
integration_nodejs_test.go test: Add failing test case for #12593 2023-04-13 18:12:18 -07:00
integration_python_acceptance_test.go all: Reformat with gofumpt 2023-03-03 09:00:24 -08:00
integration_python_test.go test: Add failing test case for #12593 2023-04-13 18:12:18 -07:00
integration_test.go sdk/go: Propagate more resource options from provider.Construct 2023-04-21 10:58:59 -07:00
integration_util_test.go all: Fix revive issues 2023-03-21 08:55:11 -07:00