-
Notifications
You must be signed in to change notification settings - Fork 949
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: HusterWan <[email protected]>
- Loading branch information
Showing
11 changed files
with
296 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// upgradeDescription is used to describe upgrade command in detail and auto generate command doc. | ||
var upgradeDescription = "" | ||
|
||
// UpgradeCommand use to implement 'upgrade' command, it is used to upgrade a container. | ||
type UpgradeCommand struct { | ||
baseCommand | ||
*container | ||
} | ||
|
||
// Init initialize upgrade command. | ||
func (ug *UpgradeCommand) Init(c *Cli) { | ||
ug.cli = c | ||
ug.cmd = &cobra.Command{ | ||
Use: "upgrade [OPTIONS] IMAGE [COMMAND] [ARG...]", | ||
Short: "Upgrade a container with new image and args", | ||
Long: upgradeDescription, | ||
Args: cobra.MinimumNArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return ug.runUpgrade(args) | ||
}, | ||
Example: upgradeExample(), | ||
} | ||
ug.addFlags() | ||
} | ||
|
||
// addFlags adds flags for specific command. | ||
func (ug *UpgradeCommand) addFlags() { | ||
flagSet := ug.cmd.Flags() | ||
flagSet.SetInterspersed(false) | ||
|
||
c := addCommonFlags(flagSet) | ||
ug.container = c | ||
} | ||
|
||
// runUpgrade is the entry of UpgradeCommand command. | ||
func (ug *UpgradeCommand) runUpgrade(args []string) error { | ||
config, err := ug.config() | ||
if err != nil { | ||
return fmt.Errorf("failed to upgrade container: %v", err) | ||
} | ||
|
||
config.Image = args[0] | ||
if len(args) > 1 { | ||
config.Cmd = args[1:] | ||
} | ||
containerName := ug.name | ||
if containerName == "" { | ||
return fmt.Errorf("failed to upgrade container: must specify container name") | ||
} | ||
|
||
ctx := context.Background() | ||
apiClient := ug.cli.Client() | ||
|
||
// TODO if error is image not found, we can pull image, and retry upgrade | ||
return apiClient.ContainerUpgrade(ctx, containerName, config.ContainerConfig, config.HostConfig) | ||
} | ||
|
||
//upgradeExample shows examples in exec command, and is used in auto-generated cli docs. | ||
func upgradeExample() string { | ||
return "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/alibaba/pouch/test/environment" | ||
|
||
"github.com/go-check/check" | ||
) | ||
|
||
// APIContainerUpgradeSuite is the test suite for container upgrade API. | ||
type APIContainerUpgradeSuite struct{} | ||
|
||
func init() { | ||
check.Suite(&APIContainerUpgradeSuite{}) | ||
} | ||
|
||
// SetUpTest does common setup in the beginning of each test. | ||
func (suite *APIContainerUpgradeSuite) SetUpTest(c *check.C) { | ||
SkipIfFalse(c, environment.IsLinux) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
//"github.com/alibaba/pouch/apis/types" | ||
"github.com/alibaba/pouch/test/command" | ||
"github.com/alibaba/pouch/test/environment" | ||
|
||
"github.com/go-check/check" | ||
"github.com/gotestyourself/gotestyourself/icmd" | ||
) | ||
|
||
// PouchUpgradeSuite is the test suite for upgrade CLI. | ||
type PouchUpgradeSuite struct{} | ||
|
||
func init() { | ||
check.Suite(&PouchUpgradeSuite{}) | ||
} | ||
|
||
// SetUpSuite does common setup in the beginning of each test suite. | ||
func (suite *PouchUpgradeSuite) SetUpSuite(c *check.C) { | ||
SkipIfFalse(c, environment.IsLinux) | ||
|
||
environment.PruneAllContainers(apiClient) | ||
|
||
command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success) | ||
} | ||
|
||
// TearDownTest does cleanup work in the end of each test. | ||
func (suite *PouchUpgradeSuite) TeadDownTest(c *check.C) { | ||
// TODO | ||
} |