-
Notifications
You must be signed in to change notification settings - Fork 80
add --image-url-substitution #296
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
base: main
Are you sure you want to change the base?
Conversation
Hi, Sorry for the delayed response and we appreciate the time spent on this PR. I feel like this can be achieved by using An example metrics_relabel_configs:
- source_labels: [image]
regex: "privateregistry\\.example\\.com/mirrored/(.*)"
target_label: image
replacement: "$1"
action: replace Which would result in the image label being |
Thx for checking! |
@roelarents Could you confirm for me this (I may be repeating what you've said above, but just so I can understand exactly what the ask/intentions are):
|
if len(sedCommand) < 4 { | ||
return "", "", "", fmt.Errorf("sed command for substitution seems to short: %s", sedCommand) | ||
} | ||
if sedCommand[0] != 's' { | ||
return "", "", "", fmt.Errorf("sed command for substitution should start with s: %s", sedCommand) | ||
} | ||
separator := regexp.QuoteMeta(sedCommand[1:2]) | ||
group := fmt.Sprintf(`((?:.|\\[%s])*)`, separator) | ||
pattern := `^s` + separator + group + separator + group + separator + group + `$` | ||
matcher, err := regexp.Compile(pattern) | ||
if err != nil { | ||
return "", "", "", fmt.Errorf("regexp to parse sed command for substitution does not compile: %s %w", pattern, err) | ||
} | ||
submatches := matcher.FindStringSubmatch(sedCommand) | ||
if len(submatches) != 4 { | ||
return "", "", "", fmt.Errorf("sed command for substitution could not be parsed: %s", pattern) | ||
} | ||
return strings.ReplaceAll(submatches[1], "\\"+separator, separator), | ||
strings.ReplaceAll(submatches[2], "\\"+separator, separator), | ||
submatches[3], nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason why you chose SED over a standard/traditional Regex? (which looks like you're doing anyway after all the sed-specific searches)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used the sed-like format/syntax to have the search and replacement string in one cli option. It seemed like a well-known/popular/widely-used format to me (s/search/replace
). For the rest it doesn't have anything to do with sed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments
Yes. Except:
|
In our use case we are mirroring external/public images (e.g. from DockerHub) to our own private container registry, so we don't have to rely on availability and rate limiting. But we only mirror particular/arbitrary tags. So version-checker will always see those as the latest tags. This PR adds a
--image-url-substitution
cli option. It enables to replace (sed
-style) something in all image URLs, before looking it up. All our mirrored images are prefixed likeprivateregistry.example.com/mirrored/docker.io/original:tag
, so we can remove that prefix.Any
override
annotation is still applied after.