Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(manager/terraform): correctly extract oci charts #21974

Merged
merged 1 commit into from May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
secustor marked this conversation as resolved.
Show resolved Hide resolved

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