Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(manager/terraform): correctly extract oci charts (#21974)
  • Loading branch information
viceice committed May 4, 2023
1 parent 665866a commit 7bdf4d6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
25 changes: 12 additions & 13 deletions lib/modules/manager/terraform/extract.spec.ts
Expand Up @@ -7,18 +7,18 @@ import type { RepoGlobalConfig } from '../../../config/types';
import * as hashicorp from '../../versioning/hashicorp';
import { extractPackageFile } from '.';

const modules = Fixtures?.get('modules.tf');
const bitbucketModules = Fixtures?.get('bitbucketModules.tf');
const azureDevOpsModules = Fixtures?.get('azureDevOpsModules.tf');
const providers = Fixtures?.get('providers.tf');
const docker = Fixtures?.get('docker.tf');
const kubernetes = Fixtures?.get('kubernetes.tf');
const modules = Fixtures.get('modules.tf');
const bitbucketModules = Fixtures.get('bitbucketModules.tf');
const azureDevOpsModules = Fixtures.get('azureDevOpsModules.tf');
const providers = Fixtures.get('providers.tf');
const docker = Fixtures.get('docker.tf');
const kubernetes = Fixtures.get('kubernetes.tf');

const helm = Fixtures?.get('helm.tf');
const lockedVersion = Fixtures?.get('lockedVersion.tf');
const lockedVersionLockfile = Fixtures?.get('rangeStrategy.hcl');
const terraformBlock = Fixtures?.get('terraformBlock.tf');
const tfeWorkspaceBlock = Fixtures?.get('tfeWorkspace.tf');
const helm = Fixtures.get('helm.tf');
const lockedVersion = Fixtures.get('lockedVersion.tf');
const lockedVersionLockfile = Fixtures.get('rangeStrategy.hcl');
const terraformBlock = Fixtures.get('terraformBlock.tf');
const tfeWorkspaceBlock = Fixtures.get('tfeWorkspace.tf');

const adminConfig: RepoGlobalConfig = {
// `join` fixes Windows CI
Expand Down Expand Up @@ -602,7 +602,6 @@ describe('modules/manager/terraform/extract', () => {
datasource: 'helm',
depName: undefined,
depType: 'helm_release',
registryUrls: ['https://charts.helm.sh/stable'],
skipReason: 'invalid-name',
},
{
Expand All @@ -629,7 +628,7 @@ describe('modules/manager/terraform/extract', () => {
datasource: 'docker',
depName: 'karpenter',
depType: 'helm_release',
registryUrls: ['https://public.ecr.aws/karpenter'],
packageName: 'public.ecr.aws/karpenter/karpenter',
},
]);
});
Expand Down
32 changes: 18 additions & 14 deletions lib/modules/manager/terraform/extractors/resources/helm-release.ts
@@ -1,5 +1,6 @@
import is from '@sindresorhus/is';
import { logger } from '../../../../../logger';
import { joinUrlParts } from '../../../../../util/url';
import { DockerDatasource } from '../../../../datasource/docker';
import { HelmDatasource } from '../../../../datasource/helm';
import { isOCIRegistry } from '../../../helmv3/utils';
Expand Down Expand Up @@ -37,28 +38,31 @@ export class HelmReleaseExtractor extends DependencyExtractor {
depName: helmRelease.chart,
datasource: HelmDatasource.id,
};
if (is.nonEmptyString(helmRelease.repository)) {
if (isOCIRegistry(helmRelease.repository)) {
// For oci repos, we remove the oci:// and use the docker datasource
dep.registryUrls = [
helmRelease.repository.replace('oci://', 'https://'),
];
dep.datasource = DockerDatasource.id;
} else {
dep.registryUrls = [helmRelease.repository];
}
}
if (!helmRelease.chart) {

dependencies.push(dep);

if (!is.nonEmptyString(helmRelease.chart)) {
dep.skipReason = 'invalid-name';
} else if (isOCIRegistry(helmRelease.chart)) {
// For oci charts, we remove the oci:// and use the docker datasource
dep.depName = helmRelease.chart.replace('oci://', '');
dep.datasource = DockerDatasource.id;
} else if (checkIfStringIsPath(helmRelease.chart)) {
dep.skipReason = 'local-chart';
} else if (is.nonEmptyString(helmRelease.repository)) {
if (isOCIRegistry(helmRelease.repository)) {
{
// For oci repos, we remove the oci://, join the chart name and use the docker datasource
dep.packageName = joinUrlParts(
helmRelease.repository.replace('oci://', ''),
helmRelease.chart
);
dep.datasource = DockerDatasource.id;
}
} else {
dep.registryUrls = [helmRelease.repository];
}
}

dependencies.push(dep);
}

return dependencies;
Expand Down

0 comments on commit 7bdf4d6

Please sign in to comment.