diff --git a/lib/modules/manager/kubernetes/extract.spec.ts b/lib/modules/manager/kubernetes/extract.spec.ts index 56052789fb6f24..6a4f5403f20d3d 100644 --- a/lib/modules/manager/kubernetes/extract.spec.ts +++ b/lib/modules/manager/kubernetes/extract.spec.ts @@ -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: '{{', - }, ], }); }); diff --git a/lib/modules/manager/kubernetes/extract.ts b/lib/modules/manager/kubernetes/extract.ts index 5d376539afdfb1..7e9313f441c9f1 100644 --- a/lib/modules/manager/kubernetes/extract.ts +++ b/lib/modules/manager/kubernetes/extract.ts @@ -37,6 +37,14 @@ 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, @@ -44,7 +52,7 @@ function extractImages( 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); @@ -60,7 +68,7 @@ function extractImages( } } - return deps.filter((dep) => !dep.currentValue?.includes('${')); + return deps; } function extractApis(