-
Notifications
You must be signed in to change notification settings - Fork 88
/
version_context.go
99 lines (85 loc) · 2.28 KB
/
version_context.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package template
import (
"text/template"
"github.com/replicatedhq/kots/kotskinds/apis/kots/v1beta1"
)
type VersionInfo struct {
Sequence int64 // the installation sequence. Always 0 when being freshly installed, etc
Cursor string // the upstream version cursor - integers for kots apps, may be semvers for helm charts
ChannelName string // the name of the channel that the current version was from
VersionLabel string // a pretty version label if provided
IsRequired bool // is the version/release required during upgrades or can it be skipped
ReleaseNotes string // the release notes for the given version
IsAirgap bool // is this an airgap app
}
type versionCtx struct {
info *VersionInfo
}
func newVersionCtx(info *VersionInfo) versionCtx {
return versionCtx{info: info}
}
func VersionInfoFromInstallation(sequence int64, isAirgap bool, spec v1beta1.InstallationSpec) VersionInfo {
return VersionInfo{
Sequence: sequence,
Cursor: spec.UpdateCursor,
ChannelName: spec.ChannelName,
VersionLabel: spec.VersionLabel,
IsRequired: spec.IsRequired,
ReleaseNotes: spec.ReleaseNotes,
IsAirgap: isAirgap,
}
}
// FuncMap represents the available functions in the versionCtx.
func (ctx versionCtx) FuncMap() template.FuncMap {
return template.FuncMap{
"Sequence": ctx.sequence,
"Cursor": ctx.cursor,
"ChannelName": ctx.channelName,
"VersionLabel": ctx.versionLabel,
"IsRequired": ctx.isRequired,
"ReleaseNotes": ctx.releaseNotes,
"IsAirgap": ctx.isAirgap,
}
}
func (ctx versionCtx) sequence() int64 {
if ctx.info == nil {
return -1
}
return ctx.info.Sequence
}
func (ctx versionCtx) cursor() string {
if ctx.info == nil {
return ""
}
return ctx.info.Cursor
}
func (ctx versionCtx) channelName() string {
if ctx.info == nil {
return ""
}
return ctx.info.ChannelName
}
func (ctx versionCtx) versionLabel() string {
if ctx.info == nil {
return ""
}
return ctx.info.VersionLabel
}
func (ctx versionCtx) isRequired() bool {
if ctx.info == nil {
return false
}
return ctx.info.IsRequired
}
func (ctx versionCtx) releaseNotes() string {
if ctx.info == nil {
return ""
}
return ctx.info.ReleaseNotes
}
func (ctx versionCtx) isAirgap() bool {
if ctx.info == nil {
return false
}
return ctx.info.IsAirgap
}