Skip to content

Commit 53477c0

Browse files
authored
fix nil (#555)
Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com> Co-authored-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
1 parent 1f36a5c commit 53477c0

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

pkg/module_manager/models/hooks/kind/batch_hook.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,22 +228,42 @@ func (h *BatchHook) GetConfigForModule(_ string) (*config.HookConfig, error) {
228228
}
229229

230230
func (h *BatchHook) GetOnStartup() *float64 {
231+
if h.config == nil || h.config.OnStartup == nil {
232+
return nil
233+
}
234+
231235
res := float64(*h.config.OnStartup)
236+
232237
return &res
233238
}
234239

235240
func (h *BatchHook) GetBeforeAll() *float64 {
241+
if h.config == nil || h.config.OnBeforeHelm == nil {
242+
return nil
243+
}
244+
236245
res := float64(*h.config.OnBeforeHelm)
246+
237247
return &res
238248
}
239249

240250
func (h *BatchHook) GetAfterAll() *float64 {
251+
if h.config == nil || h.config.OnAfterHelm == nil {
252+
return nil
253+
}
254+
241255
res := float64(*h.config.OnAfterHelm)
256+
242257
return &res
243258
}
244259

245260
func (h *BatchHook) GetAfterDeleteHelm() *float64 {
261+
if h.config == nil || h.config.OnAfterDeleteHelm == nil {
262+
return nil
263+
}
264+
246265
res := float64(*h.config.OnAfterDeleteHelm)
266+
247267
return &res
248268
}
249269

pkg/module_manager/models/hooks/kind/gohook.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -198,43 +198,39 @@ func (h *GoHook) GetConfigForModule(_ string) (*config.HookConfig, error) {
198198
}
199199

200200
func (h *GoHook) GetOnStartup() *float64 {
201-
if h.config.OnStartup != nil {
202-
return &h.config.OnStartup.Order
201+
if h.config == nil || h.config.OnStartup == nil {
202+
return nil
203203
}
204204

205-
return nil
205+
return &h.config.OnStartup.Order
206206
}
207207

208208
func (h *GoHook) GetBeforeAll() *float64 {
209-
if h.config.OnBeforeAll != nil {
210-
return &h.config.OnBeforeAll.Order
211-
}
212-
213-
if h.config.OnBeforeHelm != nil {
214-
return &h.config.OnBeforeHelm.Order
209+
if h.config == nil || h.config.OnBeforeAll == nil {
210+
return nil
215211
}
216212

217-
return nil
213+
return &h.config.OnBeforeAll.Order
218214
}
219215

220216
func (h *GoHook) GetAfterAll() *float64 {
221-
if h.config.OnAfterAll != nil {
217+
if h.config != nil && h.config.OnAfterAll != nil {
222218
return &h.config.OnAfterAll.Order
223219
}
224220

225-
if h.config.OnAfterHelm != nil {
221+
if h.config != nil && h.config.OnAfterHelm != nil {
226222
return &h.config.OnAfterHelm.Order
227223
}
228224

229225
return nil
230226
}
231227

232228
func (h *GoHook) GetAfterDeleteHelm() *float64 {
233-
if h.config.OnAfterDeleteHelm != nil {
234-
return &h.config.OnAfterDeleteHelm.Order
229+
if h.config == nil || h.config.OnAfterDeleteHelm == nil {
230+
return nil
235231
}
236232

237-
return nil
233+
return &h.config.OnAfterDeleteHelm.Order
238234
}
239235

240236
func newHookConfigFromGoConfig(input *gohook.HookConfig) (config.HookConfig, error) {

0 commit comments

Comments
 (0)