diff --git a/cmd/argocd-lovely-plugin/packageDirectories.go b/cmd/argocd-lovely-plugin/packageDirectories.go index b24ec9762..d18493f27 100644 --- a/cmd/argocd-lovely-plugin/packageDirectories.go +++ b/cmd/argocd-lovely-plugin/packageDirectories.go @@ -1,10 +1,12 @@ package main import ( - "github.com/crumbhole/argocd-lovely-plugin/pkg/features" "os" "path/filepath" "regexp" + "strings" + + "github.com/crumbhole/argocd-lovely-plugin/pkg/features" ) // PackageDirectories is an array of sub-application paths @@ -17,6 +19,23 @@ func (d *PackageDirectories) checkFile(path string, info os.DirEntry, err error) if err != nil { return err } + + // Check if path matches any ignored subpaths + ignoreSubpaths, err := features.GetIgnoreSubpaths() + if err != nil { + return err + } + for _, subpath := range ignoreSubpaths { + // Remove any leading "../" from the subpath + for strings.HasPrefix(subpath, "../") { + subpath = subpath[len("../"):] + } + + if strings.Contains(path, filepath.Clean(subpath)) { + return nil // Skip processing if the path matches any ignored subpath + } + } + if !info.IsDir() { yamlRegexp := regexp.MustCompile(features.GetDetectionRegex()) dir := filepath.Dir(path) diff --git a/doc/parameter.md b/doc/parameter.md index ad0b47309..326b1aa36 100644 --- a/doc/parameter.md +++ b/doc/parameter.md @@ -39,6 +39,7 @@ Environment variables, are conventionally ALL_CAPS, and for our purposes | Helmfile Merge | LOVELY_HELMFILE_MERGE | Set to some yaml you'd like [strategic merged](https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/patchesstrategicmerge/) into any helmfile.yaml used by helmfile. | | | Helmfile Patch | LOVELY_HELMFILE_PATCH | to some yaml or json you'd like [json6902](https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/patchesjson6902/) patched into any helmfile.yaml used by Helmfile. | | | Helmfile Template Parameters | LOVELY_HELMFILE_TEMPLATE_PARAMS | Space separated extra parameters to `Helmfile template` as you might use on the command line. You're on your own here if you pass rubbish parameters. | | +| Ignore Subpaths | LOVELY_IGNORE_SUBPATHS | This can come useful when some sub-application is not to be processed by the plugin. This is a space separated list of paths to ignore. | | ## Plugin Name You can set `PLUGIN_NAME` in the environment of the sidecar to override the default name of the plugin. This allows you to supply multiple pre-configured plugins (with different environment, but the same variation). diff --git a/pkg/features/features.go b/pkg/features/features.go index 0ae3508c0..3cb1a4670 100644 --- a/pkg/features/features.go +++ b/pkg/features/features.go @@ -35,8 +35,9 @@ const ( HelmfileMerge HelmfilePatch HelmfileTemplateParams + IgnoreSubpaths FirstFeature = Plugins - LastFeature = HelmfileTemplateParams + LastFeature = IgnoreSubpaths ) // Feature is an individual configurable element of the plugin @@ -172,5 +173,10 @@ func Features() map[FeatureID]Feature { Name: `lovely_helmfile_template_params`, Description: "Space separated extra parameters to `Helmfile template` as you might use on the command line. You're on your own here if you pass rubbish parameters.", }, + IgnoreSubpaths: { + Title: `Ignore Subpaths`, + Name: `lovely_ignore_subpaths`, + Description: "This can come useful when some sub-application is not to be processed by the plugin. This is a space separated list of paths to ignore.", + }, } } diff --git a/pkg/features/getters.go b/pkg/features/getters.go index 13a7891cc..26da02eb4 100644 --- a/pkg/features/getters.go +++ b/pkg/features/getters.go @@ -3,8 +3,9 @@ package features // The control of this is via environment variables, as that // is the way argocd allows you to control plugins import ( - "github.com/crumbhole/argocd-lovely-plugin/pkg/config" "os" + + "github.com/crumbhole/argocd-lovely-plugin/pkg/config" ) // GetPlugins returns the list of plugins to run during the generate phase after main processing @@ -165,3 +166,10 @@ func GetHelmfileTemplateParams() ([]string, error) { f := Features()[HelmfileTemplateParams] return config.GetStringListParam(f.EnvName(), f.DefaultVal, ' ') } + +// GetIgnoreSubpaths returns paths of subapplications to ignore +// Set LOVELY_IGNORE_SUBPATHS to paths of subapplications to ignore +func GetIgnoreSubpaths() ([]string, error) { + f := Features()[IgnoreSubpaths] + return config.GetStringListParam(f.EnvName(), f.DefaultVal, ' ') +}