This repository has been archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
/
chart.go
52 lines (41 loc) · 1.56 KB
/
chart.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 application
import (
"k8s.io/helm/pkg/repo"
shipper "github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1"
shipperrepo "github.com/bookingcom/shipper/pkg/chart/repo"
)
func ChartVersionResolved(app *shipper.Application) bool {
chartspec := app.Spec.Template.Chart
resVer, ok := app.Annotations[shipper.AppChartVersionResolvedAnnotation]
if !ok || resVer != chartspec.Version {
return false
}
chartName, ok := app.Annotations[shipper.AppChartNameAnnotation]
if !ok || chartName != chartspec.Name {
return false
}
return true
}
// This function modifies app object and populates it's annotations.
// The changes are not saved immediately and are delegated to the caller.
func ResolveChartVersion(app *shipper.Application, resolver shipperrepo.ChartVersionResolver) (*repo.ChartVersion, error) {
cv, err := resolver(&app.Spec.Template.Chart)
if err != nil {
return nil, err
}
rawVer := app.Spec.Template.Chart.Version
app.Spec.Template.Chart.Version = cv.Version
UpdateChartNameAnnotation(app, cv.Name)
UpdateChartVersionResolvedAnnotation(app, cv.Version)
UpdateChartVersionRawAnnotation(app, rawVer)
return cv, nil
}
func UpdateChartNameAnnotation(app *shipper.Application, name string) {
app.Annotations[shipper.AppChartNameAnnotation] = name
}
func UpdateChartVersionResolvedAnnotation(app *shipper.Application, version string) {
app.Annotations[shipper.AppChartVersionResolvedAnnotation] = version
}
func UpdateChartVersionRawAnnotation(app *shipper.Application, version string) {
app.Annotations[shipper.AppChartVersionRawAnnotation] = version
}