From 3ccbe00aa60ffbf71db6e8483bd600d29d95d49e Mon Sep 17 00:00:00 2001
From: Michael Kriese <michael.kriese@visualon.de>
Date: Fri, 26 Feb 2021 16:14:22 +0100
Subject: [PATCH] feat(helm-values): allow any image parentkey prefix (#8884)

---
 .../__fixtures__/multi_and_nested_image_values.yaml   |  6 ++++++
 .../helm-values/__snapshots__/extract.spec.ts.snap    |  8 ++++++++
 lib/manager/helm-values/extract.spec.ts               |  1 +
 lib/manager/helm-values/readme.md                     |  7 ++++++-
 lib/manager/helm-values/util.ts                       | 11 ++++++++---
 5 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/lib/manager/helm-values/__fixtures__/multi_and_nested_image_values.yaml b/lib/manager/helm-values/__fixtures__/multi_and_nested_image_values.yaml
index 8a6ad738ea..23690cdd96 100644
--- a/lib/manager/helm-values/__fixtures__/multi_and_nested_image_values.yaml
+++ b/lib/manager/helm-values/__fixtures__/multi_and_nested_image_values.yaml
@@ -21,3 +21,9 @@ someOtherKey:
       some-non-image-related-key: 'with-some-value'
 
 empty_key:
+
+# https://github.com/bitnami/charts/blob/eae34fdbf16e2cb6a6f809d72cd22f98f6bceccc/bitnami/harbor/values.yaml#L14-L17
+coreImage:
+  registry: docker.io
+  repository: bitnami/harbor-core
+  tag: 2.1.3-debian-10-r38
diff --git a/lib/manager/helm-values/__snapshots__/extract.spec.ts.snap b/lib/manager/helm-values/__snapshots__/extract.spec.ts.snap
index 0517bb9d71..8cd4ed7c28 100644
--- a/lib/manager/helm-values/__snapshots__/extract.spec.ts.snap
+++ b/lib/manager/helm-values/__snapshots__/extract.spec.ts.snap
@@ -27,6 +27,14 @@ Object {
       "replaceString": "11.5.0-debian-9-r0@sha256:4762726f1471ef048dd807afdc0e19265e95ffdcc7cb4a34891f680290022809",
       "versioning": "docker",
     },
+    Object {
+      "currentDigest": undefined,
+      "currentValue": "2.1.3-debian-10-r38",
+      "datasource": "docker",
+      "depName": "docker.io/bitnami/harbor-core",
+      "replaceString": "2.1.3-debian-10-r38",
+      "versioning": "docker",
+    },
   ],
 }
 `;
diff --git a/lib/manager/helm-values/extract.spec.ts b/lib/manager/helm-values/extract.spec.ts
index eb96bc4773..417c3825f5 100644
--- a/lib/manager/helm-values/extract.spec.ts
+++ b/lib/manager/helm-values/extract.spec.ts
@@ -35,6 +35,7 @@ describe('lib/manager/helm-values/extract', () => {
     it('extracts from complex values file correctly"', () => {
       const result = extractPackageFile(helmMultiAndNestedImageValues);
       expect(result).toMatchSnapshot();
+      expect(result.deps).toHaveLength(4);
     });
   });
 });
diff --git a/lib/manager/helm-values/readme.md b/lib/manager/helm-values/readme.md
index 031f4bb885..815f1888f0 100644
--- a/lib/manager/helm-values/readme.md
+++ b/lib/manager/helm-values/readme.md
@@ -1,9 +1,14 @@
 Renovate supports updating of Docker dependencies within Helm Chart `values.yaml` files or other YAML files that use the same format (via `fileMatch` configuration).
-Updates are performed if the files follow the conventional format used in most of the `stable` Helm charts:
+Updates are performed if the files follow the conventional format used in most of the Helm charts:
 
 ```yaml
 image:
   repository: 'some-docker/dependency'
   tag: v1.0.0
   registry: registry.example.com # optional key, will default to "docker.io"
+
+coreImage:
+  registry: docker.io
+  repository: bitnami/harbor-core
+  tag: 2.1.3-debian-10-r38
 ```
diff --git a/lib/manager/helm-values/util.ts b/lib/manager/helm-values/util.ts
index d886c16d00..1aeabaf30b 100644
--- a/lib/manager/helm-values/util.ts
+++ b/lib/manager/helm-values/util.ts
@@ -6,24 +6,29 @@ export type HelmDockerImageDependency = {
   tag: string;
 };
 
+const parentKeyRe = /image$/i;
+
 /**
  * Type guard to determine whether a given partial Helm values.yaml object potentially
  * defines a Helm Docker dependency.
  *
  * There is no exact standard of how Docker dependencies are defined in Helm
- * values.yaml files (as of January 1st 2020), this function defines a
- * heuristic based on the most commonly used format in the stable Helm charts:
+ * values.yaml files (as of February 26th 2021), this function defines a
+ * heuristic based on the most commonly used format in the Helm charts:
  *
  * image:
  *   repository: 'something'
  *   tag: v1.0.0
+ * renovateImage:
+ *   repository: 'something'
+ *   tag: v1.0.0
  */
 export function matchesHelmValuesDockerHeuristic(
   parentKey: string,
   data: unknown
 ): data is HelmDockerImageDependency {
   return (
-    parentKey === 'image' &&
+    parentKeyRe.test(parentKey) &&
     data &&
     typeof data === 'object' &&
     hasKey('repository', data) &&
-- 
GitLab