Support Entrypoint command for Host and Bootstrap containers#4636
Conversation
bc446c9 to
786f6f4
Compare
786f6f4 to
d1fb200
Compare
|
Add unit test case for compound suffix per @KCSesh |
sources/api/migration/migration-helpers/src/common_migrations.rs
Outdated
Show resolved
Hide resolved
5b0b0e7 to
7e0c99f
Compare
|
Tighten the matching implementation so that it uses regex pattern to match the settings. The regex pattern would be |
| let mut compiled_patterns = Vec::new(); | ||
| for pattern in &self.0 { | ||
| let regex_pattern = format!( | ||
| r"^{}\.(.+)\.{}$", | ||
| regex::escape(pattern.prefix), | ||
| regex::escape(pattern.suffix) | ||
| ); | ||
| let regex = | ||
| Regex::new(®ex_pattern).context(error::InvalidPrefixSuffixPatternSnafu { | ||
| prefix: pattern.prefix, | ||
| suffix: pattern.suffix, | ||
| })?; | ||
| compiled_patterns.push(regex); | ||
| } |
There was a problem hiding this comment.
We have to compile the regex patterns at runtime because it depends on the prefix and suffix. But this way we only still compile it once for the backward() call.
koooosh
left a comment
There was a problem hiding this comment.
LGTM, assuming new migration tests pass
Signed-off-by: Yutong Sun <yutongsu@amazon.com>
Signed-off-by: Yutong Sun <yutongsu@amazon.com>
7e0c99f to
23a27fb
Compare
|
Force push to rebase changes from develop |
| } | ||
|
|
||
| #[test] | ||
| fn tight_matching() { |
There was a problem hiding this comment.
Added more test cases here with real settings - for the more strict regex matching.
| let mut compiled_patterns = Vec::new(); | ||
| for pattern in &self.0 { | ||
| let regex_pattern = format!( | ||
| r"^{}\.(.+)\.{}$", |
There was a problem hiding this comment.
The migration's regex (.+) captures any characters, which is more than we allow in host/bootstrap containers today.
But this makes sense to make it more extensible for future situations, since this is in common
|
I reran the migration tests to just confirm the behavior. And it passed! |
Issue number:
Closes bottlerocket-os/bottlerocket-core-kit#593
Description of changes:
This PR adds migration support for the new
commandsetting insettings.host-containers.<name>.commandsettings.bootstrap-containers.<name>.commandKey changes:
AddPrefixSuffixMigrationhelper for migrations that needs both prefix and suffix matches.settings.{host,bootstrap}-containers.<name>.commandsettings.The migration helper uses prefix/suffix patterns to identify and remove settings during downgrades:
Testing done:
Click to expand testing details
Initial Setup and Upgrade Testing
1. Pre-upgrade validation (expected failure)
Result: Failed as expected with error:
unknown field 'command', expected one of 'source', 'mode', 'user-data', 'essential'2. Post-upgrade to v1.47.0
Applied the same configuration successfully. Verified settings were properly stored:
Downgrade Migration Testing
3. Downgrade migration validation
After downgrading from v1.47.0, verified that the
commandfield was properly removed:Runtime Verification
After applying the new settings in step 2, reboot the node to verify both bootstrap and host containers pick up the settings.
4. Container runtime validation
# Verified custom host container is running ctr -a /run/host-containerd/containerd.sock c ls CONTAINER IMAGE RUNTIME admin ecr.aws/arn:aws:ecr:us-west-2:328549459982:repository/bottlerocket-admin:v0.12.2 io.containerd.runc.v2 ... test-host public.ecr.aws/amazonlinux/amazonlinux:2023 io.containerd.runc.v25. Container execution validation
The custom host-container has entry point ["sleep", "infinity"], so we can exec into it for some extra testing.
6. Host container logs
7. Bootstrap container logs and command execution
Terms of contribution:
By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.