Skip to content

Commit

Permalink
feat(manager/kubernetes): only extract valid images
Browse files Browse the repository at this point in the history
Signed-off-by: GitHub <[email protected]>
  • Loading branch information
aslafy-z committed Sep 26, 2024
1 parent 5e86717 commit 5172de5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
18 changes: 0 additions & 18 deletions lib/modules/manager/kubernetes/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,24 +182,6 @@ kind: ConfigMap
depName: 'busybox',
replaceString: 'busybox',
},
{
autoReplaceStringTemplate:
'{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}',
currentDigest: undefined,
currentValue: undefined,
datasource: 'docker',
depName: '{{',
replaceString: '{{',
},
{
autoReplaceStringTemplate:
'{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}',
currentDigest: undefined,
currentValue: undefined,
datasource: 'docker',
depName: '{{',
replaceString: '{{',
},
],
});
});
Expand Down
12 changes: 10 additions & 2 deletions lib/modules/manager/kubernetes/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,22 @@ export function extractPackageFile(
return deps.length ? { deps } : null;
}

// Comes from https://github.com/distribution/reference/blob/v0.6.0/regexp.go
// Extracted & converted with https://go.dev/play/p/ZwF3vvRD9Rs
const dockerImageRegexPattern = `((?:(?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])(?:\\.(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]))*|\\[(?:[a-fA-F0-9:]+)\\])(?::[0-9]+)?/)?[a-z0-9]+(?:(?:[._]|__|[-]+)[a-z0-9]+)*(?:/[a-z0-9]+(?:(?:[._]|__|[-]+)[a-z0-9]+)*)*)(?::([A-Za-z0-9][A-Za-z0-9.-]{0,127}))?(?:@([A-Za-z][A-Za-z0-9]*(?:[-_+.][A-Za-z][A-Za-z0-9]*)*[:][0-9a-fA-F]{32,}))?`;

const k8sImageRegex = regEx(
`^\\s*-?\\s*image:\\s*['"]?(${dockerImageRegexPattern})['"]?\\s*`,
);

function extractImages(
content: string,
config: ExtractConfig,
): PackageDependency[] {
const deps: PackageDependency[] = [];

for (const line of content.split(newlineRegex)) {
const match = regEx(/^\s*-?\s*image:\s*['"]?([^\s'"]+)['"]?\s*/).exec(line);
const match = k8sImageRegex.exec(line);
if (match) {
const currentFrom = match[1];
const dep = getDep(currentFrom, true, config.registryAliases);
Expand All @@ -60,7 +68,7 @@ function extractImages(
}
}

return deps.filter((dep) => !dep.currentValue?.includes('${'));
return deps;
}

function extractApis(
Expand Down

0 comments on commit 5172de5

Please sign in to comment.