9
9
"strconv"
10
10
"time"
11
11
12
- "github.com/deckhouse/deckhouse/pkg/log"
13
12
"helm.sh/helm/v3/pkg/cli"
14
13
"k8s.io/cli-runtime/pkg/genericclioptions"
15
14
"k8s.io/client-go/rest"
@@ -20,15 +19,17 @@ import (
20
19
"github.com/werf/nelm/pkg/action"
21
20
)
22
21
22
+ // FIXME(nelm): get rid of all globals in Nelm to be able to run them sequentially or in parallel
23
+
23
24
var (
24
25
_ client.HelmClient = & NelmClient {}
25
26
commonOptions * CommonOptions
26
27
)
27
28
28
- func Init (opts * CommonOptions , logger * log. Logger ) error {
29
+ func Init (opts * CommonOptions , logger * NelmLogger ) error {
29
30
getter := buildConfigFlagsFromEnv (& commonOptions .Namespace , cli .New ())
30
31
31
- // XXX : add all other options from getter in the same manner
32
+ // FIXME(addon-operator) : add all other options from getter in the same manner
32
33
if opts .KubeContext == "" && getter .Context != nil {
33
34
opts .KubeContext = * getter .Context
34
35
}
@@ -37,55 +38,48 @@ func Init(opts *CommonOptions, logger *log.Logger) error {
37
38
opts .HelmDriver = os .Getenv ("HELM_DRIVER" )
38
39
}
39
40
40
- // FIXME(ilya-lesikov ): this function does A LOT. And with what addon-operator expects from us
41
+ // FIXME(nelm ): this function does A LOT. And with what addon-operator expects from us
41
42
// in regards to logging, all of this is kind of a mess now
42
- opts . context = action .SetupLogging (context .TODO (), "info" , "" , "off" )
43
+ action .SetupLogging (context .TODO (), "info" , "" , "off" )
43
44
44
45
commonOptions = opts
45
46
46
- versionResult , err := action .Version (commonOptions . context , action.VersionOptions {
47
+ versionResult , err := action .Version (context . TODO () , action.VersionOptions {
47
48
OutputNoPrint : true ,
48
49
})
49
50
if err != nil {
50
51
return fmt .Errorf ("get nelm version: %w" , err )
51
52
}
52
53
53
- logger .Info ("Nelm version" , slog .String ("version" , versionResult .FullVersion ))
54
+ logger .Info (context . TODO (), "Nelm version" , slog .String ("version" , versionResult .FullVersion ))
54
55
55
56
return nil
56
57
}
57
58
58
59
type CommonOptions struct {
59
60
Namespace string
60
61
HistoryMax int32
61
- // XXX: no global timeout in Nelm
62
+ // FIXME(nelm): add global timeout to Nelm actions
62
63
Timeout time.Duration
63
64
HelmDriver string
64
65
KubeContext string
65
- // XXX: add all other options from *genericclioptions.ConfigFlags
66
-
67
- // FIXME(ilya-lesikov): we need a special context with logboek attached to it to be passed to
68
- // Nelm actions to actually log anything
69
- context context.Context
66
+ // FIXME(addon-operator): add all other options from *genericclioptions.ConfigFlags
70
67
}
71
68
72
- func NewNelmClient (logger * log.Logger , labels map [string ]string ) * NelmClient {
73
- logEntry := logger .With ("operator.component" , "nelm" )
74
-
69
+ func NewNelmClient (logger * NelmLogger , labels map [string ]string ) * NelmClient {
75
70
return & NelmClient {
76
- logger : logEntry ,
71
+ logger : logger . With ( "operator.component" , "nelm" ) ,
77
72
labels : labels ,
78
73
}
79
74
}
80
75
81
76
type NelmClient struct {
82
- // FIXME(ilya-lesikov): not gonna be used in Nelm atm
83
- logger * log.Logger
77
+ logger * NelmLogger
84
78
labels map [string ]string
85
79
}
86
80
87
81
func (c * NelmClient ) WithLogLabels (logLabels map [string ]string ) {
88
- c .logger = utils . EnrichLoggerWithLabels ( c .logger , logLabels )
82
+ c .logger = c .logger . EnrichWithLabels ( logLabels )
89
83
}
90
84
91
85
func (c * NelmClient ) WithExtraLabels (labels map [string ]string ) {
@@ -95,13 +89,13 @@ func (c *NelmClient) WithExtraLabels(labels map[string]string) {
95
89
}
96
90
97
91
func (c * NelmClient ) LastReleaseStatus (releaseName string ) (string , string , error ) {
98
- releaseGetResult , err := action .ReleaseGet (commonOptions . context , releaseName , commonOptions .Namespace , action.ReleaseGetOptions {
92
+ releaseGetResult , err := action .ReleaseGet (context . TODO () , releaseName , commonOptions .Namespace , action.ReleaseGetOptions {
99
93
KubeContext : commonOptions .KubeContext ,
100
94
OutputNoPrint : true ,
101
95
ReleaseStorageDriver : commonOptions .HelmDriver ,
102
96
})
103
97
if err != nil {
104
- // FIXME(ilya-lesikov ): return a specific error from ReleaseGet if release not found
98
+ // FIXME(nelm ): return a specific error from ReleaseGet if release not found
105
99
if regexp .MustCompile (`.+release ".+" (namespace ".+") not found` ).Match ([]byte (err .Error ())) {
106
100
return "0" , "" , fmt .Errorf ("get nelm release %q: %w" , releaseName , err )
107
101
}
@@ -113,17 +107,15 @@ func (c *NelmClient) LastReleaseStatus(releaseName string) (string, string, erro
113
107
}
114
108
115
109
func (c * NelmClient ) UpgradeRelease (releaseName string , chartName string , valuesPaths []string , setValues []string , labels map [string ]string , namespace string ) error {
116
- c .logger .Info ("Running nelm install for release" ,
110
+ c .logger .Info (context . TODO (), "Running nelm install for release" ,
117
111
slog .String ("release" , releaseName ),
118
112
slog .String ("chart" , chartName ),
119
113
slog .String ("namespace" , namespace ))
120
114
121
- // XXX: for some reason upgrade was called twice previously?
122
- // XXX: why we always deployed with upg.SkipCRDs = true?
123
- // XXX: Nelm does not care about pending status and will upgrade pending release just fine. Does it mean we are going to be fine without this: https://github.com/flant/addon-operator/blob/b7c97010128922e066fed35e2e53e91834a250de/pkg/helm/helm3lib/helm3lib.go#L293-L300
124
- // FIXME(ilya-lesikov): allow passing labels to Release.Labels
125
- if err := action .ReleaseInstall (commonOptions .context , releaseName , namespace , action.ReleaseInstallOptions {
126
- // XXX: Nelm doesn't allow anything besides chart dir
115
+ // FIXME(nelm): deploy without installing CRDs
116
+ // FIXME(nelm): allow passing labels to Release.Labels
117
+ if err := action .ReleaseInstall (context .TODO (), releaseName , namespace , action.ReleaseInstallOptions {
118
+ // FIXME(nelm): allow passing remote chart path
127
119
ChartDirPath : chartName ,
128
120
ExtraLabels : c .labels ,
129
121
KubeContext : commonOptions .KubeContext ,
@@ -135,7 +127,7 @@ func (c *NelmClient) UpgradeRelease(releaseName string, chartName string, values
135
127
return fmt .Errorf ("install nelm release %q: %w" , releaseName , err )
136
128
}
137
129
138
- c .logger .Info ("Nelm install successful" ,
130
+ c .logger .Info (context . TODO (), "Nelm install successful" ,
139
131
slog .String ("release" , releaseName ),
140
132
slog .String ("chart" , chartName ),
141
133
slog .String ("namespace" , namespace ))
@@ -148,7 +140,7 @@ func (c *NelmClient) GetReleaseValues(releaseName string) (utils.Values, error)
148
140
}
149
141
150
142
func (c * NelmClient ) GetReleaseChecksum (releaseName string ) (string , error ) {
151
- releaseGetResult , err := action .ReleaseGet (commonOptions . context , releaseName , commonOptions .Namespace , action.ReleaseGetOptions {
143
+ releaseGetResult , err := action .ReleaseGet (context . TODO () , releaseName , commonOptions .Namespace , action.ReleaseGetOptions {
152
144
KubeContext : commonOptions .KubeContext ,
153
145
OutputNoPrint : true ,
154
146
ReleaseStorageDriver : commonOptions .HelmDriver ,
@@ -161,25 +153,28 @@ func (c *NelmClient) GetReleaseChecksum(releaseName string) (string, error) {
161
153
return checksum , nil
162
154
}
163
155
164
- // XXX: here was a fallback to get "_addonOperatorModuleChecksum" value from last release values
165
- // instead. In Nelm via action.ReleaseGet we don't expose values of last release, I don't think
166
- // they are relevant when we already expose manifests. Do we really need this?
156
+ // FIXME(nelm): expose Values in ReleaseGetResult and uncomment this
157
+ // if recordedChecksum, hasKey := releaseGetResult.Values["_addonOperatorModuleChecksum"]; hasKey {
158
+ // if recordedChecksumStr, ok := recordedChecksum.(string); ok {
159
+ // return recordedChecksumStr, nil
160
+ // }
161
+ // }
167
162
168
163
return "" , fmt .Errorf ("moduleChecksum label not found in nelm release %q" , releaseName )
169
164
}
170
165
171
166
func (c * NelmClient ) DeleteRelease (releaseName string ) error {
172
- c .logger .Debug ("nelm release: execute nelm uninstall" , slog .String ("release" , releaseName ))
167
+ c .logger .Debug (context . TODO (), "nelm release: execute nelm uninstall" , slog .String ("release" , releaseName ))
173
168
174
- if err := action .ReleaseUninstall (commonOptions . context , releaseName , commonOptions .Namespace , action.ReleaseUninstallOptions {
169
+ if err := action .ReleaseUninstall (context . TODO () , releaseName , commonOptions .Namespace , action.ReleaseUninstallOptions {
175
170
KubeContext : commonOptions .KubeContext ,
176
171
ReleaseHistoryLimit : int (commonOptions .HistoryMax ),
177
172
ReleaseStorageDriver : commonOptions .HelmDriver ,
178
173
}); err != nil {
179
174
return fmt .Errorf ("nelm uninstall release %q: %w" , releaseName , err )
180
175
}
181
176
182
- c .logger .Debug ("nelm release deleted" , slog .String ("release" , releaseName ))
177
+ c .logger .Debug (context . TODO (), "nelm release deleted" , slog .String ("release" , releaseName ))
183
178
184
179
return nil
185
180
}
@@ -198,20 +193,20 @@ func (c *NelmClient) IsReleaseExists(releaseName string) (bool, error) {
198
193
}
199
194
200
195
func (c * NelmClient ) ListReleasesNames () ([]string , error ) {
201
- // FIXME(ilya-lesikov ): not implemented in Nelm actions yet
196
+ // FIXME(nelm ): implement ReleaseList as a Nelm action
202
197
panic ("not implemented yet" )
203
198
}
204
199
205
200
func (c * NelmClient ) Render (releaseName , chartName string , valuesPaths , setValues []string , namespace string , debug bool ) (string , error ) {
206
- // XXX : debug arg is not used now. Nelm doesn't return bad manifests on error, instead it has very verbose trace log level which prints them. Do we really need to dump bad manifests on error?
201
+ // FIXME(nelm) : debug arg is not used now. Nelm doesn't return bad manifests on error, instead it has very verbose trace log level which prints them. Do we really need to dump bad manifests on error?
207
202
208
- c .logger .Debug ("Render nelm templates for chart ..." ,
203
+ c .logger .Debug (context . TODO (), "Render nelm templates for chart ..." ,
209
204
slog .String ("chart" , chartName ),
210
205
slog .String ("namespace" , namespace ))
211
206
212
- // FIXME(ilya-lesikov ): need to return ChartRenderResultV1, like we did in action.ChartRender
213
- err := action .ChartRender (commonOptions . context , action.ChartRenderOptions {
214
- // XXX: only local chart dirs are supported
207
+ // FIXME(nelm ): need to return ChartRenderResultV1, like we did in action.ChartRender
208
+ err := action .ChartRender (context . TODO () , action.ChartRenderOptions {
209
+ // FIXME(nelm): allow passing remote chart path
215
210
ChartDirPath : chartName ,
216
211
ExtraLabels : c .labels ,
217
212
KubeContext : commonOptions .KubeContext ,
@@ -226,9 +221,9 @@ func (c *NelmClient) Render(releaseName, chartName string, valuesPaths, setValue
226
221
return "" , fmt .Errorf ("render nelm chart %q: %w" , chartName , err )
227
222
}
228
223
229
- c .logger .Info ("Render nelm templates for chart was successful" , slog .String ("chart" , chartName ))
224
+ c .logger .Info (context . TODO (), "Render nelm templates for chart was successful" , slog .String ("chart" , chartName ))
230
225
231
- // FIXME(ilya-lesikov ): we should return manifests from ChartRenderResultV1
226
+ // FIXME(nelm ): we should return manifests from ChartRenderResultV1
232
227
panic ("not implemented yet" )
233
228
}
234
229
0 commit comments