From d80bc01ebe4fd3e168c0a0de7161ffa99f428128 Mon Sep 17 00:00:00 2001
From: Sebastian Poxhofer <secustor@users.noreply.github.com>
Date: Thu, 7 Oct 2021 09:09:04 +0200
Subject: [PATCH] feat(helm-values): support inline image definitions (#12041)

---
 .../__fixtures__/multi_and_nested_image_values.yaml       | 2 ++
 .../helm-values/__snapshots__/extract.spec.ts.snap        | 8 ++++++++
 lib/manager/helm-values/extract.spec.ts                   | 2 +-
 lib/manager/helm-values/extract.ts                        | 8 +++++++-
 lib/manager/helm-values/util.ts                           | 7 +++++++
 5 files changed, 25 insertions(+), 2 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 23690cdd96..afb3969032 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
@@ -1,4 +1,6 @@
 ---
+inline_image: docker.io/library/nginx:1.18-alpine
+
 api:
   image:
     image:
diff --git a/lib/manager/helm-values/__snapshots__/extract.spec.ts.snap b/lib/manager/helm-values/__snapshots__/extract.spec.ts.snap
index 7c463545d4..ae90d042fb 100644
--- a/lib/manager/helm-values/__snapshots__/extract.spec.ts.snap
+++ b/lib/manager/helm-values/__snapshots__/extract.spec.ts.snap
@@ -3,6 +3,14 @@
 exports[`manager/helm-values/extract extractPackageFile() extracts from complex values file correctly" 1`] = `
 Object {
   "deps": Array [
+    Object {
+      "autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}",
+      "currentDigest": undefined,
+      "currentValue": "1.18-alpine",
+      "datasource": "docker",
+      "depName": "docker.io/library/nginx",
+      "replaceString": "docker.io/library/nginx:1.18-alpine",
+    },
     Object {
       "autoReplaceStringTemplate": "{{newValue}}{{#if newDigest}}@{{newDigest}}{{/if}}",
       "currentDigest": undefined,
diff --git a/lib/manager/helm-values/extract.spec.ts b/lib/manager/helm-values/extract.spec.ts
index 08213783dc..a2a1c6196d 100644
--- a/lib/manager/helm-values/extract.spec.ts
+++ b/lib/manager/helm-values/extract.spec.ts
@@ -40,7 +40,7 @@ describe('manager/helm-values/extract', () => {
     it('extracts from complex values file correctly"', () => {
       const result = extractPackageFile(helmMultiAndNestedImageValues);
       expect(result).toMatchSnapshot();
-      expect(result.deps).toHaveLength(4);
+      expect(result.deps).toHaveLength(5);
     });
   });
 });
diff --git a/lib/manager/helm-values/extract.ts b/lib/manager/helm-values/extract.ts
index 6b962e5987..a57a2876a0 100644
--- a/lib/manager/helm-values/extract.ts
+++ b/lib/manager/helm-values/extract.ts
@@ -4,7 +4,10 @@ import { id as dockerVersioning } from '../../versioning/docker';
 import { getDep } from '../dockerfile/extract';
 import type { PackageDependency, PackageFile } from '../types';
 import type { HelmDockerImageDependency } from './types';
-import { matchesHelmValuesDockerHeuristic } from './util';
+import {
+  matchesHelmValuesDockerHeuristic,
+  matchesHelmValuesInlineImage,
+} from './util';
 
 function getHelmDep({
   registry,
@@ -45,6 +48,9 @@ function findDependencies(
       const repository = String(currentItem.repository);
       const tag = String(currentItem.tag);
       packageDependencies.push(getHelmDep({ repository, tag, registry }));
+    } else if (matchesHelmValuesInlineImage(key, parsedContent[key])) {
+      const currentItem = parsedContent[key];
+      packageDependencies.push(getDep(currentItem));
     } else {
       findDependencies(parsedContent[key], packageDependencies);
     }
diff --git a/lib/manager/helm-values/util.ts b/lib/manager/helm-values/util.ts
index ffc9ee74cb..f1707aef7b 100644
--- a/lib/manager/helm-values/util.ts
+++ b/lib/manager/helm-values/util.ts
@@ -30,3 +30,10 @@ export function matchesHelmValuesDockerHeuristic(
     hasKey('tag', data)
   );
 }
+
+export function matchesHelmValuesInlineImage(
+  parentKey: string,
+  data: unknown
+): data is string {
+  return parentKeyRe.test(parentKey) && data && typeof data === 'string';
+}
-- 
GitLab