Skip to content

Commit

Permalink
Fix error handling in to parse ignoreFields (#4295)
Browse files Browse the repository at this point in the history
* Fix error handling

* Add valide function to DriftDetection
  • Loading branch information
funera1 committed Mar 28, 2023
1 parent 8277f58 commit 9a5910b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 0 additions & 3 deletions pkg/app/piped/driftdetector/kubernetes/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@ func (d *detector) checkApplication(ctx context.Context, app *model.Application,
for _, ignoreField := range ddCfg.IgnoreFields {
// ignoreField is 'apiVersion:kind:namespace:name#fieldPath'
splited := strings.Split(ignoreField, "#")
if len(splited) != 2 {
return fmt.Errorf("It should be entered in the form of 'apiVersion:kind:namespace:name#fieldPath'")
}
key, ignoredPath := splited[0], splited[1]
ignoreConfig[key] = append(ignoreConfig[key], ignoredPath)
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/config/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/pipe-cd/pipecd/pkg/model"
)
Expand Down Expand Up @@ -649,6 +650,16 @@ type DriftDetection struct {
IgnoreFields []string `json:"ignoreFields"`
}

func (d *DriftDetection) Validate() error {
for _, ignoreField := range d.IgnoreFields {
splited := strings.Split(ignoreField, "#")
if len(splited) != 2 {
return fmt.Errorf("It should be entered in the form of 'apiVersion:kind:namespace:name#fieldPath'")
}
}
return nil
}

func LoadApplication(repoPath, configRelPath string, appKind model.ApplicationKind) (*GenericApplicationSpec, error) {
var absPath = filepath.Join(repoPath, configRelPath)

Expand Down

0 comments on commit 9a5910b

Please sign in to comment.