简体   繁体   English

如何从命令行更新 Helm Chart.yaml

[英]How to update Helm Chart.yaml from command line

I'm looking to dynamically update my Chart.yaml file specifically the version when I run a make helm build command.我希望动态更新我的Chart.yaml文件,特别是运行 make helm build 命令时的版本。

For example Chart.yaml contains例如 Chart.yaml 包含

apiVersion: v1
appVersion "1.0"
description: A helm chart for so and so
name: my app
version: 0.2

I'm looking for a way to run make helm build version=0.3 and when that build is complete see the updated version number in that builds Chart.yaml我正在寻找一种运行make helm build version=0.3的方法,当构建完成时,请查看构建Chart.yaml中的更新版本号

It's my understanding I can't pass variables to.yaml files so not sure if this is possible?据我了解,我无法将变量传递给 .yaml 文件,所以不确定这是否可能?

First of all your Chart.yaml is not valid YAML, you need to insert a value separator ( : ) before "1.0" on the second line. 首先你Chart.yaml无效YAML,你需要插入值分隔符( :前) "1.0"在第二行。

Assuming your Makefile looks like: 假设你的Makefile看起来像:

helm:
        python3 updateversion.py Chart.yaml ${version}
        cat Chart.yaml

, ruamel.yaml is installed for your Python3 and your updateversion.py : ruamel.yaml安装了您的Python3和你updateversion.py

import sys
from pathlib import Path
import ruamel.yaml

yaml_file = Path(sys.argv[1])

yaml = ruamel.yaml.YAML()
yaml.preserve_quotes = True
# uncomment and adapt next line in case defaults don't match your indentation
# yaml.indent(mapping=4, sequence=4, offset=2)

data = yaml.load(yaml_file)
version = sys.argv[2]
if isinstance(data['version'], float):
    version = float(version)
data['version'] = version

yaml.dump(data, yaml_file)

you can run make helm version=0.3 to get output: 你可以运行make helm version=0.3来获得输出:

apiVersion: v1
appVersion: "1.0"
description: A helm chart for so and so
name: my app
version: 0.3

The trick with testing value for version being a float is necessary as 0.2 is a float when loading YAML, but 0.2.1 is a string. version为float的测试值的技巧是必要的,因为0.2是加载YAML时的浮点数,但0.2.1是一个字符串。 And what you get from the commandline using sys.argv[2] is always a string. 而使用sys.argv[2]获得的内容总是一个字符串。

You can replace the cat Chart.yaml line for the target helm with whatever you need to run with the updated file. 您可以将目标helmcat Chart.yaml行替换为您需要使用更新文件运行的任何内容。

Helm package has a --version argument Helm package 有一个--version参数

Run helm package --version 1.2.3.helm/package_name运行helm package --version 1.2.3.helm/package_name

  • This won't help you modify the Chart.yaml , it creates a Chart archive file instead.这不会帮助您修改Chart.yaml ,而是创建一个图表存档文件。
  • For more information, take a look at helm package --help .有关更多信息,请查看helm package --help

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM