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:
@@ -73,6 +73,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
opts.specFile = fmt.Sprintf("function-%v.yaml", fnName)
|
||||
}
|
||||
specDir := util.GetSpecDir(input)
|
||||
specIgnore := util.GetSpecIgnore(input)
|
||||
|
||||
if !toSpec {
|
||||
// check for unique function names within a namespace
|
||||
@@ -126,7 +127,8 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
var pkg *fv1.Package
|
||||
|
||||
if toSpec {
|
||||
fr, err := spec.ReadSpecs(specDir)
|
||||
|
||||
fr, err := spec.ReadSpecs(specDir, specIgnore)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("error reading spec in '%v'", specDir))
|
||||
}
|
||||
@@ -166,8 +168,8 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
}
|
||||
|
||||
if toSpec {
|
||||
specDir := util.GetSpecDir(input)
|
||||
fr, err := spec.ReadSpecs(specDir)
|
||||
|
||||
fr, err := spec.ReadSpecs(specDir, specIgnore)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("error reading spec in '%v'", specDir))
|
||||
}
|
||||
|
||||
@@ -134,7 +134,8 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
// For Specs, the spec validate checks for function reference
|
||||
if input.Bool(flagkey.SpecSave) {
|
||||
specDir := util.GetSpecDir(input)
|
||||
fr, err := spec.ReadSpecs(specDir)
|
||||
specIgnore := util.GetSpecIgnore(input)
|
||||
fr, err := spec.ReadSpecs(specDir, specIgnore)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("error reading spec in '%v'", specDir))
|
||||
}
|
||||
|
||||
@@ -66,7 +66,8 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
|
||||
if input.Bool(flagkey.SpecSave) {
|
||||
specDir := util.GetSpecDir(input)
|
||||
fr, err := spec.ReadSpecs(specDir)
|
||||
specIgnore := util.GetSpecIgnore(input)
|
||||
fr, err := spec.ReadSpecs(specDir, specIgnore)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("error reading spec in '%v'", specDir))
|
||||
}
|
||||
|
||||
@@ -127,7 +127,8 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
|
||||
if input.Bool(flagkey.SpecSave) {
|
||||
specDir := util.GetSpecDir(input)
|
||||
fr, err := spec.ReadSpecs(specDir)
|
||||
specIgnore := util.GetSpecIgnore(input)
|
||||
fr, err := spec.ReadSpecs(specDir, specIgnore)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("error reading spec in '%v'", specDir))
|
||||
}
|
||||
|
||||
@@ -86,7 +86,8 @@ func (opts *CreateSubCommand) run(input cli.Input) error {
|
||||
|
||||
if input.Bool(flagkey.SpecSave) {
|
||||
specDir = util.GetSpecDir(input)
|
||||
fr, err := spec.ReadSpecs(specDir)
|
||||
specIgnore := util.GetSpecIgnore(input)
|
||||
fr, err := spec.ReadSpecs(specDir, specIgnore)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("error reading spec in '%v'", specDir))
|
||||
}
|
||||
@@ -185,7 +186,7 @@ func CreatePackage(input cli.Input, client client.Interface, pkgName string, pkg
|
||||
|
||||
if input.Bool(flagkey.SpecSave) {
|
||||
// if a package with the same spec exists, don't create a new spec file
|
||||
fr, err := spec.ReadSpecs(util.GetSpecDir(input))
|
||||
fr, err := spec.ReadSpecs(util.GetSpecDir(input), util.GetSpecIgnore(input))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error reading specs")
|
||||
}
|
||||
|
||||
@@ -161,7 +161,8 @@ func CreateArchive(client client.Interface, input cli.Input, includeFiles []stri
|
||||
}
|
||||
} else if input.Bool(flagkey.SpecSave) {
|
||||
// check if this AUS exists in the specs; if so, don't create a new one
|
||||
fr, err := spec.ReadSpecs(specDir)
|
||||
specIgnore := util.GetSpecIgnore(input)
|
||||
fr, err := spec.ReadSpecs(specDir, specIgnore)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error reading specs")
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ func (opts *ApplySubCommand) do(input cli.Input) error {
|
||||
|
||||
func (opts *ApplySubCommand) run(input cli.Input) error {
|
||||
specDir := util.GetSpecDir(input)
|
||||
specIgnore := util.GetSpecIgnore(input)
|
||||
|
||||
deleteResources := input.Bool(flagkey.SpecDelete)
|
||||
watchResources := input.Bool(flagkey.SpecWatch)
|
||||
@@ -111,7 +112,7 @@ func (opts *ApplySubCommand) run(input cli.Input) error {
|
||||
|
||||
for {
|
||||
// read all specs
|
||||
fr, err := ReadSpecs(specDir)
|
||||
fr, err := ReadSpecs(specDir, specIgnore)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error reading specs")
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ func Commands() *cobra.Command {
|
||||
RunE: wrapper.Wrapper(Validate),
|
||||
}
|
||||
wrapper.SetFlags(validateCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.SpecDir},
|
||||
Optional: []flag.Flag{flag.SpecDir, flag.SpecIgnore},
|
||||
})
|
||||
|
||||
applyCmd := &cobra.Command{
|
||||
@@ -48,7 +48,7 @@ func Commands() *cobra.Command {
|
||||
RunE: wrapper.Wrapper(Apply),
|
||||
}
|
||||
wrapper.SetFlags(applyCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.SpecDir, flag.SpecDelete, flag.SpecWait, flag.SpecWatch, flag.SpecValidation},
|
||||
Optional: []flag.Flag{flag.SpecDir, flag.SpecIgnore, flag.SpecDelete, flag.SpecWait, flag.SpecWatch, flag.SpecValidation},
|
||||
})
|
||||
|
||||
destroyCmd := &cobra.Command{
|
||||
@@ -57,7 +57,7 @@ func Commands() *cobra.Command {
|
||||
RunE: wrapper.Wrapper(Destroy),
|
||||
}
|
||||
wrapper.SetFlags(destroyCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.SpecDir},
|
||||
Optional: []flag.Flag{flag.SpecDir, flag.SpecIgnore},
|
||||
})
|
||||
|
||||
listCmd := &cobra.Command{
|
||||
@@ -66,7 +66,7 @@ func Commands() *cobra.Command {
|
||||
RunE: wrapper.Wrapper(List),
|
||||
}
|
||||
wrapper.SetFlags(listCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.SpecDeployID, flag.SpecDir},
|
||||
Optional: []flag.Flag{flag.SpecDeployID, flag.SpecDir, flag.SpecIgnore},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
|
||||
@@ -38,11 +38,12 @@ func (opts *DestroySubCommand) do(input cli.Input) error {
|
||||
}
|
||||
|
||||
func (opts *DestroySubCommand) run(input cli.Input) error {
|
||||
// get specdir
|
||||
// get specdir and specignore
|
||||
specDir := util.GetSpecDir(input)
|
||||
specIgnore := util.GetSpecIgnore(input)
|
||||
|
||||
// read everything
|
||||
fr, err := ReadSpecs(specDir)
|
||||
fr, err := ReadSpecs(specDir, specIgnore)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error reading specs")
|
||||
}
|
||||
|
||||
@@ -50,9 +50,10 @@ func (opts *ListSubCommand) do(input cli.Input) error {
|
||||
func (opts *ListSubCommand) run(input cli.Input) error {
|
||||
deployID := input.String(flagkey.SpecDeployID)
|
||||
if len(deployID) == 0 {
|
||||
// get specdir and read the deployID
|
||||
// get specdir, specignore and read the deployID
|
||||
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")
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ func SpecSave(resource interface{}, specFile string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
fr, err := ReadSpecs(specDir)
|
||||
fr, err := ReadSpecs(specDir, util.SPEC_IGNORE_FILE)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("error reading spec in '%v'", specDir))
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -77,7 +77,8 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
|
||||
if input.Bool(flagkey.SpecSave) {
|
||||
specDir := util.GetSpecDir(input)
|
||||
fr, err := spec.ReadSpecs(specDir)
|
||||
specIgnore := util.GetSpecIgnore(input)
|
||||
fr, err := spec.ReadSpecs(specDir, specIgnore)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("error reading spec in '%v'", specDir))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user