某客户准备修改 CI/CD 流程中原有的 公网 ip 地址为 弹性ip,想了解涉及修改的各个方面,告知客户有如下地方会有改动( 原有流水线的自动触发、 harbor上对应的webhook、制品仓库对应的webhook、gitlab这边的webhook),
经过简单演示,发现难点是 gitlab 这边如何批量更换新的 webhook 地址,所有应用全部手动点一圈显然比较繁琐,于是有了下面的测试。
通过模拟环境,检查发现这些 webhook 地址是以数据的形式存放在 gitlab对应的postgres数据库里面。
对应的数据库为 gitlabhq_production,表为 web_hooks,还有一个表 web_hook_logs 是存放webhook相关的历史记录等完整信息。
kubectl get po -n 某名字ns
kubectl exec -it -n 某名字ns gitlab-postgresql-6995884f-dl92s sh
换用户# su - postgres# 数据备份postgres@gitlab-postgresql-6995884f-dl92s:~$ pg_dump gitlabhq_production > gitlab.sql# 查看备份postgres@gitlab-postgresql-6995884f-dl92s:~$ ls -lhtotal 472Kdrwx------ 3 postgres postgres 18 Apr 29 2020 10-rw-rw-r-- 1 postgres postgres 461K May 8 16:24 gitlab.sql# 另一个终端,将 sql 备份文件拷贝到本地kubectl cp 某名字ns/gitlab-postgresql-6995884f-dl92s:gitlab.sql /root/gitlab.sql# 进入psql命令模式postgres@gitlab-postgresql-6995884f-dl92s:~$ psqlpsql (10.4 (Ubuntu 10.4-2.pgdg18.04+1))Type "help" for help.postgres=# \xExpanded display is on.# 查数据列表postgres=# \lList of databases-[ RECORD 1 ]-----+----------------------Name | gitlabhq_productionOwner | postgresEncoding | UTF8Collate | CCtype | CAccess privileges | =Tc/postgres + | postgres=CTc/postgres+ | gitlab=CTc/postgres# 换库postgres=# \c gitlabhq_production;# 查询记录gitlabhq_production=# select * from web_hooks;-[ RECORD 1 ]--------------+-----------------------------------------------------------------id | 4url | http://10.23.5.53:8089/hook/28a369a1-17f9-4b98-b766-439df6d1c6b3project_id | 2created_at | 2021-05-07 17:44:52.392552updated_at | 2021-05-07 17:44:52.392552type | ProjectHookservice_id |push_events | tissues_events | fmerge_requests_events | ttag_push_events | tnote_events | fenable_ssl_verification | fwiki_page_events | ftoken | aec78a4e-dc82-4f3c-be84-7415dc57349dpipeline_events | fconfidential_issues_events | frepository_update_events | fjob_events | fconfidential_note_events |-[ RECORD 2 ]--------------+-----------------------------------------------------------------id | 5url | http://10.23.5.53:8089/hook/e0e9dec8-915a-4eff-972c-89de9094046aproject_id | 4created_at | 2021-05-08 10:23:23.036441updated_at | 2021-05-08 10:23:23.036441type | ProjectHookservice_id |push_events | tissues_events | fmerge_requests_events | ttag_push_events | tnote_events | fenable_ssl_verification | fwiki_page_events | ftoken | cfc46dc9-faed-434a-88f4-c6113e9f9a2epipeline_events | fconfidential_issues_events | frepository_update_events | fjob_events | fconfidential_note_events | |
# 单个替换 url,简单将8089端口替换为8088
UPDATE 1 |
图这里忽略,也就是 http://10.23.5.53:8089修改为 http://10.23.5.53:8088
# 进入数据库容器kubectl exec -it -n 某名字ns gitlab-postgresql-6995884f-dl92s sh# 换用户# su - postgres# 换库postgres=# \c gitlabhq_production;# 查询记录gitlabhq_production=# select * from web_hooks;# 替换url地址gitlabhq_production=# UPDATE web_hooks SET url = replace (url,'10.23.5.53:8089','10.23.5.53:8088');UPDATE 2# 再次查询记录gitlabhq_production=# select * from web_hooks; |
修改前 端口8089


修改后,端口8088,符合预期


点击test,测试效果


hook execution successfully : http 200
输出hook 正常,符合预期。
ps. 如果异常,这里会返回提示连接拒绝
Hook execution failed: Failed to open TCP connection to 10.23.5.53:8088 (Connection refused - connect(2) for "10.23.5.53" port 8088)
调度
CI/CD 跑流水线,制品仓库是否有正常推送的制品。
镜像拉取测试正常
至此gitlab 下 webhook 批量修改成功,验证通过。
本文为12月第二周网站忘记续费后从webcache里面找回的
2022-05-10,有人问起,原来内网还写了一篇,有图,哈哈,补上。

文章评论