helm3.x拉取harbor2.x中helm chart问题解析

软件环境

Harbor v2.0.1
Helm v3.3.1

问题场景

在企业内部搭建了私有Harbor做image和helm chart的存储,但是最近发现上传到Harbor的helm chax T z +rt包pulr D S + ` Cl不下来,pull命令执行成功,但是l 1 . # O找不q k * % |到helm chart包

问题复现

上传helm chart到harbor的charts项目中

# helm registry logi, ~ una B n f x.xx o c 9 * i.x.com
# helm chart save /root/testchart x.x.x.com/charts/testchart:v4.0.7-1
ref:     x.x.x.com/charts/testchart:v40 - _ +.0.7-1
digest:  0f21cQ 2 l a W Y . Idap % ^ M r } } % [817efc0d415beabc7bc2cf6742814d5f4e924d6b7fe998ca2f3480be1
size:    77.4 KiB
name:    testchart
version: 1.0.0
v4.0.7-1: saved
# helm chaW U 8 U ^ ,rt push x.x.x.com/charts/testchart:v4.0.7-1
The push refy 3 ^ A E bers to repository [x.x.x.com/cY ? X - Kharts/teP u Y g H t 2 9stchart]
ref:     x.x.x.com/charts/testchar 6 urt:v4.0.7-1
digest:  0f21cda817efc0d415beabc7bc2cf6742813 $ R j G ]4d5f4e924d6b7fe998ca2f3480be1
s| } + h @ ? size:    77.4 KiB
name:    testchart
version: 1.0.0
v4.0.7-1: pushed to remote (1 layer, 77.4 KiB total)

根据harbor提示的拉取命令pull对应的helm chaB g B &rt包

helm3.x拉取harbor2.x中helm chart问题解析
通过如上截图我们可以看到,上传到harbor的helm chart有对应的拉取命令可以下载,命令如下:

# helm chart pull x.x.x.com/ch& c U y * U + k warts/testchart@sha256:0f21cda817efc0d40 ^ k W { E15beabc7bc2! r - cf6742814d5f4e924d6b7fe998ca2f348V } {0be1
0f21cdaa [ l j l C b817efc0d415beabc7bc2cf6742814d5f4e924d6b7fe998ca2f3480be1: Pulling from x.x.x.com/charts/testchart@sha256
ref:     x.x.x.com/charts/testchart@sha256:0f21cda817efc0d415beabc7bc2cf6742814d5f4ey s Q q Y924d6b7fe998ca2f3480be1
digest:  0f21cda817efc0d415beabc7bc2cf6742814d5f4e924d6b7fe9x ` H { Z i K98ca2f3480be1
size:    71 / c k7.4 KiB
name:    testchart
version: 1.0.0
Status: Downloaded newer chart fC # d y Uod R Ur x.x.x.com/charts/testchart@sha256:0f21cda817efc0d415beabc7bc2cf67P O 8 L42814d5f4e924d6b7fe998ca2f3480be1

看如上命令的自行结果,应该是下载成功了。但是,拉取之后发现本地目录什么都没有。

排查

1,第一S X [ ) c : x k l反应,harbor提供的命令有错?所以就查harbor的官方文档。
从官方文档我N V V们发现harbor1.x的版本从1.6开始,支持通过界面来上传helm chart,支持通过helm add repo和helm pull的方J s 0 % p d式从harbor中拉取helm chart;而; g _我们使用的harbor2.x版本需要使用OCI兼容的helm3来和harbor来pull和push,故根据官方文档的介绍我们使用的命p ` e m S J 2令是正确的。
2,怀疑是否是helm版本问题,故把hel _ 9lm3的版本升级到了最新版本,发现问y 7 f N 6 6 (题依旧。但是,发现了一些端倪。从命令的输出结果Status字段我们可以看到再次执行pu% 5 . h Ill操作不是Downloaded newer chart而是Chart is up to date,故我们A ` 8可以猜测本地已经存储了相关的chart文件了。

# helm chart pull x.x.x.com/charts/testchart@sha256:0f21cda817efc0d415beabc7bc2cf6742814d5f4e924d6b7fe998ca2f3480be1
0f21cda817efc0d415beabc7bc2cf6742814d5f4e924d6b7fe998ca2f3480be1H H P @ ) t E ( X: Pulling fromH d Y Q C P % x.x.x.com/charts/testcha` 0 : Krt@sha256
ref:     x.x.x.com/ch2 ; U Qarts/testchart@sha256:0f21cda817efc0d415beabc7bc2cf6742814d5f4e924d6b7fe998ca2f3480be1
digest:  85966eb90776e71c4ab72e0abfc70df12276b3201e99e98cb204a9219688af89
size:    77.4 KiB
name:    testchart
version: 1.0.0
Status: Ch/ ! ) ` 6 9 4 { Iart is up to date for x.xk  Z 9.x.com/charts/testchart@sha256:0f21cda817efc0d415beabc7bc2cf6742814d5f4e924d6b7fe998ca2f3480be1

3,根据2的判断,既然能判断本地文件是否是最新,那肯定需要读取本地文件。我们使用stracev + ^ A u A %跟踪下命令的执行,就大概能知道chart文件的存S v + + ?储位置了。

# strace -s 1024 -o 1.loD Y R 9 ; & ^g helm chart puY - I J Dll x.x.x.com/charts/testchart@sha256:0f21cda817efc0d415beabc| J a $ k7bc2cf6742814d5f4e924d6bs n  H | y ~ P U7fe998ca2f34P l 0 I W d80be1
# vim 1.lok H ~ 5 [ u e cg (如下内容为核心需要关注的,忽略无价值的内容)
openat(AT_FDCWD, "/root/.cache/helm/regis/ / Q I u ] c 7 Stry/H ) . 2 ~ +  c YcacT i 9 b z a ]he/indexh _ - = 4 4 &.json", O_RDONLY|O_CLOEXEC) = 6
read(6, "{\"schemaVersion\":2,\"manifests\":[{I - = h 9 p | q y\"mediaType\b x & N 7 { ( { l":\"appl| 7 ~ 2 { Bication/vnd.oci.image/ g 6 R h J D W.manifest.v1+json\",\"digest\":\"sha256:85966eb90776e71c4ab72e0abfc70df12276b3201e99e98cb204a92192 ) w i P C ` $ C688af89\",\"size\":A X C % V + ~ I323,\"annotations\":{\"org.opencontainers.image.ref.name\":\"A r ] a D ]x.x.x.com/charts/testchart:v4.0.7-1\"}},{\"mediaType\":\"a [ % Z Vapplication/vnd.oci.image.manifest.v1+json\",\"digest\"d ~ k:\! t $"sha256V z w . x m G z:0f21cda817efc0d415beabc7bc2cf6742814d5fT G M4e924d6b7fe998ca2f3480beh 4 h @ w ? ) z {1\",\f 6 8 w"size\":323,\"annotaT Z P ~ 9tions\":{\"org.opencontainers.imk i l , kage.ref.naX v s J v 1 7 q }me\":\"xK F u v V Q G 7 m.x.x", 51q + a E w ! u2) = 512
read(6, "x/charts/testchart:v4.0.7-1\"}},{\"mediaType\":\"application/vnd.oci.image.mH , 1 ` [ 0 ) O manifest.v1+json\"a x 1 y t { } u f,\"digest\":\S o k ) Q a"sha256:0f21cda817efc0d415beabc7bc2cf6742814d5f4e924d6b7fe998ca2f3480be1\",\"size\":3v q & m - _ ; o /23,\"annotations\":{\"org.opencontainer9 J ] $ _ o L ` 9s.image.rea u ] 0 jf.name\":\"x.x.x.com/chaE , J @rts/testchart@shf ^  _ x f #a256:0f21cda817efc0d415beabc7bc2cf6742814d5f4e924d6b7f] f z ; j Xe998ca2f3480be1\"}}]}u d L $ l g @", 1024) = 370
openat(A G / G Y 0 s WT_FDCWD, "/root/.cache/helm/registryL V S & W/cache/blobs/sha256/0f21cda817efc0d415beabD { cc7bc2cf6742814d5f4e924d6b7fe998ca2f3480be1", O_RDONLY|O_CLOEXEC) = 6
pread64(6, "{\"sch/ I l u  D 4emaVersion\":2,\"confi@ g t ~ D ng\":{\"mediaType\":\I - @ % E 2"application/vnd.cncf.helm.configB r j `.v1+json\",\"digestm Z y W C Y\":\"sha256:a3bd29841247ececd155 y B t L0763a9a9da5dbdc546f94bc6af7666f37f920317z P P 2 T O qbe1d7\",\"sizeg W G J ! #\":578},\"layers\":[{\"mediaType\":u ~ 4 Z , } v I s\"application/tar+gzip\",\"digest\":\"sha256:76v 7 z l H z ) & Jbee0bf754f2170d18ed( p Eb0032I ^ 0 : 9 A j59a853789fe7b500d2ce3438ec6b] K a C - U  U75faa27289v M U\",\"size\4 V # [ V | k b [":79213}]}", 323, 0) = 323
newfstatat(AT_* J SFDCWD, "/root/.cache/helm/registry/cache/blobs/sha256/76bee0bf754f2170d18edb003259a853789fe7b500d2ce3438ec6b75faa27289", {st_mode=S_IFREG|0444, st_size=79213, ...}, 0) = 0

通过分析1.log文U f e ] e 7件,发现要去加载几个文件。而通过看/root/.cache/helm/registry/cache/blobs/sha256/76bee0bf754f2170d18edb003259a8537g | U89fe7b500d2ce3438ec6b75faa27289这个文件的“z , L |st_size=79213”,~ ! v S /这个size和harbor显示的大小差不多,基本这个就是我们要找的helm chart包了。
4,+ O E S & s验证helm chart包,发现这个hash名字的压缩文件就是我们要找的helm chart包了

[root@_ % c F ~ U % *master1 te( d t O Yst]# cp /root/.cache/helm/registry/cacheX e 8 ] /blobs/shak h ~ * |256/76bee0bf754f2170d18edb003259a853789fe7b500d2ce3438ec6b75] I O f 2 # efaa27289 ./
[root@master1 test]# ls
76bee0bf754f2170d18edb003259a853789fe7b500d2ce3438ec6b75faa27289
[root@master1 test]# tar xf 7S 1 h = E s6bee0bf754f2170d18edb003259a8Q Y ? 0 D Z j ; C53789fe7b500d2ce3438ec6b75faa277 T O i y J 1 P k289
[root@master1 test]# ls
76bee0bf754f2170d18edb003259a853789fe7b500d2ce3438ec6b75faa272* S O a 89  testchart

结论

1,strace依然是神器,多利用
2,通过查helm的官方文档,发现在linux下helF p ]m有三个特殊目录:

  • $HOME/.cache/helm 存放缓存相关,例如元数据信3 . f u & y息和helm chart包等
  • $HOM w 6 q = M r = zME/.conr m W X p .fig/helm 存放helm相关配置,例如harbor这个reQ ! v c C [ f B vgistry的用户名和密码等
  • $HOME/.local/share/helm 存储helm依赖相关数据,例如plD g P @ugin等

目录主要的文件类型/ @ `

  • /p M 0 ^root/.cache/helm/reg` m a w X `istry/cache/index.json 存放helm管理的所有l $ ` 0 5 ~ 3 Q _Helm chart的refs相关信息,每个helm chart包会有一条记录

  • /root/.cacS X 3 5 c v she/helW 0 # f * {m/registry/cache/blobs/sha256/0f21cda817efc0d415beabc7bc2cf6742814d5f4e924d6b7fe998ca2f3480be1 存放对应的的单个helm chart的refs和真实helm chart压缩文件路径等元数p + } . c X M R b据信息。如下H w N v V N J文件样例,layers.digest对应的即为helm chart压缩文件名字。
{"schemaVersion":2,"config":{"mediaType":"appla O Dication/vnd.cncf.helm.config.v1+json","d: Q ` m r I S !igest":"sha256:a3bd29841247ececd150763a9a9da5dbdc546f94b- J l ? f 4 Gc6af7666f37f920317be1d7","sii Z U b e g J N @ze":578},"lay* H M J wers":[Q ] _{"mediaType":"application/tar+gzip","t y vdiC ` . M l [ m TgestS q g `":"sM 8 ^ 9 a w J } gha6 d 0 D256:ad212466aaffd6f34a15* ; ;9f2f5036e9180644a36a825e99f03b745dfd9ce8886g : t b 3 Q P5","size":68351}]}
  • /root/.ca_ j 2 ~ . ] n 3che/helm/registry/cache/blobs/sha256/76bee0bf754f217P * r 9 r %0dN O s x R18edb003259a853789fe7b500d2ce3438ec6b75faa27289 存储helm& * ; Q { S . Q 2 chart的压缩^ V l文件
  • /root/.config/helm/registry.jso _ con 存放harbor ry P _ f $ hegisty用户名和密码

4,目前通过/root/.cache/helm/registry/cache/blobs/sha256/目录中存放的文件能知道对应的heQ # | F L a Wlm chart,但是这个方式有点麻烦。目前,harbor2.x+helm3.x的组合没有找到其他办法,欢迎网友提供更简单有效的方法。
5,生命在于运动,技术在于折腾

参考# h & * X 4 + S文档

https://helm.sh/docs/helm/hF T } felm/
https://goharbor.io/do8 e H . B *cs/2.0.0/working-with-projects/working-with-images/managing-helm-charts/