Skip to content

Commit

Permalink
Refactor: move plugin kind to apitype (#15946)
Browse files Browse the repository at this point in the history
<!--- 
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->

# Description

This PR moves PluginKind to apitype to prevent circular dependencies
when adding apitype as a dependency of the workspace module.
It also re-exports PluginKind to keep backward compatibility

## Checklist

- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [x] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
  • Loading branch information
glena committed Apr 25, 2024
1 parent 61c5b03 commit d7f24df
Show file tree
Hide file tree
Showing 42 changed files with 367 additions and 276 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- type: chore
scope: cli/plugin
description: Move PluginKind type definition into apitype and re-export for backward compatibility
2 changes: 1 addition & 1 deletion cmd/pulumi-test-language/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (h *testHost) EnsurePlugins(plugins []workspace.PluginSpec, kinds plugin.Fl
}

func (h *testHost) ResolvePlugin(
kind workspace.PluginKind, name string, version *semver.Version,
kind apitype.PluginKind, name string, version *semver.Version,
) (*workspace.PluginInfo, error) {
panic("not implemented")
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/pulumi-test-language/l2continue_on_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"path/filepath"
"testing"

"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/rpcutil"
"github.com/pulumi/pulumi/sdk/v3/go/common/workspace"
Expand Down Expand Up @@ -132,12 +133,12 @@ func (h *L2ContinueOnErrorHost) GetRequiredPlugins(
Plugins: []*pulumirpc.PluginDependency{
{
Name: "simple",
Kind: string(workspace.ResourcePlugin),
Kind: string(apitype.ResourcePlugin),
Version: "2.0.0",
},
{
Name: "fail_on_create",
Kind: string(workspace.ResourcePlugin),
Kind: string(apitype.ResourcePlugin),
Version: "4.0.0",
},
},
Expand Down
3 changes: 2 additions & 1 deletion cmd/pulumi-test-language/l2destroy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"strconv"
"testing"

"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/rpcutil"
Expand Down Expand Up @@ -131,7 +132,7 @@ func (h *L2DestroyLanguageHost) GetRequiredPlugins(
Plugins: []*pulumirpc.PluginDependency{
{
Name: "simple",
Kind: string(workspace.ResourcePlugin),
Kind: string(apitype.ResourcePlugin),
Version: "2.0.0",
},
},
Expand Down
3 changes: 2 additions & 1 deletion cmd/pulumi-test-language/l2large_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"path/filepath"
"testing"

"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/rpcutil"
"github.com/pulumi/pulumi/sdk/v3/go/common/workspace"
Expand Down Expand Up @@ -127,7 +128,7 @@ func (h *L2LargeLanguageHost) GetRequiredPlugins(
Plugins: []*pulumirpc.PluginDependency{
{
Name: "large",
Kind: string(workspace.ResourcePlugin),
Kind: string(apitype.ResourcePlugin),
Version: "4.3.2",
},
},
Expand Down
3 changes: 2 additions & 1 deletion cmd/pulumi-test-language/l2resourcesimple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"path/filepath"
"testing"

"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/rpcutil"
"github.com/pulumi/pulumi/sdk/v3/go/common/workspace"
Expand Down Expand Up @@ -135,7 +136,7 @@ func (h *L2ResourceSimpleLanguageHost) GetRequiredPlugins(
Plugins: []*pulumirpc.PluginDependency{
{
Name: "simple",
Kind: string(workspace.ResourcePlugin),
Kind: string(apitype.ResourcePlugin),
Version: "2.0.0",
},
},
Expand Down
7 changes: 4 additions & 3 deletions pkg/cmd/pulumi/about.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/pulumi/pulumi/pkg/v3/resource/deploy"
"github.com/pulumi/pulumi/pkg/v3/resource/stack"
"github.com/pulumi/pulumi/pkg/v3/version"
"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
Expand Down Expand Up @@ -223,9 +224,9 @@ func (summary *summaryAbout) Print() {
}

type pluginAbout struct {
Name string `json:"name"`
Version *semver.Version `json:"version"`
Kind workspace.PluginKind `json:"kind"`
Name string `json:"name"`
Version *semver.Version `json:"version"`
Kind apitype.PluginKind `json:"kind"`
}

func getPluginsAbout(ctx *plugin.Context, proj *workspace.Project, pwd, main string) ([]pluginAbout, error) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/cmd/pulumi/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/pulumi/pulumi/pkg/v3/engine"
"github.com/pulumi/pulumi/pkg/v3/util"
"github.com/pulumi/pulumi/pkg/v3/version"
"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
"github.com/pulumi/pulumi/sdk/v3/go/common/encoding"
"github.com/pulumi/pulumi/sdk/v3/go/common/env"
Expand All @@ -58,7 +59,7 @@ func loadConverterPlugin(
// Default to the known version of the plugin, this ensures we use the version of the yaml-converter
// that aligns with the yaml codegen we've linked to for this CLI release.
pluginSpec := workspace.PluginSpec{
Kind: workspace.ConverterPlugin,
Kind: apitype.ConverterPlugin,
Name: name,
}
if versionSet := util.SetKnownPluginVersion(&pluginSpec); versionSet {
Expand Down Expand Up @@ -327,7 +328,7 @@ func runConvert(

pluginSpec := workspace.PluginSpec{
Name: string(provider),
Kind: workspace.ResourcePlugin,
Kind: apitype.ResourcePlugin,
}
version, err := pkgWorkspace.InstallPlugin(pluginSpec, log)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/cmd/pulumi/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/pulumi/pulumi/pkg/v3/resource/deploy/providers"
"github.com/pulumi/pulumi/pkg/v3/resource/stack"
pkgWorkspace "github.com/pulumi/pulumi/pkg/v3/workspace"
"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
"github.com/pulumi/pulumi/sdk/v3/go/common/env"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
Expand Down Expand Up @@ -698,7 +699,7 @@ func newImportCmd() *cobra.Command {

pluginSpec := workspace.PluginSpec{
Name: string(provider),
Kind: workspace.ResourcePlugin,
Kind: apitype.ResourcePlugin,
}
version, err := pkgWorkspace.InstallPlugin(pluginSpec, log)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/cmd/pulumi/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"runtime"
"strings"

"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
"github.com/pulumi/pulumi/sdk/v3/go/common/env"
"github.com/pulumi/pulumi/sdk/v3/go/common/workspace"
Expand Down Expand Up @@ -168,7 +169,7 @@ func providerFromSource(packageSource string) (plugin.Provider, error) {
var missingError *workspace.MissingError
if errors.As(err, &missingError) {
spec := workspace.PluginSpec{
Kind: workspace.ResourcePlugin,
Kind: apitype.ResourcePlugin,
Name: pkg,
Version: version,
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/cmd/pulumi/plugin_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/blang/semver"
"github.com/pulumi/pulumi/pkg/v3/util"
"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag/colors"
"github.com/pulumi/pulumi/sdk/v3/go/common/encoding"
Expand Down Expand Up @@ -107,7 +108,7 @@ func (cmd *pluginInstallCmd) Run(ctx context.Context, args []string) error {
// Parse the kind, name, and version, if specified.
var installs []workspace.PluginSpec
if len(args) > 0 {
if !workspace.IsPluginKind(args[0]) {
if !apitype.IsPluginKind(args[0]) {
return fmt.Errorf("unrecognized plugin kind: %s", args[0])
} else if len(args) < 2 {
return errors.New("missing plugin name argument")
Expand Down Expand Up @@ -137,7 +138,7 @@ func (cmd *pluginInstallCmd) Run(ctx context.Context, args []string) error {
}

pluginSpec := workspace.PluginSpec{
Kind: workspace.PluginKind(args[0]),
Kind: apitype.PluginKind(args[0]),
Name: args[1],
Version: version,
PluginDownloadURL: cmd.serverURL, // If empty, will use default plugin source.
Expand Down Expand Up @@ -190,7 +191,7 @@ func (cmd *pluginInstallCmd) Run(ctx context.Context, args []string) error {
for _, plugin := range plugins {
// Skip language plugins; by definition, we already have one installed.
// TODO[pulumi/pulumi#956]: eventually we will want to honor and install these in the usual way.
if plugin.Kind != workspace.LanguagePlugin {
if plugin.Kind != apitype.LanguagePlugin {
installs = append(installs, plugin)
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/cmd/pulumi/plugin_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/blang/semver"
"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
"github.com/pulumi/pulumi/sdk/v3/go/common/testing/diagtest"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/env"
"github.com/pulumi/pulumi/sdk/v3/go/common/workspace"
Expand Down Expand Up @@ -49,7 +50,7 @@ func TestBundledDev(t *testing.T) {
pluginGetLatestVersion: func(ps workspace.PluginSpec) (*semver.Version, error) {
getLatestVersionCalled = true
assert.Equal(t, "nodejs", ps.Name)
assert.Equal(t, workspace.LanguagePlugin, ps.Kind)
assert.Equal(t, apitype.LanguagePlugin, ps.Kind)
return nil, errors.New("404 HTTP error fetching plugin")
},
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/cmd/pulumi/plugin_rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"errors"
"fmt"

"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"

"github.com/blang/semver"
Expand Down Expand Up @@ -55,14 +56,14 @@ func newPluginRmCmd() *cobra.Command {
}

// Parse the filters.
var kind workspace.PluginKind
var kind apitype.PluginKind
var name string
var version *semver.Range
if len(args) > 0 {
if !workspace.IsPluginKind(args[0]) {
if !apitype.IsPluginKind(args[0]) {
return fmt.Errorf("unrecognized plugin kind: %s", kind)
}
kind = workspace.PluginKind(args[0])
kind = apitype.PluginKind(args[0])
} else if !all {
return errors.New("please pass --all if you'd like to remove all plugins")
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/cmd/pulumi/plugin_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/spf13/cobra"

pkgWorkspace "github.com/pulumi/pulumi/pkg/v3/workspace"
"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
"github.com/pulumi/pulumi/sdk/v3/go/common/env"
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
Expand All @@ -38,10 +39,10 @@ type pluginRunCmd struct {
}

func (cmd *pluginRunCmd) run(args []string) error {
if !workspace.IsPluginKind(cmd.kind) {
if !apitype.IsPluginKind(cmd.kind) {
return fmt.Errorf("unrecognized plugin kind: %s", cmd.kind)
}
kind := workspace.PluginKind(cmd.kind)
kind := apitype.PluginKind(cmd.kind)

// Parse the name and version from the second argument in the form of "NAME[@VERSION]".
name := args[0]
Expand Down
5 changes: 3 additions & 2 deletions pkg/codegen/convert/plugin_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/blang/semver"

"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
Expand Down Expand Up @@ -136,7 +137,7 @@ func NewPluginMapper(ws Workspace,
// and so the user can just delete the higher version plugins from their cache.
latestVersions := make(map[string]semver.Version)
for _, plugin := range allPlugins {
if plugin.Kind != workspace.ResourcePlugin {
if plugin.Kind != apitype.ResourcePlugin {
continue
}

Expand All @@ -153,7 +154,7 @@ func NewPluginMapper(ws Workspace,
// iterate all the plugins now because the convert might not even ask for any mappings.
plugins := make([]mapperPluginSpec, 0)
for _, plugin := range allPlugins {
if plugin.Kind != workspace.ResourcePlugin {
if plugin.Kind != apitype.ResourcePlugin {
continue
}

Expand Down

0 comments on commit d7f24df

Please sign in to comment.