summaryrefslogtreecommitdiff
path: root/cmd/podman/play
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2021-08-16 09:37:50 -0500
committerBrent Baude <bbaude@redhat.com>2021-08-24 14:26:14 -0500
commit1e176923b15360559d859000f2fb0c0a3e30f792 (patch)
tree5a888021a0fa58375ebe947b86e5dc37fd8d22a0 /cmd/podman/play
parente9daaf62e3921b8c696f3abd92f001a9447c8aa1 (diff)
downloadpodman-1e176923b15360559d859000f2fb0c0a3e30f792.tar.gz
podman-1e176923b15360559d859000f2fb0c0a3e30f792.tar.bz2
podman-1e176923b15360559d859000f2fb0c0a3e30f792.zip
teardown play kube
add the ability for play kube to tear down based on the yaml used to play it. it is indicated by --down in the play kube command. volumes are NOT deleted during the teardown. pods and their containers are stopped and removed. Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman/play')
-rw-r--r--cmd/podman/play/kube.go48
1 files changed, 47 insertions, 1 deletions
diff --git a/cmd/podman/play/kube.go b/cmd/podman/play/kube.go
index 2eebd9f86..9308371d2 100644
--- a/cmd/podman/play/kube.go
+++ b/cmd/podman/play/kube.go
@@ -86,6 +86,9 @@ func init() {
flags.StringVar(&kubeOptions.Authfile, authfileFlagName, auth.GetDefaultAuthFile(), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
_ = kubeCmd.RegisterFlagCompletionFunc(authfileFlagName, completion.AutocompleteDefault)
+ downFlagName := "down"
+ flags.BoolVar(&kubeOptions.Down, downFlagName, false, "Stop pods defined in the YAML file")
+
if !registry.IsRemote() {
certDirFlagName := "cert-dir"
flags.StringVar(&kubeOptions.CertDir, certDirFlagName, "", "`Pathname` of a directory containing TLS certificates and keys")
@@ -144,12 +147,55 @@ func kube(cmd *cobra.Command, args []string) error {
}
kubeOptions.StaticMACs = append(kubeOptions.StaticMACs, m)
}
+ if kubeOptions.Down {
+ return teardown(yamlfile)
+ }
+ return playkube(yamlfile)
+}
- report, err := registry.ContainerEngine().PlayKube(registry.GetContext(), yamlfile, kubeOptions.PlayKubeOptions)
+func teardown(yamlfile string) error {
+ var (
+ podStopErrors utils.OutputErrors
+ podRmErrors utils.OutputErrors
+ )
+ options := new(entities.PlayKubeDownOptions)
+ reports, err := registry.ContainerEngine().PlayKubeDown(registry.GetContext(), yamlfile, *options)
if err != nil {
return err
}
+ // Output stopped pods
+ fmt.Println("Pods stopped:")
+ for _, stopped := range reports.StopReport {
+ if len(stopped.Errs) == 0 {
+ fmt.Println(stopped.Id)
+ } else {
+ podStopErrors = append(podStopErrors, stopped.Errs...)
+ }
+ }
+ // Dump any stop errors
+ lastStopError := podStopErrors.PrintErrors()
+ if lastStopError != nil {
+ fmt.Fprintf(os.Stderr, "Error: %s\n", lastStopError)
+ }
+
+ // Output rm'd pods
+ fmt.Println("Pods removed:")
+ for _, removed := range reports.RmReport {
+ if removed.Err == nil {
+ fmt.Println(removed.Id)
+ } else {
+ podRmErrors = append(podRmErrors, removed.Err)
+ }
+ }
+ return podRmErrors.PrintErrors()
+}
+
+func playkube(yamlfile string) error {
+ report, err := registry.ContainerEngine().PlayKube(registry.GetContext(), yamlfile, kubeOptions.PlayKubeOptions)
+ if err != nil {
+ return err
+ }
// Print volumes report
for i, volume := range report.Volumes {
if i == 0 {