Skip to content

Commit

Permalink
Adding GetIgnoreSubpaths() getter, updating checkFile()
Browse files Browse the repository at this point in the history
  • Loading branch information
Valkony Balazs (XC/ENG4-Bp) authored and Valkony Balazs (XC/ENG4-Bp) committed Feb 26, 2024
1 parent f200bab commit 33cbd82
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
22 changes: 21 additions & 1 deletion cmd/argocd-lovely-plugin/packageDirectories.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,6 +19,24 @@ 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 {

Check failure on line 28 in cmd/argocd-lovely-plugin/packageDirectories.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary leading newline (whitespace)

// 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)
Expand Down
1 change: 1 addition & 0 deletions doc/parameter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
8 changes: 7 additions & 1 deletion pkg/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ const (
HelmfileMerge
HelmfilePatch
HelmfileTemplateParams
IgnoreSubpaths
FirstFeature = Plugins
LastFeature = HelmfileTemplateParams
LastFeature = IgnoreSubpaths
)

// Feature is an individual configurable element of the plugin
Expand Down Expand Up @@ -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.",
},
}
}
7 changes: 7 additions & 0 deletions pkg/features/getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,10 @@ func GetHelmfileTemplateParams() ([]string, error) {
f := Features()[HelmfileTemplateParams]
return config.GetStringListParam(f.EnvName(), f.DefaultVal, ' ')
}

// GetHelmfileTemplateParams returns extra parameters to pass to helmfile template

Check warning on line 169 in pkg/features/getters.go

View workflow job for this annotation

GitHub Actions / lint

exported: comment on exported function GetIgnoreSubpaths should be of the form "GetIgnoreSubpaths ..." (revive)
// Set LOVELY_HELMFILE_TEMPLATE_PARAMS to extra parameters to pass to helmfile template
func GetIgnoreSubpaths() ([]string, error) {
f := Features()[IgnoreSubpaths]
return config.GetStringListParam(f.EnvName(), f.DefaultVal, ' ')
}

0 comments on commit 33cbd82

Please sign in to comment.