summaryrefslogtreecommitdiff
path: root/pkg/domain/infra
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-08-26 13:58:44 -0400
committerGitHub <noreply@github.com>2021-08-26 13:58:44 -0400
commit94c37d7d470871f9d63b32c97094f5faab1e8a08 (patch)
tree7597eba1d8c63fbf9c7fe19c1ee5255f9194a027 /pkg/domain/infra
parent70caa63e7cfc4a2b70722058be9f315b4a76defe (diff)
parente88b62b34bbd7cd0240a8717ba14f31e1856f832 (diff)
downloadpodman-94c37d7d470871f9d63b32c97094f5faab1e8a08.tar.gz
podman-94c37d7d470871f9d63b32c97094f5faab1e8a08.tar.bz2
podman-94c37d7d470871f9d63b32c97094f5faab1e8a08.zip
Merge pull request #11298 from baude/kubeupdown
teardown play kube
Diffstat (limited to 'pkg/domain/infra')
-rw-r--r--pkg/domain/infra/abi/play.go70
-rw-r--r--pkg/domain/infra/tunnel/play.go4
2 files changed, 74 insertions, 0 deletions
diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go
index 6224feff5..f22b2dbbb 100644
--- a/pkg/domain/infra/abi/play.go
+++ b/pkg/domain/infra/abi/play.go
@@ -586,3 +586,73 @@ func getBuildFile(imageName string, cwd string) (string, error) {
}
return "", err
}
+
+func (ic *ContainerEngine) PlayKubeDown(ctx context.Context, path string, _ entities.PlayKubeDownOptions) (*entities.PlayKubeReport, error) {
+ var (
+ podNames []string
+ )
+ reports := new(entities.PlayKubeReport)
+
+ // read yaml document
+ content, err := ioutil.ReadFile(path)
+ if err != nil {
+ return nil, err
+ }
+
+ // split yaml document
+ documentList, err := splitMultiDocYAML(content)
+ if err != nil {
+ return nil, err
+ }
+
+ // sort kube kinds
+ documentList, err = sortKubeKinds(documentList)
+ if err != nil {
+ return nil, errors.Wrapf(err, "unable to sort kube kinds in %q", path)
+ }
+
+ for _, document := range documentList {
+ kind, err := getKubeKind(document)
+ if err != nil {
+ return nil, errors.Wrapf(err, "unable to read %q as kube YAML", path)
+ }
+
+ switch kind {
+ case "Pod":
+ var podYAML v1.Pod
+ if err := yaml.Unmarshal(document, &podYAML); err != nil {
+ return nil, errors.Wrapf(err, "unable to read YAML %q as Kube Pod", path)
+ }
+ podNames = append(podNames, podYAML.ObjectMeta.Name)
+ case "Deployment":
+ var deploymentYAML v1apps.Deployment
+
+ if err := yaml.Unmarshal(document, &deploymentYAML); err != nil {
+ return nil, errors.Wrapf(err, "unable to read YAML %q as Kube Deployment", path)
+ }
+ var numReplicas int32 = 1
+ deploymentName := deploymentYAML.ObjectMeta.Name
+ if deploymentYAML.Spec.Replicas != nil {
+ numReplicas = *deploymentYAML.Spec.Replicas
+ }
+ for i := 0; i < int(numReplicas); i++ {
+ podName := fmt.Sprintf("%s-pod-%d", deploymentName, i)
+ podNames = append(podNames, podName)
+ }
+ default:
+ continue
+ }
+ }
+
+ // Add the reports
+ reports.StopReport, err = ic.PodStop(ctx, podNames, entities.PodStopOptions{})
+ if err != nil {
+ return nil, err
+ }
+
+ reports.RmReport, err = ic.PodRm(ctx, podNames, entities.PodRmOptions{})
+ if err != nil {
+ return nil, err
+ }
+ return reports, nil
+}
diff --git a/pkg/domain/infra/tunnel/play.go b/pkg/domain/infra/tunnel/play.go
index e66ff0308..e39751a18 100644
--- a/pkg/domain/infra/tunnel/play.go
+++ b/pkg/domain/infra/tunnel/play.go
@@ -22,3 +22,7 @@ func (ic *ContainerEngine) PlayKube(ctx context.Context, path string, opts entit
}
return play.Kube(ic.ClientCtx, path, options)
}
+
+func (ic *ContainerEngine) PlayKubeDown(ctx context.Context, path string, _ entities.PlayKubeDownOptions) (*entities.PlayKubeReport, error) {
+ return play.KubeDown(ic.ClientCtx, path)
+}