-
Notifications
You must be signed in to change notification settings - Fork 3
/
version.go
52 lines (44 loc) · 1.15 KB
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package chart
import (
"io/ioutil"
"gopkg.in/yaml.v2"
)
// Version represents the value type for the chart version enum.
type Version int
const (
// V01 is the previous chart version for developing on the backend-specific infrastructure.
V01 Version = iota
// V9 is the latest chart version for developing on the backend-specific infrastructure.
V9
// VUnknown is an unknown chart version type.
VUnknown
)
// ReadVersionFile loads a version file from disk.
func ReadVersionFile(filename string) (VersionFile, error) {
var vf VersionFile
raw, err := ioutil.ReadFile(filename)
if err != nil {
return vf, err
}
if err := yaml.Unmarshal(raw, &vf); err != nil {
return vf, err
}
return vf, nil
}
// VersionFile represents the file structure of a chart file only with version.
type VersionFile struct {
ChartVersion string `yaml:"chartVersion"`
}
// Version returns the correct version to be using.
func (f VersionFile) Version() Version {
return f.parseVersion(f.ChartVersion)
}
func (f VersionFile) parseVersion(version string) Version {
switch version {
case "0.1.0":
return V01
case "9.0.0-stable", "9.0.0":
return V9
}
return VUnknown
}