26.2. 运行 Helm chart-verifier 工具
执行 chart-verifier 工具的建议目录结构如下:
.
└── src
├── Chart.yaml
├── README.md
├── templates
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── hpa.yaml
│ ├── ingress.yaml
│ ├── NOTES.txt
│ ├── serviceaccount.yaml
│ ├── service.yaml
│ └── tests
│ └── test-connection.yaml
├── values.schema.json
└── values.yaml
先决条件
- 安装 Podman 或 Docker CLI 的容器引擎。
- 互联网连接,以检查镜像是否经过红帽认证。
- GitHub 配置集,将 chart 提交到 OpenShift Helm Charts 仓库。
- Red Hat OpenShift Container Platform 集群。
在运行 chart-verifier 工具前,使用以下命令打包 Helm Chart:
$ helm package <helmchart folder>此命令将归档您的 Helm Chart,并将其转换为
.tgz文件格式。
步骤
您可以使用两种方法运行一组 chart-verifier 工具:
26.2.1. 使用 Podman 或 Docker 复制链接链接已复制到粘贴板!
使用通用资源标识符(uri)远程运行可用 chart 的所有可用检查,假设 kube 配置文件位于位置
${HOME}/.kube :$ podman run --rm -i \ -e KUBECONFIG=/.kube/config \ -v "${HOME}/.kube":/.kube \ "quay.io/redhat-certification/chart-verifier" \ verify \ <chart-uri>在这个命令中,图表是 https uri 上可用的 Chart 存档的位置。确保存档必须采用
.tgz格式。在您的系统中本地运行所有可用检查,假设 chart 在当前目录中可用,并且 kube 配置文件位于
${HOME}/.kube的位置:$ podman run --rm \ -e KUBECONFIG=/.kube/config \ -v "${HOME}/.kube":/.kube \ -v $(pwd):/charts \ "quay.io/redhat-certification/chart-verifier" \ verify \ /charts/<chart>在这个命令中,chart-uri 是您的本地目录中提供的 chart 归档的位置。确保存档必须采用
.tgz格式。运行以下命令,以获取与命令关联的可用选项及其用法:
$ podman run -it --rm quay.io/redhat-certification/chart-verifier verify --help命令的输出类似以下示例:
Verifies a Helm chart by checking some of its characteristics Usage: chart-verifier verify <chart-uri> [flags] Flags: -S, --chart-set strings set values for the chart (can specify multiple or separate values with commas: key1=val1,key2=val2) -G, --chart-set-file strings set values from respective files specified via the command line (can specify multiple or separate values with commas: key1=path1,key2=path2) -X, --chart-set-string strings set STRING values for the chart (can specify multiple or separate values with commas: key1=val1,key2=val2) -F, --chart-values strings specify values in a YAML file or a URL (can specify multiple) --debug enable verbose output -x, --disable strings all checks will be enabled except the informed ones -e, --enable strings only the informed checks will be enabled --helm-install-timeout duration helm install timeout (default 5m0s) -h, --help help for verify --kube-apiserver string the address and the port for the Kubernetes API server --kube-as-group stringArray group to impersonate for the operation, this flag can be repeated to specify multiple groups. --kube-as-user string username to impersonate for the operation --kube-ca-file string the certificate authority file for the Kubernetes API server connection --kube-context string name of the kubeconfig context to use --kube-token string bearer token used for authentication --kubeconfig string path to the kubeconfig file -n, --namespace string namespace scope for this request -V, --openshift-version string set the value of certifiedOpenShiftVersions in the report -o, --output string the output format: default, json or yaml -k, --pgp-public-key string file containing gpg public key of the key used to sign the chart -W, --web-catalog-only set this to indicate that the distribution method is web catalog only (default: true) --registry-config string path to the registry config file (default "/home/baiju/.config/helm/registry.json") --repository-cache string path to the file containing cached repository indexes (default "/home/baiju/.cache/helm/repository") --repository-config string path to the file containing repository names and URLs (default "/home/baiju/.config/helm/repositories.yaml") -s, --set strings overrides a configuration, e.g: dummy.ok=false -f, --set-values strings specify application and check configuration values in a YAML file or a URL (can specify multiple) -E, --suppress-error-log suppress the error log (default: written to ./chartverifier/verifier-<timestamp>.log) --timeout duration time to wait for completion of chart install and test (default 30m0s) -w, --write-to-file write report to ./chartverifier/report.yaml (default: stdout) Global Flags: --config string config file (default is $HOME/.chart-verifier.yaml)运行检查的子集:
$ podman run --rm -i \ -e KUBECONFIG=/.kube/config \ -v "${HOME}/.kube":/.kube \ "quay.io/redhat-certification/chart-verifier" \ verify -enable images-are-certified,helm-lint \ <chart-uri>运行除子集之外的所有检查:
$ podman run --rm -i \ -e KUBECONFIG=/.kube/config \ -v "${HOME}/.kube":/.kube \ "quay.io/redhat-certification/chart-verifier" \ verify -disable images-are-certified,helm-lint \ <chart-uri>注意运行检查子集旨在减少开发的反馈循环。要认证您的图表,您必须运行所有必要的检查。
提供 chart-override 值:
$ podman run --rm -i \ -e KUBECONFIG=/.kube/config \ -v "${HOME}/.kube":/.kube \ "quay.io/redhat-certification/chart-verifier" \ verify –chart-set default.port=8080 \ <chart-uri>从当前目录中的文件提供 chart-override 值:
$ podman run --rm -i \ -e KUBECONFIG=/.kube/config \ -v "${HOME}/.kube":/.kube \ -v $(pwd):/values \ "quay.io/redhat-certification/chart-verifier" \ verify –chart-values /values/overrides.yaml \ <chart-uri>
26.2.1.1. 配置 timeout 选项 复制链接链接已复制到粘贴板!
如果 chart-testing 进程延迟,请增加超时值。默认情况下,图表测试过程需要大约 30 分钟才能完成。
$ podman run --rm -i \
-e KUBECONFIG=/.kube/config \
-v "${HOME}/.kube":/.kube \
-v $(pwd):/values \
"quay.io/redhat-certification/chart-verifier" \
verify --timeout 40m \
<chart-uri>
如果您在 Chart 测试过程中观察到延迟,红帽建议您向红帽认证团队提交报告进行验证。
26.2.1.2. 保存报告 复制链接链接已复制到粘贴板!
当 chart 测试过程完成后,报告信息会被默认显示。您可以通过将报告重定向到文件来保存报告。
例如:
$ podman run --rm -i \
-e KUBECONFIG=/.kube/config \
-v "${HOME}/.kube":/.kube \
"quay.io/redhat-certification/chart-verifier" \
verify –enable images-are-certified,helm-lint \
<chart-uri> > report.yaml
除了这个命令,使用 a -w 选项将报告直接写入文件 ./chartverifier/report.yaml。若要获取此文件,您必须对文件进行卷挂载至 /app/chartverifer。
例如:
$ podman run --rm -i \
-e KUBECONFIG=/.kube/config \
-v "${HOME}/.kube":/.kube \
-v $(pwd)/chartverifier:/app/chartverifier \
-w \
"quay.io/redhat-certification/chart-verifier" \
verify –enable images-are-certified,helm-lint \
<chart-uri>
如果文件已存在,新报告会覆盖该文件。
26.2.1.3. 配置错误日志 复制链接链接已复制到粘贴板!
默认情况下,生成错误日志并保存到文件 ./chartverifier/verify-<timestamp>.yaml 中。它包括错误消息、每个检查的结果以及有关 Chart 测试的附加信息。要获得错误日志的副本,您必须挂载卷到 /app/chartverifer。
例如:
$ podman run --rm -i \
-e KUBECONFIG=/.kube/config \
-v "${HOME}/.kube":/.kube \
-v $(pwd)/chartverifier:/app/chartverifier \
"quay.io/redhat-certification/chart-verifier" \
verify –enable images-are-certified,helm-lint \
<chart-uri> > report.yaml
如果要将多个日志存储到同一目录中,您可以一次存储最多 10 个日志文件。当达到最大文件限制时,旧的日志文件会自动替换为较新的日志文件。
使用 -E or -suppress-error-log 选项来限制错误日志输出。
错误和警告消息是标准错误输出信息,无法使用 -E or -suppress-error-log 选项阻止。
26.2.2. 使用二进制文件 复制链接链接已复制到粘贴板!
这个方法只适用于 Linux 系统。
- 从版本页面中下载并安装最新的 chart-verifier 二进制文件。https://github.com/redhat-certification/chart-verifier/releases
使用以下命令解压 tarball 二进制文件:
$ tar zxvf <tarball>在 unzipped 目录中运行以下命令执行所有 Helm Chart 检查:
$ ./chart-verifier verify <chart-uri>在这个命令中,
chart-uri是服务器上可用的 Chart 存档的位置。确保存档必须采用.tgz格式。默认情况下,chart-verifier 工具假定 kube 配置文件位于默认位置$HOME/.kube。如果文件在默认位置不可用,请将环境变量设置为KUBECONFIG。chart-verifier 的输出包括执行的测试详情以及每个测试的结果状态。它还指明每个测试对于红帽认证是否是必需的或推荐。如需更多信息,请参阅 Helm Chart 检查的类型。