Skip to content

Commit e4c0595

Browse files
EtiennePerotgvisor-bot
authored andcommitted
Ignore container name remap annotations during spec validation.
Such annotations are *expected* to change, that's the point of the remap. There is extra code in the restore process that verifies that the same container names are defined in these annotations, so no further re-verification of this is necessary at this stage. PiperOrigin-RevId: 756989545
1 parent 81d7f66 commit e4c0595

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

runsc/container/container_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3836,6 +3836,18 @@ func TestSpecValidation(t *testing.T) {
38363836
},
38373837
wantErr: "",
38383838
},
3839+
{
3840+
name: "AnnotationsContainerNameRemapIgnored",
3841+
mutate: func(spec, restoreSpec *specs.Spec, _, _ string) {
3842+
spec.Annotations = make(map[string]string)
3843+
spec.Annotations["dev.gvisor.dev.gvisor.container-name-remap.1"] = "name1"
3844+
3845+
restoreSpec.Annotations = make(map[string]string)
3846+
restoreSpec.Annotations["dev.gvisor.dev.gvisor.container-name-remap.1"] = "name2"
3847+
restoreSpec.Annotations["dev.gvisor.dev.gvisor.container-name-remap.asdf"] = "foobar"
3848+
},
3849+
wantErr: "",
3850+
},
38393851
{
38403852
name: "AnnotationsFail",
38413853
mutate: func(spec, restoreSpec *specs.Spec, _, _ string) {

runsc/specutils/restore.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,15 @@ func validateDevices(field, cName string, o, n []specs.LinuxDevice) error {
136136

137137
func extractAnnotationsToValidate(o map[string]string) map[string]string {
138138
const (
139-
gvisorPrefix = "dev.gvisor."
140-
internalPrefix = "dev.gvisor.internal."
141-
mntPrefix = "dev.gvisor.spec.mount."
139+
gvisorPrefix = "dev.gvisor."
140+
internalPrefix = "dev.gvisor.internal."
141+
mntPrefix = "dev.gvisor.spec.mount."
142+
containerNameRemapPrefix = "dev.gvisor.container-name-remap."
142143
)
143144

144145
n := make(map[string]string)
145146
for key, val := range o {
146-
if strings.HasPrefix(key, internalPrefix) || (strings.HasPrefix(key, mntPrefix) && strings.HasSuffix(key, ".source")) {
147+
if strings.HasPrefix(key, internalPrefix) || strings.HasPrefix(key, containerNameRemapPrefix) || (strings.HasPrefix(key, mntPrefix) && strings.HasSuffix(key, ".source")) {
147148
continue
148149
}
149150

0 commit comments

Comments
 (0)