feature: Added '--specignore' option to pass file containing specs to be ignored for fission spec commands (#2239)
- New flag `--specignore` has been added for command fission spec [list | validate | apply | destroy] - This flag is optional. - The default spec ignore file name is `.specignore`, if the flag is not used - The spec ignore file existence will be checked in the `--specdir` path - If spec ignore file is passed to the flag, with a name other than .specignore and if it does not exist in the `--specdir` path then an error will be returned. - `--specdir` will be the root path against which the patterns will be evaluated - The behaviour of the spec ignore file will be similar to .gitignore (only for yml and yaml files). For reference: http://git-scm.com/docs/gitignore
This commit is contained in:
@@ -53,7 +53,8 @@ func (opts *ValidateSubCommand) run(input cli.Input) error {
|
||||
|
||||
// this will error on parse errors and on duplicates
|
||||
specDir := util.GetSpecDir(input)
|
||||
fr, err := ReadSpecs(specDir)
|
||||
specIgnore := util.GetSpecIgnore(input)
|
||||
fr, err := ReadSpecs(specDir, specIgnore)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error reading specs")
|
||||
}
|
||||
@@ -197,7 +198,7 @@ func isResourceConflicts(deployUID string, specObj fv1.MetadataAccessor, cluster
|
||||
|
||||
// ReadSpecs reads all specs in the specified directory and returns a parsed set of
|
||||
// fission resources.
|
||||
func ReadSpecs(specDir string) (*FissionResources, error) {
|
||||
func ReadSpecs(specDir, specIgnore string) (*FissionResources, error) {
|
||||
|
||||
// make sure spec directory exists before continue
|
||||
if _, err := os.Stat(specDir); os.IsNotExist(err) {
|
||||
@@ -205,6 +206,11 @@ func ReadSpecs(specDir string) (*FissionResources, error) {
|
||||
"Please check directory path or run \"fission spec init\" to create it.", specDir)
|
||||
}
|
||||
|
||||
ignoreParser, err := util.GetSpecIgnoreParser(specDir, specIgnore)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fr := FissionResources{
|
||||
Packages: make([]fv1.Package, 0),
|
||||
Functions: make([]fv1.Function, 0),
|
||||
@@ -222,7 +228,7 @@ func ReadSpecs(specDir string) (*FissionResources, error) {
|
||||
var result *multierror.Error
|
||||
|
||||
// Users can organize the specdir into subdirs if they want to.
|
||||
err := filepath.Walk(specDir, func(path string, info os.FileInfo, err error) error {
|
||||
err = filepath.Walk(specDir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -232,6 +238,11 @@ func ReadSpecs(specDir string) (*FissionResources, error) {
|
||||
if !(strings.HasSuffix(path, ".yaml") || strings.HasSuffix(path, ".yml")) {
|
||||
return nil
|
||||
}
|
||||
|
||||
if ignoreParser.MatchesPath(path) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// read
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user