Skip to content

Commit

Permalink
Merge pull request #78 from ninech/deploy-jobs-name-validation
Browse files Browse the repository at this point in the history
fix: validate deploy job name
  • Loading branch information
pawelkuc authored Feb 28, 2024
2 parents 7867a7c + 81ab63a commit 5d6e63b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
22 changes: 22 additions & 0 deletions api/validation/config.go
Original file line number Diff line number Diff line change
@@ -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
}
9 changes: 9 additions & 0 deletions create/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions update/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand Down

0 comments on commit 5d6e63b

Please sign in to comment.