helm源码分析-核心数据结构
| 阅读 | 共 1755 字,阅读约
Overview
helm源码分析-核心数据结构
概述
- 包(Chart):表示一个k8s资源包,包括:元信息、默认配置、可选参数、依赖包
- 实例(Release):表示一个chart部署到k8s后的一个实例
- 仓库(File):表示仓库列表信息
- 索引(index):表示一个Chart仓库的索引信息
Chart
pkg/chart/chart.go
1type Chart struct {
2 // 包含了chart包原始文件的内容
3 Raw []*File `json:"-"`
4 // chart包的元信息,具体参考后面的Metadata对象
5 Metadata *Metadata `json:"metadata"`
6 // Chart.lock文件对象
7 Lock *Lock `json:"lock"`
8 // Templates for this chart.
9 Templates []*File `json:"templates"`
10 // 默认配置文件对象,以map形式存储
11 Values map[string]interface{} `json:"values"`
12 // values以json格式序列化的值
13 Schema []byte `json:"schema"`
14 // 其他文件对象,比如:Readme、License等
15 Files []*File `json:"files"`
16
17 // 父chart
18 parent *Chart
19 // 依赖的子chart
20 dependencies []*Chart
21}
File
以key、value形式表示一个chart资源的原生文件名和数据资源
pkg/chart/file.go
1type File struct {
2 // chart包名称
3 Name string `json:"name"`
4 // 数据
5 Data []byte `json:"data"`
6}
Metadata
metadata代表了chart包中的Chart.yaml文件的数据
1type Metadata struct {
2 // chart的名称,必填字段
3 Name string `json:"name,omitempty"`
4 // 项目首页、git仓库或者个人网址
5 Home string `json:"home,omitempty"`
6 // Source is the URL to the source code of this chart
7 Sources []string `json:"sources,omitempty"`
8 // A SemVer 2 conformant version string of the chart. Required.
9 Version string `json:"version,omitempty"`
10 // A one-sentence description of the chart
11 Description string `json:"description,omitempty"`
12 // A list of string keywords
13 Keywords []string `json:"keywords,omitempty"`
14 // A list of name and URL/email address combinations for the maintainer(s)
15 Maintainers []*Maintainer `json:"maintainers,omitempty"`
16 // The URL to an icon file.
17 Icon string `json:"icon,omitempty"`
18 // The API Version of this chart. Required.
19 APIVersion string `json:"apiVersion,omitempty"`
20 // The condition to check to enable chart
21 Condition string `json:"condition,omitempty"`
22 // The tags to check to enable chart
23 Tags string `json:"tags,omitempty"`
24 // The version of the application enclosed inside of this chart.
25 AppVersion string `json:"appVersion,omitempty"`
26 // Whether or not this chart is deprecated
27 Deprecated bool `json:"deprecated,omitempty"`
28 // Annotations are additional mappings uninterpreted by Helm,
29 // made available for inspection by other applications.
30 Annotations map[string]string `json:"annotations,omitempty"`
31 // KubeVersion is a SemVer constraint specifying the version of Kubernetes required.
32 KubeVersion string `json:"kubeVersion,omitempty"`
33 // Dependencies are a list of dependencies for a chart.
34 Dependencies []*Dependency `json:"dependencies,omitempty"`
35 // Specifies the chart type: application or library
36 Type string `json:"type,omitempty"`
37}
Lock
1type Lock struct {
2 // Generated is the date the lock file was last generated.
3 Generated time.Time `json:"generated"`
4 // Digest is a hash of the dependencies in Chart.yaml.
5 Digest string `json:"digest"`
6 // Dependencies is the list of dependencies that this lock file has locked.
7 Dependencies []*Dependency `json:"dependencies"`
8}
Release
pkg/release/release.go
1type Release struct {
2 // release的名称
3 Name string `json:"name,omitempty"`
4
5 // release的基本信息,具体看后面的Info对象
6 Info *Info `json:"info,omitempty"`
7
8 // release对应的chart对象
9 Chart *chart.Chart `json:"chart,omitempty"`
10
11 // 添加到chart中的额外配置,这些值会覆盖默认的配置
12 Config map[string]interface{} `json:"config,omitempty"`
13
14 // 模板渲染之后的k8s资源信息,以字符串形式保存
15 // helm执行安装,其实最终执行的也是调用k8s的api,执行这个menifest文件
16 Manifest string `json:"manifest,omitempty"`
17
18 // 声明的一些钩子信息,用于在helm声明周期的各个阶段插入一些操作
19 Hooks []*Hook `json:"hooks,omitempty"`
20
21 // relase的版本信息
22 Version int `json:"version,omitempty"`
23
24 // release 所属的命名空间
25 Namespace string `json:"namespace,omitempty"`
26
27 // label信息
28 Labels map[string]string `json:"-"`
29}
Info
1
2type Info struct {
3 // release第一次部署的时间
4 FirstDeployed time.Time `json:"first_deployed,omitempty"`
5 // release最后一次部署的时间
6 LastDeployed time.Time `json:"last_deployed,omitempty"`
7 // release被删除的时间
8 Deleted time.Time `json:"deleted"`
9 // 易于人理解的,关于release的描述信息
10 Description string `json:"description,omitempty"`
11 // release的当前状态
12 Status Status `json:"status,omitempty"`
13 // release渲染后的描述信息
14 Notes string `json:"notes,omitempty"`
15}
Status
1// status用字符串表示
2type Status string
3
4// 以下是所有的状态枚举值
5const (
6 // StatusUnknown indicates that a release is in an uncertain state.
7 StatusUnknown Status = "unknown"
8 // StatusDeployed indicates that the release has been pushed to Kubernetes.
9 StatusDeployed Status = "deployed"
10 // StatusUninstalled indicates that a release has been uninstalled from Kubernetes.
11 StatusUninstalled Status = "uninstalled"
12 // StatusSuperseded indicates that this release object is outdated and a newer one exists.
13 StatusSuperseded Status = "superseded"
14 // StatusFailed indicates that the release was not successfully deployed.
15 StatusFailed Status = "failed"
16 // StatusUninstalling indicates that a uninstall operation is underway.
17 StatusUninstalling Status = "uninstalling"
18 // StatusPendingInstall indicates that an install operation is underway.
19 StatusPendingInstall Status = "pending-install"
20 // StatusPendingUpgrade indicates that an upgrade operation is underway.
21 StatusPendingUpgrade Status = "pending-upgrade"
22 // StatusPendingRollback indicates that an rollback operation is underway.
23 StatusPendingRollback Status = "pending-rollback"
24)
25
Hook
1type Hook struct {
2 Name string `json:"name,omitempty"`
3 // Kind is the Kubernetes kind.
4 Kind string `json:"kind,omitempty"`
5 // Path is the chart-relative path to the template.
6 Path string `json:"path,omitempty"`
7 // Manifest is the manifest contents.
8 Manifest string `json:"manifest,omitempty"`
9 // Events are the events that this hook fires on.
10 Events []HookEvent `json:"events,omitempty"`
11 // LastRun indicates the date/time this was last run.
12 LastRun HookExecution `json:"last_run,omitempty"`
13 // Weight indicates the sort order for execution among similar Hook type
14 Weight int `json:"weight,omitempty"`
15 // DeletePolicies are the policies that indicate when to delete the hook
16 DeletePolicies []HookDeletePolicy `json:"delete_policies,omitempty"`
17}
File
File代表一个 repositories.yaml 文件
pkg/repo/repo.go
1type File struct {
2 APIVersion string `json:"apiVersion"`
3 Generated time.Time `json:"generated"`
4 Repositories []*Entry `json:"repositories"`
5}
Entry
1type Entry struct {
2 Name string `json:"name"`
3 URL string `json:"url"`
4 Username string `json:"username"`
5 Password string `json:"password"`
6 CertFile string `json:"certFile"`
7 KeyFile string `json:"keyFile"`
8 CAFile string `json:"caFile"`
9 InsecureSkipTLSverify bool `json:"insecure_skip_tls_verify"`
10}
Index
pkg/repo/index.go
1type IndexFile struct {
2 // This is used ONLY for validation against chartmuseum's index files and is discarded after validation.
3 ServerInfo map[string]interface{} `json:"serverInfo,omitempty"`
4 APIVersion string `json:"apiVersion"`
5 Generated time.Time `json:"generated"`
6 Entries map[string]ChartVersions `json:"entries"`
7 PublicKeys []string `json:"publicKeys,omitempty"`
8
9 // Annotations are additional mappings uninterpreted by Helm. They are made available for
10 // other applications to add information to the index file.
11 Annotations map[string]string `json:"annotations,omitempty"`
12}
13
14type ChartVersions []*ChartVersion
ChartVersion
1type ChartVersion struct {
2 *chart.Metadata
3 URLs []string `json:"urls"`
4 Created time.Time `json:"created,omitempty"`
5 Removed bool `json:"removed,omitempty"`
6 Digest string `json:"digest,omitempty"`
7
8 // ChecksumDeprecated is deprecated in Helm 3, and therefore ignored. Helm 3 replaced
9 // this with Digest. However, with a strict YAML parser enabled, a field must be
10 // present on the struct for backwards compatibility.
11 ChecksumDeprecated string `json:"checksum,omitempty"`
12
13 // EngineDeprecated is deprecated in Helm 3, and therefore ignored. However, with a strict
14 // YAML parser enabled, this field must be present.
15 EngineDeprecated string `json:"engine,omitempty"`
16
17 // TillerVersionDeprecated is deprecated in Helm 3, and therefore ignored. However, with a strict
18 // YAML parser enabled, this field must be present.
19 TillerVersionDeprecated string `json:"tillerVersion,omitempty"`
20
21 // URLDeprecated is deprectaed in Helm 3, superseded by URLs. It is ignored. However,
22 // with a strict YAML parser enabled, this must be present on the struct.
23 URLDeprecated string `json:"url,omitempty"`
24}