diff --git a/api/validation/config.go b/api/validation/config.go new file mode 100644 index 0000000..9131978 --- /dev/null +++ b/api/validation/config.go @@ -0,0 +1,22 @@ +package validation + +import ( + "errors" + + apps "github.com/ninech/apis/apps/v1alpha1" +) + +// ConfigValidator validates a Config +type ConfigValidator struct { + Config apps.Config +} + +// Validate validates the config +func (c ConfigValidator) Validate() error { + if c.Config.DeployJob != nil { + if len(c.Config.DeployJob.Name) == 0 { + return errors.New("deploy job name cannot be empty") + } + } + return nil +} diff --git a/create/application.go b/create/application.go index df355b4..ca97ae4 100644 --- a/create/application.go +++ b/create/application.go @@ -149,6 +149,15 @@ func (app *applicationCmd) Run(ctx context.Context, client *api.Client) error { } } + if newApp.Spec.ForProvider.Config.DeployJob != nil { + configValidator := &validation.ConfigValidator{ + Config: newApp.Spec.ForProvider.Config, + } + if err := configValidator.Validate(); err != nil { + return fmt.Errorf("error when validating application config: %w", err) + } + } + c := newCreator(client, newApp, strings.ToLower(apps.ApplicationKind)) appWaitCtx, cancel := context.WithTimeout(ctx, app.WaitTimeout) defer cancel() diff --git a/update/application.go b/update/application.go index 62dafb1..716378c 100644 --- a/update/application.go +++ b/update/application.go @@ -140,6 +140,15 @@ func (cmd *applicationCmd) Run(ctx context.Context, client *api.Client) error { } } + if app.Spec.ForProvider.Config.DeployJob != nil { + configValidator := &validation.ConfigValidator{ + Config: app.Spec.ForProvider.Config, + } + if err := configValidator.Validate(); err != nil { + return fmt.Errorf("error when validating application config: %w", err) + } + } + return nil })