Skip to content

Commit 8663326

Browse files
committed
add optional versioning of charts
1 parent 1c4a37f commit 8663326

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Here's an example of a project's configuration file:
6464
```yaml
6565
apiVersion: v1
6666
charts:
67-
stable/factorio:
67+
stable/factorio:0.2.0:
6868
resources:
6969
requests:
7070
memory: 1024Mi
@@ -86,6 +86,9 @@ For the above example, see here for the default configurations:
8686
* stable/factorio: https://git.io/v9Tyr
8787
* stable/minecraft: https://git.io/v9Tya
8888
89+
You can optionally pin your chart to a specific version, by appending `:x.y.z`
90+
to the chart name.
91+
8992
The Chart Configuration file can also contain templated language which is
9093
processed by [epp](https://github.com/blendle/epp).
9194

parser/chart.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,18 @@ func (c *Chart) ToResources(name, namespace string) ([]byte, error) {
5353
return nil, err
5454
}
5555

56-
resources, err := chartToResources(c.Location, name, namespace, tmpfile.Name())
56+
resources, err := chartToResources(c.Location, c.Version, name, namespace, tmpfile.Name())
5757
if err != nil {
5858
return nil, err
5959
}
6060

6161
return resources, nil
6262
}
6363

64-
func chartToResources(location, releaseName, namespace, values string) ([]byte, error) {
64+
func chartToResources(location, version, releaseName, namespace, values string) ([]byte, error) {
6565
var output string
6666

67-
location, err := locateChartPath(location, "")
67+
location, err := locateChartPath(location, version)
6868
if err != nil {
6969
return nil, err
7070
}

parser/config.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package parser
22

33
import (
44
"errors"
5+
"strings"
56

7+
"github.com/Masterminds/semver"
68
"github.com/blendle/epp/epp"
79
"github.com/blendle/kubecrt/config"
810
yaml "gopkg.in/yaml.v2"
@@ -19,6 +21,7 @@ type ChartsConfiguration struct {
1921
// Chart ...
2022
type Chart struct {
2123
Location string
24+
Version string
2225
Config interface{}
2326
}
2427

@@ -71,10 +74,19 @@ func NewChartsConfiguration(m map[string]interface{}, opts *config.ChartsConfigO
7174

7275
charts, _ = m["charts"].(map[interface{}]interface{})
7376
for key, config := range charts {
74-
location, _ := key.(string)
77+
var version, location string
78+
79+
s, _ := key.(string)
80+
p := strings.Split(s, ":")
81+
location = p[0]
82+
if len(p) > 1 {
83+
version, p = p[len(p)-1], p[:len(p)-1]
84+
location = strings.Join(p, ":")
85+
}
7586

7687
c := &Chart{
7788
Location: location,
89+
Version: version,
7890
Config: config,
7991
}
8092

@@ -118,6 +130,12 @@ func validateConfig(cc *ChartsConfiguration) error {
118130
if c.Location == "" {
119131
return errors.New("Invalid or missing chart name")
120132
}
133+
134+
if c.Version != "" {
135+
if _, err := semver.NewVersion(c.Version); err != nil {
136+
return errors.New(c.Version + ": " + err.Error())
137+
}
138+
}
121139
}
122140

123141
return nil

0 commit comments

Comments
 (0)