Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add framework for remote claims storage plugins #699

Merged
merged 4 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 47 additions & 1 deletion Gopkg.lock

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

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@
name = "github.com/PaesslerAG/jsonpath"
version = "v0.1.1"

[[constraint]]
name = "github.com/hashicorp/go-plugin"
version = "^v1.0.0"

[prune]
non-go = true
go-tests = true
Expand Down
1 change: 1 addition & 0 deletions cmd/porter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func buildRootCommand() *cobra.Command {
cmd.AddCommand(buildBundleCommands(p))
cmd.AddCommand(buildInstanceCommands(p))
cmd.AddCommand(buildMixinCommands(p))
cmd.AddCommand(buildPluginsCommands(p))
cmd.AddCommand(buildCredentialsCommands(p))

for _, alias := range buildAliasCommands(p) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/porter/mixins.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func buildMixinCommands(p *porter.Porter) *cobra.Command {
cmd := &cobra.Command{
Use: "mixins",
Aliases: []string{"mixin"},
Short: "Mixin commands",
Short: "Mixin commands. Mixins assist with authoring bundles.",
Annotations: map[string]string{
"group": "resource",
},
Expand Down
62 changes: 62 additions & 0 deletions cmd/porter/plugins.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import (
"github.com/deislabs/porter/pkg/porter"
"github.com/spf13/cobra"
)

func buildPluginsCommands(p *porter.Porter) *cobra.Command {
cmd := &cobra.Command{
Use: "plugins",
Aliases: []string{"plugin"},
Hidden: true,
Short: "Plugin commands. Plugins let Porter work on different cloud providers and systems.",
Annotations: map[string]string{
"group": "resource",
},
}

cmd.AddCommand(buildPluginsListCommand(p))
cmd.AddCommand(buildPluginRunCommand(p))

return cmd
}

func buildPluginsListCommand(p *porter.Porter) *cobra.Command {
opts := porter.PrintPluginsOptions{}

cmd := &cobra.Command{
Use: "list",
Short: "List installed plugins",
Hidden: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.ParseFormat()
},
RunE: func(cmd *cobra.Command, args []string) error {
return p.PrintPlugins(opts)
},
}

cmd.Flags().StringVarP(&opts.RawFormat, "output", "o", "table",
"Output format, allowed values are: table, json, yaml")

return cmd
}

func buildPluginRunCommand(p *porter.Porter) *cobra.Command {
var opts porter.RunInternalPluginOpts

cmd := &cobra.Command{
Use: "run",
Short: "Serve internal plugins",
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.Validate(args)
},
Run: func(cmd *cobra.Command, args []string) {
p.RunInternalPlugins(opts)
},
Hidden: true, // This should ALWAYS be hidden, it is not a user-facing command
}

return cmd
}
4 changes: 2 additions & 2 deletions docs/content/cli/mixins.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ url: /cli/porter_mixins/
---
## porter mixins

Mixin commands
Mixin commands. Mixins assist with authoring bundles.

### Synopsis

Mixin commands
Mixin commands. Mixins assist with authoring bundles.

### Options

Expand Down
2 changes: 1 addition & 1 deletion docs/content/cli/mixins_feed.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Feed commands

### SEE ALSO

* [porter mixins](/cli/porter_mixins/) - Mixin commands
* [porter mixins](/cli/porter_mixins/) - Mixin commands. Mixins assist with authoring bundles.
* [porter mixins feed generate](/cli/porter_mixins_feed_generate/) - Generate an atom feed from the mixins in a directory
* [porter mixins feed template](/cli/porter_mixins_feed_template/) - Create an atom feed template

2 changes: 1 addition & 1 deletion docs/content/cli/mixins_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ porter mixins install NAME [flags]

### SEE ALSO

* [porter mixins](/cli/porter_mixins/) - Mixin commands
* [porter mixins](/cli/porter_mixins/) - Mixin commands. Mixins assist with authoring bundles.

2 changes: 1 addition & 1 deletion docs/content/cli/mixins_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ porter mixins list [flags]

### SEE ALSO

* [porter mixins](/cli/porter_mixins/) - Mixin commands
* [porter mixins](/cli/porter_mixins/) - Mixin commands. Mixins assist with authoring bundles.

2 changes: 1 addition & 1 deletion docs/content/cli/mixins_uninstall.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ porter mixins uninstall NAME [flags]

### SEE ALSO

* [porter mixins](/cli/porter_mixins/) - Mixin commands
* [porter mixins](/cli/porter_mixins/) - Mixin commands. Mixins assist with authoring bundles.

2 changes: 1 addition & 1 deletion docs/content/cli/porter.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ I am porter 👩🏽‍✈️, the friendly neighborhood CNAB authoring tool
* [porter instances](/cli/porter_instances/) - Bundle Instance commands
* [porter invoke](/cli/porter_invoke/) - Invoke a custom action on a bundle instance
* [porter list](/cli/porter_list/) - list instances of installed bundles
* [porter mixins](/cli/porter_mixins/) - Mixin commands
* [porter mixins](/cli/porter_mixins/) - Mixin commands. Mixins assist with authoring bundles.
* [porter publish](/cli/porter_publish/) - Publish a bundle
* [porter schema](/cli/porter_schema/) - Print the JSON schema for the Porter manifest
* [porter show](/cli/porter_show/) - Show an instance of a bundle
Expand Down
33 changes: 0 additions & 33 deletions pkg/cnab/provider/claims.go

This file was deleted.

5 changes: 4 additions & 1 deletion pkg/cnab/provider/dockerdriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package cnabprovider
import (
"testing"

instancestorageprovider "github.com/deislabs/porter/pkg/instance-storage/provider"

"github.com/stretchr/testify/require"

"github.com/deislabs/cnab-go/driver/docker"
Expand All @@ -12,7 +14,8 @@ import (

func TestNewDriver_Docker(t *testing.T) {
c := config.NewTestConfig(t)
d := NewRuntime(c.Config)
instanceStorage := instancestorageprovider.NewPluginDelegator(c.Config)
d := NewRuntime(c.Config, instanceStorage)

driver, err := d.newDriver("docker", "myclaim", ActionArguments{})
require.NoError(t, err)
Expand Down
6 changes: 1 addition & 5 deletions pkg/cnab/provider/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ func (d *Runtime) Install(args ActionArguments) error {
runErr := i.Run(c, creds, d.ApplyConfig(args)...)

// ALWAYS write out a claim, even if the installation fails
claimStore, err := d.NewClaimStore()
if err != nil {
return errors.Wrap(err, "could not access claim store")
}
saveErr := claimStore.Store(*c)
saveErr := d.instanceStorage.Store(*c)
if runErr != nil {
return errors.Wrap(runErr, "failed to install the bundle")
}
Expand Down
8 changes: 2 additions & 6 deletions pkg/cnab/provider/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import (
)

func (d *Runtime) Invoke(action string, args ActionArguments) error {
claims, err := d.NewClaimStore()
if err != nil {
return errors.Wrapf(err, "could not access claim store")
}
c, err := claims.Read(args.Claim)
c, err := d.instanceStorage.Read(args.Claim)
if err != nil {
return errors.Wrapf(err, "could not load claim %s", args.Claim)
}
Expand Down Expand Up @@ -64,7 +60,7 @@ func (d *Runtime) Invoke(action string, args ActionArguments) error {
runErr := i.Run(&c, creds, d.ApplyConfig(args)...)

// ALWAYS write out a claim, even if the action fails
saveErr := claims.Store(c)
saveErr := d.instanceStorage.Store(c)
if runErr != nil {
return errors.Wrap(runErr, "failed to invoke the bundle")
}
Expand Down