MCPcopy Create free account
hub / github.com/devspace-sh/devspace / validateHooks

Function validateHooks

pkg/devspace/config/versions/validate.go:199–252  ·  view source on GitHub ↗
(config *latest.Config)

Source from the content-addressed store, hash-verified

197}
198
199func validateHooks(config *latest.Config) error {
200 for index, hookConfig := range config.Hooks {
201 if len(hookConfig.Events) == 0 {
202 return errors.Errorf("hooks[%d].events is required", index)
203 }
204 if hookConfig.Command == "" && hookConfig.Upload == nil && hookConfig.Download == nil && hookConfig.Logs == nil && hookConfig.Wait == nil {
205 return errors.Errorf("hooks[%d].command, hooks[%d].logs, hooks[%d].wait, hooks[%d].download or hooks[%d].upload is required", index, index, index, index, index)
206 }
207 enabled := 0
208 if hookConfig.Command != "" {
209 enabled++
210 }
211 if hookConfig.Download != nil {
212 enabled++
213 }
214 if hookConfig.Upload != nil {
215 enabled++
216 }
217 if hookConfig.Logs != nil {
218 enabled++
219 }
220 if hookConfig.Wait != nil {
221 enabled++
222 }
223 if enabled > 1 {
224 return errors.Errorf("you can only use one of hooks[%d].command, hooks[%d].logs, hooks[%d].wait, hooks[%d].upload and hooks[%d].download per hook", index, index, index, index, index)
225 }
226 if hookConfig.Upload != nil && hookConfig.Container == nil {
227 return errors.Errorf("hooks[%d].container is required if hooks[%d].upload is used", index, index)
228 }
229 if hookConfig.Download != nil && hookConfig.Container == nil {
230 return errors.Errorf("hooks[%d].container is required if hooks[%d].download is used", index, index)
231 }
232 if hookConfig.Logs != nil && hookConfig.Container == nil {
233 return errors.Errorf("hooks[%d].container is required if hooks[%d].logs is used", index, index)
234 }
235 if hookConfig.Wait != nil && hookConfig.Container == nil {
236 return errors.Errorf("hooks[%d].container is required if hooks[%d].wait is used", index, index)
237 }
238 if hookConfig.Wait != nil && !hookConfig.Wait.Running && hookConfig.Wait.TerminatedWithCode == nil {
239 return errors.Errorf("hooks[%d].wait.running or hooks[%d].wait.terminatedWithCode is required if hooks[%d].wait is used", index, index, index)
240 }
241 if hookConfig.Container != nil {
242 if hookConfig.Container.ContainerName != "" && len(hookConfig.Container.LabelSelector) == 0 {
243 return errors.Errorf("hooks[%d].container.containerName is defined but hooks[%d].container.labelSelector is not defined", index, index)
244 }
245 if len(hookConfig.Container.LabelSelector) == 0 && hookConfig.Container.ImageSelector == "" {
246 return errors.Errorf("hooks[%d].container.labelSelector and hooks[%d].container.imageSelector are not defined", index, index)
247 }
248 }
249 }
250
251 return nil
252}
253
254func validateDeployments(config *latest.Config) error {
255 for index, deployConfig := range config.Deployments {

Callers 2

ValidateFunction · 0.85
TestValidateHooksFunction · 0.85

Calls 1

ErrorfMethod · 0.45

Tested by 1

TestValidateHooksFunction · 0.68