From 3d56684aa727e315e3d7e967a75594c2e217543d Mon Sep 17 00:00:00 2001
From: Gaston Festari <cilindrox@gmail.com>
Date: Fri, 3 Sep 2021 08:40:25 -0300
Subject: [PATCH] feat(kustomize): add components support (#11553)

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
---
 lib/manager/kustomize/__fixtures__/depsInResources.yaml  | 3 +++
 lib/manager/kustomize/__snapshots__/extract.spec.ts.snap | 7 ++++++-
 lib/manager/kustomize/extract.spec.ts                    | 6 ++++--
 lib/manager/kustomize/extract.ts                         | 5 ++++-
 lib/manager/kustomize/readme.md                          | 1 +
 5 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/lib/manager/kustomize/__fixtures__/depsInResources.yaml b/lib/manager/kustomize/__fixtures__/depsInResources.yaml
index acdcb457a6..d8c210bd9f 100644
--- a/lib/manager/kustomize/__fixtures__/depsInResources.yaml
+++ b/lib/manager/kustomize/__fixtures__/depsInResources.yaml
@@ -10,5 +10,8 @@ resources:
 - deployment.yaml
 - github.com/fluxcd/flux/deploy?ref=1.19.0
 
+components:
+- github.com/fluxcd/flux/memcache-dep?ref=1.18.0
+
 images:
 - name: nginx
diff --git a/lib/manager/kustomize/__snapshots__/extract.spec.ts.snap b/lib/manager/kustomize/__snapshots__/extract.spec.ts.snap
index ec2fc9f816..55eaee5461 100644
--- a/lib/manager/kustomize/__snapshots__/extract.spec.ts.snap
+++ b/lib/manager/kustomize/__snapshots__/extract.spec.ts.snap
@@ -67,7 +67,7 @@ Array [
 ]
 `;
 
-exports[`manager/kustomize/extract extractPackageFile() should extract bases from bases block and the resources block 1`] = `
+exports[`manager/kustomize/extract extractPackageFile() should extract bases resources and components from their respective blocks 1`] = `
 Array [
   Object {
     "currentValue": "v0.0.1",
@@ -79,6 +79,11 @@ Array [
     "datasource": "github-tags",
     "depName": "fluxcd/flux",
   },
+  Object {
+    "currentValue": "1.18.0",
+    "datasource": "github-tags",
+    "depName": "fluxcd/flux",
+  },
 ]
 `;
 
diff --git a/lib/manager/kustomize/extract.spec.ts b/lib/manager/kustomize/extract.spec.ts
index 7fe27a2522..44c2b71ca9 100644
--- a/lib/manager/kustomize/extract.spec.ts
+++ b/lib/manager/kustomize/extract.spec.ts
@@ -242,14 +242,16 @@ describe('manager/kustomize/extract', () => {
     it('does nothing with kustomize empty kustomize files', () => {
       expect(extractPackageFile(kustomizeEmpty)).toBeNull();
     });
-    it('should extract bases from bases block and the resources block', () => {
+    it('should extract bases resources and components from their respective blocks', () => {
       const res = extractPackageFile(kustomizeDepsInResources);
       expect(res).not.toBeNull();
       expect(res.deps).toMatchSnapshot();
-      expect(res.deps).toHaveLength(2);
+      expect(res.deps).toHaveLength(3);
       expect(res.deps[0].currentValue).toEqual('v0.0.1');
       expect(res.deps[1].currentValue).toEqual('1.19.0');
+      expect(res.deps[2].currentValue).toEqual('1.18.0');
       expect(res.deps[1].depName).toEqual('fluxcd/flux');
+      expect(res.deps[2].depName).toEqual('fluxcd/flux');
     });
     it('extracts sha256 instead of tag', () => {
       expect(extractPackageFile(sha)).toMatchSnapshot({
diff --git a/lib/manager/kustomize/extract.ts b/lib/manager/kustomize/extract.ts
index 12bfb8280c..8a06c3da71 100644
--- a/lib/manager/kustomize/extract.ts
+++ b/lib/manager/kustomize/extract.ts
@@ -84,7 +84,10 @@ export function parseKustomize(content: string): Kustomize | null {
     return null;
   }
 
-  pkg.bases = (pkg.bases || []).concat(pkg.resources || []);
+  pkg.bases = (pkg.bases || []).concat(
+    pkg.resources || [],
+    pkg.components || []
+  );
   pkg.images = pkg.images || [];
 
   return pkg;
diff --git a/lib/manager/kustomize/readme.md b/lib/manager/kustomize/readme.md
index b38948bb55..1a63c7718c 100644
--- a/lib/manager/kustomize/readme.md
+++ b/lib/manager/kustomize/readme.md
@@ -2,6 +2,7 @@ This package will manage two parts of the `kustomization.yaml` file:
 
 1. [remote bases](https://github.com/kubernetes-sigs/kustomize/blob/master/examples/remoteBuild.md)
 2. [image tags](https://github.com/kubernetes-sigs/kustomize/blob/master/examples/image.md)
+3. [components](https://github.com/kubernetes-sigs/kustomize/blob/master/examples/components.md)
 
 **How It Works**
 
-- 
GitLab