Skip to content

Commit

Permalink
Merge pull request #17430 from openshift-cherrypick-robot/cherry-pick…
Browse files Browse the repository at this point in the history
…-17420-to-v4.4

[v4.4] kube play: do not teardown unconditionally on error
  • Loading branch information
openshift-merge-robot authored Feb 8, 2023
2 parents db50458 + 68a58c9 commit 393336b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
19 changes: 12 additions & 7 deletions cmd/podman/kube/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,19 @@ func play(cmd *cobra.Command, args []string) error {
}

if err := kubeplay(reader); err != nil {
// FIXME: The cleanup logic below must be fixed to only remove
// resources that were created before a failure. Otherwise,
// rerunning the same YAML file will cause an error and remove
// the previously created workload.
//
// teardown any containers, pods, and volumes that might have created before we hit the error
teardownReader, trErr := readerFromArg(args[0])
if trErr != nil {
return trErr
}
if tErr := teardown(teardownReader, entities.PlayKubeDownOptions{Force: true}, true); tErr != nil && !errorhandling.Contains(tErr, define.ErrNoSuchPod) {
return fmt.Errorf("error tearing down workloads %q after kube play error %q", tErr, err)
}
// teardownReader, trErr := readerFromArg(args[0])
// if trErr != nil {
// return trErr
// }
// if tErr := teardown(teardownReader, entities.PlayKubeDownOptions{Force: true}, true); tErr != nil && !errorhandling.Contains(tErr, define.ErrNoSuchPod) {
// return fmt.Errorf("error tearing down workloads %q after kube play error %q", tErr, err)
// }
return err
}

Expand Down
6 changes: 6 additions & 0 deletions test/system/700-play.bats
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ RELABEL="system_u:object_r:container_file_t:s0"
is "$output" "${RELABEL} $TESTDIR" "selinux relabel should have happened"
fi

# Now rerun twice to make sure nothing gets removed
run_podman 125 play kube $PODMAN_TMPDIR/test.yaml
is "$output" ".* is in use: pod already exists"
run_podman 125 play kube $PODMAN_TMPDIR/test.yaml
is "$output" ".* is in use: pod already exists"

run_podman stop -a -t 0
run_podman pod rm -t 0 -f test_pod
}
Expand Down

0 comments on commit 393336b

Please sign in to comment.