From 9630fb998f6bb5573b0d30ba82d17613b188da85 Mon Sep 17 00:00:00 2001
From: Joe Lanford <joe.lanford@gmail.com>
Date: Mon, 2 Dec 2019 17:47:42 -0500
Subject: [PATCH] *: allow relative paths for helm charts in watches.yaml file

---
 CHANGELOG.md                         |  1 +
 doc/helm/dev/developer_guide.md      | 15 ++-------------
 doc/helm/user-guide.md               | 14 +-------------
 internal/scaffold/helm/entrypoint.go |  3 ++-
 internal/scaffold/helm/watches.go    |  2 +-
 5 files changed, 7 insertions(+), 28 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index f3197719e40..3c47f61e99c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@
 ### Added
 - Support for vars in top level ansible watches. ([#2147](https://github.com/operator-framework/operator-sdk/pull/2147))
 - Support for `"ansible.operator-sdk/verbosity"` annotation on Custom Resources watched by Ansible based operators to override verbosity on an individual resource. ([#2102](https://github.com/operator-framework/operator-sdk/pull/2102))
+- Support for relative helm chart paths in the Helm operator's watches.yaml file. ([#2287](https://github.com/operator-framework/operator-sdk/pull/2287))
 
 ### Changed
 - Upgrade minimal Ansible version in the init projects from `2.4` to `2.6`. ([#2107](https://github.com/operator-framework/operator-sdk/pull/2107))
diff --git a/doc/helm/dev/developer_guide.md b/doc/helm/dev/developer_guide.md
index b590b2bedcc..ef3d2d3b2f8 100644
--- a/doc/helm/dev/developer_guide.md
+++ b/doc/helm/dev/developer_guide.md
@@ -228,7 +228,8 @@ mandatory fields:
 **chart**:  This is the path to the Helm chart that you have added to the
 container. For example, if your Helm charts directory is at
 `/opt/helm/helm-charts/` and your Helm chart is named `busybox`, this value
-will be `/opt/helm/helm-charts/busybox`.
+will be `/opt/helm/helm-charts/busybox`. If the path is relative, it is
+relative to the current working directory.
 
 Example specifying a Helm chart watch:
 
@@ -267,18 +268,6 @@ when we were testing our Helm chart locally. This section assumes the developer
 has read the [Helm Operator user guide][helm_operator_user_guide] and has the
 proper dependencies installed.
 
-Since `up local` reads from `./watches.yaml`, there are a couple options
-available to the developer. If `chart` is left alone (by default
-`/opt/helm/helm-charts/<name>`) the Helm chart must exist at that location in
-the filesystem. It is recommended that the developer create a symlink at this
-location, pointed to the Helm chart in the project directory, so that changes
-to the Helm chart are reflected where necessary.
-
-```sh
-sudo mkdir -p /opt/helm/helm-charts
-sudo ln -s $PWD/helm-charts/<name> /opt/helm/helm-charts/<name>
-```
-
 Create a Custom Resource Definition (CRD) for resource Foo. `operator-sdk` autogenerates this file
 inside of the `deploy` folder:
 
diff --git a/doc/helm/user-guide.md b/doc/helm/user-guide.md
index b273072ee64..d6d38d928e7 100644
--- a/doc/helm/user-guide.md
+++ b/doc/helm/user-guide.md
@@ -88,7 +88,7 @@ in `watches.yaml` and executes Helm releases using the specified chart:
 - version: v1alpha1
   group: example.com
   kind: Nginx
-  chart: /opt/helm/helm-charts/nginx
+  chart: helm-charts/nginx
 ```
 
 ### Reviewing the Nginx Helm Chart
@@ -210,18 +210,6 @@ nginx-operator       1         1         1            1           1m
 
 This method is preferred during the development cycle to speed up deployment and testing.
 
-It is important that the `chart` path referenced in `watches.yaml` exists
-on your machine. By default, the `watches.yaml` file is scaffolded to work with
-an operator image built with `operator-sdk build`. When developing and
-testing your operator with `operator-sdk up local`, the SDK will look in your
-local filesystem for this path. The SDK team recommends creating a symlink at
-this location to point to your helm chart's path:
-
-```sh
-sudo mkdir -p /opt/helm/helm-charts
-sudo ln -s $PWD/helm-charts/nginx /opt/helm/helm-charts/nginx
-```
-
 Run the operator locally with the default Kubernetes config file present at
 `$HOME/.kube/config`:
 
diff --git a/internal/scaffold/helm/entrypoint.go b/internal/scaffold/helm/entrypoint.go
index a38eda5d994..0ee9518d57d 100644
--- a/internal/scaffold/helm/entrypoint.go
+++ b/internal/scaffold/helm/entrypoint.go
@@ -45,5 +45,6 @@ if ! whoami &>/dev/null; then
   fi
 fi
 
-exec ${OPERATOR} run helm --watches-file=/opt/helm/watches.yaml $@
+cd $HOME
+exec ${OPERATOR} run helm --watches-file=$HOME/watches.yaml $@
 `
diff --git a/internal/scaffold/helm/watches.go b/internal/scaffold/helm/watches.go
index 28cb63aff62..fdedac03e09 100644
--- a/internal/scaffold/helm/watches.go
+++ b/internal/scaffold/helm/watches.go
@@ -47,5 +47,5 @@ const watchesYAMLTmpl = `---
 - version: {{.Resource.Version}}
   group: {{.Resource.FullGroup}}
   kind: {{.Resource.Kind}}
-  chart: /opt/helm/{{.HelmChartsDir}}/{{.ChartName}}
+  chart: {{.HelmChartsDir}}/{{.ChartName}}
 `