Skip to content

Commit

Permalink
Implement kustomizeOptions
Browse files Browse the repository at this point in the history
Allows passing flags equivalent to `--enable-helm` via the
environment variable `POLICY_GEN_ENABLE_HELM`

ref: https://issues.redhat.com/browse/ACM-9060
Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com>
  • Loading branch information
dhaiducek committed Jan 16, 2024
1 parent cea7921 commit b3ad200
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ make build
kustomize build --enable-alpha-plugins
```

**NOTE:** To enable Helm processing when passing a Kustomize directory into the generator, set
the environment variable `POLICY_GEN_ENABLE_HELM` to `"true"`.

### As a standalone binary

In order to bypass Kustomize and run the generator binary directly, change to the directory of PolicyGenerator
Expand All @@ -119,7 +122,10 @@ cd examples
../PolicyGenerator policyGenerator.yaml
```

**NOTE:** To print the trace in the case of an error, you can add the `--debug` flag to the arguments.
**NOTE:**
- To print the trace in the case of an error, you can add the `--debug` flag to the arguments.
- To enable Helm processing when passing a Kustomize directory into the generator, set
the environment variable `POLICY_GEN_ENABLE_HELM` to `"true"`.

## Additional Policy Generator references

Expand Down
9 changes: 8 additions & 1 deletion internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,14 @@ func setNamespaceSelector(

// processKustomizeDir runs a provided directory through Kustomize in order to generate the manifests within it.
func processKustomizeDir(path string) ([]map[string]interface{}, error) {
k := krusty.MakeKustomizer(krusty.MakeDefaultOptions())
kustomizeOpts := krusty.MakeDefaultOptions()

if os.Getenv("POLICY_GEN_ENABLE_HELM") == "true" {
kustomizeOpts.PluginConfig.HelmConfig.Enabled = true
kustomizeOpts.PluginConfig.HelmConfig.Command = "helm"
}

k := krusty.MakeKustomizer(kustomizeOpts)

resourceMap, err := k.Run(filesys.MakeFsOnDisk(), path)
if err != nil {
Expand Down

0 comments on commit b3ad200

Please sign in to comment.