Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

[WIP] Well known custom actions #703

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions docs/guides/bundle-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ case $action in
upgrade)
echo "Upgrade action"
;;
downgrade)
echo "Downgrade action"
;;
status)
io.cnab.status)
echo "Status action"
;;
*)
Expand Down
4 changes: 2 additions & 2 deletions docs/proposal/200-duffle.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The following commands run a CNAB's applicable invocation image, each passing a
- `duffle install` captures the intent to install a bundle, and sets `CNAB_ACTION=install`.
- `duffle upgrade` captures the intent to upgrade an existing installation with a bundle, and sets `CNAB_ACTION=upgrade`.
- `duffle uninstall` captures the intent to uninstall an application, and sets `CNAB_ACTION=uninstall`.
- `duffle status` captures the intent to determine the status of an application, and sets `CNAB_ACTION=status`.
- `duffle status` captures the intent to determine the status of an application, and sets `CNAB_ACTION=io.cnab.status`.

All of these actions accept [credential sets](201-credentialsets.md). `install` and `upgrade` accept parameters. (TODO: In the future, `uninstall` may also accept parameters).

Expand All @@ -35,7 +35,7 @@ Upgrade takes a claim's installation name as input, loads the claim, executes th

Uninstall takes a claim's installation name, looks up the claim, executes the uninstall, and then destroys the claim.

Status takes a claim's installation name, looks up a claim, and executes the status. Status never modifies the claim.
Status takes a claim's installation name, looks up a claim, and executes the `io.cnab.status` action. Status never modifies the claim.

## Duffle List

Expand Down
5 changes: 1 addition & 4 deletions examples/helloazure/cnab/app/run
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ case $action in
upgrade)
echo "Upgrade action"
;;
downgrade)
echo "Downgrade action"
;;
status)
io.cnab.status)
echo "Status action"
;;
*)
Expand Down
5 changes: 1 addition & 4 deletions examples/helloworld/cnab/app/run
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ case $action in
upgrade)
echo "Upgrade action"
;;
downgrade)
echo "Downgrade action"
;;
status)
io.cnab.status)
echo "Status action"
;;
*)
Expand Down
2 changes: 0 additions & 2 deletions pkg/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ const stateful = false
// - install
// - upgrade
// - uninstall
// - downgrade
// - status
type Action interface {
// Run an action, and record the status in the given claim
Run(*claim.Claim, credentials.Set) error
Expand Down
11 changes: 1 addition & 10 deletions pkg/action/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,5 @@ type Status struct {

// Run executes a status action in an image
func (i *Status) Run(c *claim.Claim, creds credentials.Set, w io.Writer) error {
invocImage, err := selectInvocationImage(i.Driver, c)
if err != nil {
return err
}

op, err := opFromClaim(claim.ActionStatus, stateful, c, invocImage, creds, w)
if err != nil {
return err
}
return i.Driver.Run(op)
return (&RunCustom{Driver: i.Driver, Action: "io.cnab.status"}).Run(c, creds, w)
}
6 changes: 4 additions & 2 deletions pkg/action/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"
"time"

"github.com/deislabs/duffle/pkg/bundle"
"github.com/deislabs/duffle/pkg/claim"
"github.com/deislabs/duffle/pkg/driver"

Expand All @@ -13,15 +14,16 @@ import (

func TestStatus_Run(t *testing.T) {
out := ioutil.Discard

b := mockBundle()
b.Actions["io.cnab.status"] = bundle.Action{}
st := &Status{Driver: &driver.DebugDriver{}}
c := &claim.Claim{
Created: time.Time{},
Modified: time.Time{},
Name: "name",
Revision: "revision",
Bundle: mockBundle(),
Parameters: map[string]interface{}{},
Bundle: b,
}

if err := st.Run(c, mockSet, out); err != nil {
Expand Down
4 changes: 1 addition & 3 deletions pkg/claim/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ const (
const (
ActionInstall = "install"
ActionUpgrade = "upgrade"
ActionDowngrade = "downgrade"
ActionUninstall = "uninstall"
ActionStatus = "status"
ActionUnknown = "unknown"
)

// Claim is an installation claim receipt.
//
// Claims reprsent information about a particular installation, and
// provide the necessary data to upgrade, uninstall, and downgrade
// provide the necessary data to upgrade and uninstall.
// a CNAB package.
type Claim struct {
Name string `json:"name"`
Expand Down