---
# System prepended metadata

title: Customize Tanzu Convention Server
tags: [tap]

---

# Customize Tanzu Convention Server
###### tags: `TAP`

## 1. KO 準備
- ko 是一個簡單、快速的 Go 應用程序容器鏡像構建器。
- 它非常適合假如映像包含單個 Go 應用程序而對 OS 基礎映像沒有許多 dependencies 的範例。
- ko 通過在本地機器上有效地執行 go build 來構建 image，因此不需要安裝 docker。
- 這可以使其非常適合輕量級 CI/CD 用例。
- ko 還包括對簡單 YAML 模板的支持，這使其成為 Kubernetes 應用程序的強大工具。
### 安裝 ko 指令 (mac)
```
# via go
go install github.com/google/ko@latest
# via brew
brew install ko
```
### 使用 ko 指令登入 harbor
```shell=
ko login harbor.lab.tw -u admin -p ********
```
### 設定 KO_DOCKER_REPO
```shell=
export KO_DOCKER_REPO=harbor.lab.tw/tim
```

## 2. 建置 Convention Server
### 編譯 go 並打包 image 至 harbor 以及 create resource for K8S
```shell=
ko apply -f server.yaml

2022/12/16 15:37:36 Using base distroless.dev/static:latest@sha256:f9998530e92993931755e4a84a2078ccc2a819d516ddefb66548848f273fb5e0 for github.com/vmware-tanzu/cartographer-conventions/samples/convention-server
2022/12/16 15:37:38 Building github.com/vmware-tanzu/cartographer-conventions/samples/convention-server for linux/amd64
2022/12/16 15:37:39 Publishing harbor.lab.tw/tim/convention-server-2f86e2aac52ba4ca8ea6deaee7465c61:latest
2022/12/16 15:37:40 pushed blob: sha256:24fc58adf805a5ca535937a80102e273a7b725c201f203cd95217545ce4ba13a
2022/12/16 15:37:40 pushed blob: sha256:9a450cec78876e0b649a64a9fd18aaaa63b4c3862e1641eb6ab4fc5c79699539
2022/12/16 15:37:40 harbor.lab.tw/tim/convention-server-2f86e2aac52ba4ca8ea6deaee7465c61:sha256-d659ea2ae7d988b5d328506d4e9b183ca19b14ba7fe762b8398e1ec6763d91c1.sbom: digest: sha256:cab0e0cfe6b17db831318991696a38147f42e7dc2de4d8de04d302e4936c1253 size: 369
2022/12/16 15:37:40 Published SBOM harbor.lab.tw/tim/convention-server-2f86e2aac52ba4ca8ea6deaee7465c61:sha256-d659ea2ae7d988b5d328506d4e9b183ca19b14ba7fe762b8398e1ec6763d91c1.sbom
2022/12/16 15:37:41 pushed blob: sha256:3683de207ee09219c0a03b35e9c7a5c3c190574eaa611a033d23d6f24d91a5ab
2022/12/16 15:37:41 pushed blob: sha256:250c06f7c38e52dc77e5c7586c3e40280dc7ff9bb9007c396e06d96736cf8542
2022/12/16 15:37:43 pushed blob: sha256:9a9dca5cc5f35a206afcb3c9c13fc4c608ed358190f16c56f1172cbd3a37d9b7
2022/12/16 15:37:47 pushed blob: sha256:b817f72898d0934aec8851db0f45368fb48458623375b1d0a38c995b13078316
2022/12/16 15:37:47 harbor.lab.tw/tim/convention-server-2f86e2aac52ba4ca8ea6deaee7465c61:latest: digest: sha256:d659ea2ae7d988b5d328506d4e9b183ca19b14ba7fe762b8398e1ec6763d91c1 size: 1074
2022/12/16 15:37:47 Published harbor.lab.tw/tim/convention-server-2f86e2aac52ba4ca8ea6deaee7465c61@sha256:d659ea2ae7d988b5d328506d4e9b183ca19b14ba7fe762b8398e1ec6763d91c1

namespace/sample-conventions created

issuer.cert-manager.io/selfsigned-issuer created

certificate.cert-manager.io/webhook-cert created

Warning: clusterimagepolicies.signing.apps.tanzu.vmware.com "image-policy" not found. Image policy enforcement was not applied.

deployment.apps/webhook created

service/webhook created

clusterpodconvention.conventions.carto.run/sample created
```
### 確認 Convention Server 已經部署起來
```shell=
k get clusterpodconvention                                                   
NAME                     READY   REASON   AGE
appliveview-sample       True    InSync   31d
developer-conventions    True    InSync   31d
sample                   True    InSync   26s
spring-boot-convention   True    InSync   31d 
```

### 將 image pull secret 新增至 sample-conventions (namespace)
```shell=
# Add new registry for private repo
# tanzu secret registry add registry-credentials --server REGISTRY-SERVER --username REGISTRY-USERNAME --password REGISTRY-PASSWORD --namespace YOUR-NAMESPACE
tanzu secret registry add registry-credentials --server harbor.lab.tw --username "########" --password "********" --namespace sample-conventions
```

### 新增 imagePullSecrets 至 default namespace
```shell=
k -n sample-conventions patch sa default --type merge --patch '{"imagePullSecrets": [{"name": "registry-credentials"}]}'
```

## 3. 測試是否 convention 有成功
```shell=
k create -f workload.yaml -n tap-tim
k get Podintent.v1alpha1.conventions.carto.run sample -n tap-tim -oyaml
k delete Podintent.v1alpha1.conventions.carto.run -n tap-tim sample
```
