Don't detach from container while copying files from it

Files copying from containers to host shouldn't be performed
in background, because corresponding states must ensure
that operation is completed. Also remove containers after
data is copied.

It's impossible to create a state which waits util the
command in container exits by using 'dockerng' module, for
details see this issue: https://github.com/saltstack/salt/issues/30199

Change-Id: I74cc1f93b5f72e2e05add0a147e03f149846a07e
Closes: https://mirantis.jira.com/browse/PROD-12036
diff --git a/kubernetes/_common.sls b/kubernetes/_common.sls
index a238128..113e67d 100644
--- a/kubernetes/_common.sls
+++ b/kubernetes/_common.sls
@@ -25,12 +25,8 @@
     - group: root
 
 hyperkube-copy:
-  dockerng.running:
-    - image: {{ common.hyperkube.image }}
-    - command: cp -v /hyperkube /tmp/hyperkube
-    - binds:
-      - /tmp/hyperkube/:/tmp/hyperkube/
-    - force: True
+  cmd.run:
+    - name: docker run --rm -v /tmp/hyperkube:/tmp/hyperkube --entrypoint cp {{ common.hyperkube.image }} -vr /hyperkube /tmp/hyperkube
     - require:
       - file: /tmp/hyperkube
     {%- if grains.get('noservices') %}
@@ -45,7 +41,7 @@
     - user: root
     - group: root
     - require:
-      - dockerng: hyperkube-copy
+      - cmd: hyperkube-copy
     {%- if grains.get('noservices') %}
     - onlyif: /bin/false
     {%- endif %}
diff --git a/kubernetes/pool/calico.sls b/kubernetes/pool/calico.sls
index 9e31551..4b1a8d1 100644
--- a/kubernetes/pool/calico.sls
+++ b/kubernetes/pool/calico.sls
@@ -7,17 +7,10 @@
       - group: root
 
 copy-calico-ctl:
-  dockerng.running:
-    - image: {{ pool.network.calicoctl.image }}
-    {%- if grains.get('noservices') %}
-    - onlyif: /bin/false
-    {%- endif %}
-
-copy-calico-ctl-cmd:
   cmd.run:
-    - name: docker cp copy-calico-ctl:calicoctl /tmp/calico/
+    - name: docker run --rm -v /tmp/calico/:/tmp/calico/ --entrypoint cp {{ pool.network.calicoctl.image }} -v /calicoctl /tmp/calico/
     - require:
-      - dockerng: copy-calico-ctl
+      - file: /tmp/calico/
     {%- if grains.get('noservices') %}
     - onlyif: /bin/false
     {%- endif %}
@@ -29,23 +22,16 @@
     - user: root
     - group: root
     - require:
-      - cmd: copy-calico-ctl-cmd
+      - cmd: copy-calico-ctl
     {%- if grains.get('noservices') %}
     - onlyif: /bin/false
     {%- endif %}
 
 copy-calico-node:
-  dockerng.running:
-    - image: {{ pool.network.get('image', 'calico/node') }}
-    {%- if grains.get('noservices') %}
-    - onlyif: /bin/false
-    {%- endif %}
-
-copy-bird-cl-cmd:
   cmd.run:
-    - name: docker cp copy-calico-node:/bin/birdcl /tmp/calico/
+    - name: docker run --rm -v /tmp/calico/:/tmp/calico/ --entrypoint cp {{ pool.network.get('image', 'calico/node') }} -v /bin/birdcl /tmp/calico/
     - require:
-      - dockerng: copy-calico-node
+      - file: /tmp/calico/
     {%- if grains.get('noservices') %}
     - onlyif: /bin/false
     {%- endif %}
@@ -57,18 +43,16 @@
     - user: root
     - group: root
     - require:
-      - cmd: copy-bird-cl-cmd
+      - cmd: copy-calico-node
     {%- if grains.get('noservices') %}
     - onlyif: /bin/false
     {%- endif %}
 
 copy-calico-cni:
-  dockerng.running:
-    - image: {{ pool.network.cni.image }}
-    - command: cp -vr /opt/cni/bin/ /tmp/calico/
-    - binds:
-      - /tmp/calico/:/tmp/calico/
-    - force: True
+  cmd.run:
+    - name: docker run --rm -v /tmp/calico/:/tmp/calico/ --entrypoint cp {{ pool.network.cni.image }} -vr /opt/cni/bin/ /tmp/calico/
+    - require:
+      - file: /tmp/calico/
     {%- if grains.get('noservices') %}
     - onlyif: /bin/false
     {%- endif %}
@@ -83,7 +67,7 @@
     - user: root
     - group: root
     - require:
-      - dockerng: copy-calico-cni
+      - cmd: copy-calico-cni
     - require_in:
       - service: calico_node
     {%- if grains.get('noservices') %}
diff --git a/kubernetes/pool/cni.sls b/kubernetes/pool/cni.sls
index ffcf2ad..bf896ae 100644
--- a/kubernetes/pool/cni.sls
+++ b/kubernetes/pool/cni.sls
@@ -10,12 +10,8 @@
     - group: root
 
 copy-network-cni:
-  dockerng.running:
-    - image: {{ common.hyperkube.image }}
-    - command: cp -vr /opt/cni/bin/ /tmp/cni/
-    - binds:
-      - /tmp/cni/:/tmp/cni/
-    - force: True
+  cmd.run:
+    - name: docker run --rm -v /tmp/cni/:/tmp/cni/ --entrypoint cp {{ common.hyperkube.image }} -vr /opt/cni/bin/ /tmp/cni/
     - require:
         - file: /tmp/cni/
     {%- if grains.get('noservices') %}
@@ -33,7 +29,7 @@
     - watch_in:
       - service: kubelet_service
     - require:
-      - dockerng: copy-network-cni
+      - cmd: copy-network-cni
     {%- if grains.get('noservices') %}
     - onlyif: /bin/false
     {%- endif %}