-
Notifications
You must be signed in to change notification settings - Fork 88
/
version_context.go
134 lines (117 loc) · 3.69 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package template
import (
"text/template"
"github.com/replicatedhq/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
ReplicatedRegistryDomain string // the custom domain for the replicated registry
ReplicatedProxyDomain string // the custom domain for the replicated proxy
}
type versionCtx struct {
info *VersionInfo
}
func newVersionCtx(info *VersionInfo) versionCtx {
return versionCtx{info: info}
}
func VersionInfoFromInstallationSpec(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,
ReplicatedRegistryDomain: spec.ReplicatedRegistryDomain,
ReplicatedProxyDomain: spec.ReplicatedProxyDomain,
}
}
func InstallationSpecFromVersionInfo(info *VersionInfo) v1beta1.InstallationSpec {
if info == nil {
return v1beta1.InstallationSpec{}
}
return v1beta1.InstallationSpec{
UpdateCursor: info.Cursor,
ChannelName: info.ChannelName,
VersionLabel: info.VersionLabel,
IsRequired: info.IsRequired,
ReleaseNotes: info.ReleaseNotes,
ReplicatedRegistryDomain: info.ReplicatedRegistryDomain,
ReplicatedProxyDomain: info.ReplicatedProxyDomain,
}
}
// 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,
"ReplicatedRegistryDomain": ctx.replicatedRegistryDomain,
"ReplicatedProxyDomain": ctx.replicatedProxyDomain,
}
}
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
}
func (ctx versionCtx) replicatedRegistryDomain() string {
if ctx.info == nil {
return ""
}
return ctx.info.ReplicatedRegistryDomain
}
func (ctx versionCtx) replicatedProxyDomain() string {
if ctx.info == nil {
return ""
}
return ctx.info.ReplicatedProxyDomain
}