diff --git a/cmd/options.go b/cmd/options.go index 98bebb58..890e7b97 100644 --- a/cmd/options.go +++ b/cmd/options.go @@ -507,6 +507,12 @@ func (o *RawOptions) ToConfig() (*Config, error) { return nil, fmt.Errorf("--traverse-app-of-apps requires --render-method=repo-server-api (current: %s)", cfg.RenderMethod) } + // Helm hooks are not returned by the Argo CD CLI renderer. They can only be + // included when manifests are fetched through one of the API renderers. + if cfg.IncludeHelmHooks && cfg.RenderMethod == RenderMethodCLI { + return nil, fmt.Errorf("--include-helm-hooks is incompatible with --render-method=cli; use --render-method=server-api or --render-method=repo-server-api") + } + // Check if argocd CLI is installed when not using API mode if cfg.RenderMethod == RenderMethodCLI && !cfg.DryRun { if _, err := exec.LookPath("argocd"); err != nil { diff --git a/cmd/options_test.go b/cmd/options_test.go index 35d75873..afddde6c 100644 --- a/cmd/options_test.go +++ b/cmd/options_test.go @@ -32,3 +32,32 @@ func TestNewLogger_Human(t *testing.T) { assert.Equal(t, "failed to render (app: my-app)", strings.TrimSpace(buf.String())) } + +func TestRawOptionsToConfig_IncludeHelmHooksRenderMethod(t *testing.T) { + baseOptions := func(renderMethod string) RawOptions { + return RawOptions{ + BaseBranch: "main", + TargetBranch: "feature", + Repo: "example/repo", + RenderMethod: renderMethod, + IncludeHelmHooks: true, + DryRun: true, + } + } + + t.Run("rejects CLI renderer", func(t *testing.T) { + options := baseOptions("cli") + _, err := options.ToConfig() + require.EqualError(t, err, "--include-helm-hooks is incompatible with --render-method=cli; use --render-method=server-api or --render-method=repo-server-api") + }) + + for _, renderMethod := range []string{"server-api", "repo-server-api"} { + t.Run(renderMethod, func(t *testing.T) { + options := baseOptions(renderMethod) + cfg, err := options.ToConfig() + require.NoError(t, err) + assert.True(t, cfg.IncludeHelmHooks) + assert.Equal(t, RenderMethod(renderMethod), cfg.RenderMethod) + }) + } +} diff --git a/integration-test/README.md b/integration-test/README.md index c900f37a..1cbc921e 100644 --- a/integration-test/README.md +++ b/integration-test/README.md @@ -183,12 +183,12 @@ Each `branch-N/target[-suffix]/` directory contains expected output files (`outp ### Branch 15: Additional Coverage - `target`: Basic diff (no special options) -### Branch 16-20: repo-server-api Render Method +### Branch 16-21: repo-server-api Render Method - `branch-16/target`: Config Management Plugin (kustomize-build-with-helm) via `repo-server-api` - `branch-17/target-1` / `target-2`: App-of-apps traversal via `repo-server-api` - `branch-18/target`: Single-source local Helm chart whose `helm.valueFiles` reference a file OUTSIDE the chart directory via a repo-root-absolute path (`/examples/out-of-chart-values/env/values.yaml`). Regression test for `repo-server-api`: the tool must stream the whole branch folder so the out-of-chart value file is reachable, otherwise the render fails with `no such file or directory`. - `branch-19/target`: Kustomize resource outside the application directory via `repo-server-api`. It requires global `kustomize.buildOptions: --load-restrictor LoadRestrictionsNone` from `argocd-cm`, proving the direct repo-server request forwards that setting. -- `branch-20/target`: Local Helm chart that gates a ServiceMonitor on the kind-level capability `monitoring.coreos.com/v1/ServiceMonitor`, via `repo-server-api` against a cluster with the ServiceMonitor CRD. The target enables it, so the diff must show the ServiceMonitor added, as a real Argo CD sync would render it. +- `branch-21/target`: Local Helm chart that gates a ServiceMonitor on the kind-level capability `monitoring.coreos.com/v1/ServiceMonitor`, via `repo-server-api` against a cluster with the ServiceMonitor CRD. The target enables it, so the diff must show the ServiceMonitor added, as a real Argo CD sync would render it. ## Prerequisites diff --git a/integration-test/branch-2/target-1/output.html b/integration-test/branch-2/target-1/output.html index c35376e1..12fa308e 100644 --- a/integration-test/branch-2/target-1/output.html +++ b/integration-test/branch-2/target-1/output.html @@ -60,7 +60,7 @@
Summary:
Modified (1): -± internal-chart-example (+7|-7)+± internal-chart-example (+5|-5)
kind: Pod |
metadata: |
annotations: |
helm.sh/hook: test |
labels: |
app.kubernetes.io/instance: internal-chart-example |
app.kubernetes.io/managed-by: Helm |
app.kubernetes.io/name: myApp |
app.kubernetes.io/version: 1.16.0 |
helm.sh/chart: myApp-0.1.0 |
- name: super-app-name-test-connection |
+ name: new-app-name-test-connection |
namespace: default |
spec: |
containers: |
- args: |
- - super-app-name:80 |
+ - new-app-name:80 |
command: |
- wget |
image: busybox |
name: wget |
restartPolicy: Never |
kind: Pod |
metadata: |
annotations: |
helm.sh/hook: test |
labels: |
app.kubernetes.io/instance: internal-chart-example |
app.kubernetes.io/managed-by: Helm |
app.kubernetes.io/name: myApp |
app.kubernetes.io/version: 1.16.0 |
helm.sh/chart: myApp-0.1.0 |
- name: super-app-name-test-connection |
+ name: new-app-name-test-connection |
namespace: default |
spec: |
containers: |
- args: |
- - super-app-name:80 |
+ - new-app-name:80 |
command: |
- wget |
image: busybox |
name: wget |
restartPolicy: Never |