essie-chiang / blog-incubator

0 stars 0 forks source link

oc cp 之能力限制 #24

Open essie-chiang opened 1 year ago

essie-chiang commented 1 year ago

oc cp source 只能指向路径,不支持文件的模糊标识

以下命令会成功

$ oc cp rook-ceph-operator-6c55787d94-xxxx:/tmp/ .
tar: Removing leading `/' from member names
tar: /tmp/ks-script-3bnza7lh: Cannot open: Permission denied
tar: /tmp/ks-script-i86fq85v: Cannot open: Permission denied

但是这些写法会失败哦

oc cp rook-ceph-operator-6c55787d94-stgr6:/tmp/ceph* .
tar: Removing leading `/' from member names
tar: /tmp/ceph*: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
oc cp rook-ceph-operator-6c55787d94-stgr6:/tmp/* .
tar: Removing leading `/' from member names
tar: /tmp/ceph*: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
essie-chiang commented 1 year ago

这么弱的语法支持感到失望吗,看看这个bug,3.x 版本连用/结尾都不可以呢,现在亲测是支持的 https://bugzilla.redhat.com/show_bug.cgi?id=1470962

essie-chiang commented 1 year ago

想要只打印出pod 名字,是有很多讨论,不过oc cp 这个command 不能很好的支持 pod/pod-name-xxx 这种输入哦 https://stackoverflow.com/questions/57700073/oc-get-pods-command-to-just-print-pod-names

所以不要使用这种高级的写法,会报错哦

oc cp -n openshift-storage $(oc get pods -n openshift-storage -o name -l app=rook-ceph-operator):/tmp/ .
essie-chiang commented 1 year ago

总结了这么多问题以后,居然在某个环境里面还是报错了,这样workaround

oc exec -n -- cat >

原因是: kubectl cp requires the tar to be present in your container,同样的container,为什么某个环境里面就能成功呢,我有些困惑呀,莫非是因为odf 版本???

感谢 https://stackoverflow.com/questions/67087858/why-does-kubectl-cp-command-terminates-with-exit-code-126

不要使用oc cp,会变得不幸。。。

marcio-pessoa commented 7 months ago

I never found a solution to this problem, so I finally wrote an application to copy files without tar. It is just a beta, but is working fine on my environment.

https://github.com/marcio-pessoa/kubectl-cp

essie-chiang commented 6 months ago

Thanks @marcio-pessoa Never thought I will get response from English reader or any reader. I like your tool, will try later.