Skip to content

Commit 8165ec8

Browse files
ayushr2gvisor-bot
authored andcommitted
Exclude debug-related flag annotations from checkpoint/restore validation.
The dev.gvisor.flag. annotations used for controlling debug logging (e.g., strace, debug-log) do not impact the ability to restore a container. Allow them to change so it is easier to enable debugging on restoring Pods. PiperOrigin-RevId: 899755195
1 parent 775f675 commit 8165ec8

2 files changed

Lines changed: 59 additions & 11 deletions

File tree

runsc/container/container_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4097,7 +4097,7 @@ func TestSpecValidation(t *testing.T) {
40974097
name: "AnnotationsFail",
40984098
mutate: func(spec, restoreSpec *specs.Spec, _, _ string) {
40994099
spec.Annotations = make(map[string]string)
4100-
spec.Annotations["dev.gvisor.net-disconnect-ok"] = strconv.FormatBool(true)
4100+
spec.Annotations["dev.gvisor.flag.net-disconnect-ok"] = strconv.FormatBool(true)
41014101
},
41024102
wantErr: "Annotations does not match across checkpoint restore",
41034103
},
@@ -4112,6 +4112,17 @@ func TestSpecValidation(t *testing.T) {
41124112
},
41134113
wantErr: "",
41144114
},
4115+
{
4116+
name: "DebugLogAnnotationsSuccess",
4117+
mutate: func(spec, restoreSpec *specs.Spec, _, _ string) {
4118+
restoreSpec.Annotations = make(map[string]string)
4119+
restoreSpec.Annotations["dev.gvisor.flag.debug-log"] = "/tmp/sandbox-%ID%/"
4120+
restoreSpec.Annotations["dev.gvisor.flag.debug"] = "true"
4121+
restoreSpec.Annotations["dev.gvisor.flag.debug-command"] = "boot,gofer,start,create"
4122+
restoreSpec.Annotations["dev.gvisor.flag.strace"] = "true"
4123+
},
4124+
wantErr: "",
4125+
},
41154126
{
41164127
name: "Capabilities",
41174128
mutate: func(spec, restoreSpec *specs.Spec, _, _ string) {

runsc/specutils/restore.go

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,58 @@ func validateDevices(field, cName string, o, n []specs.LinuxDevice) error {
139139
return nil
140140
}
141141

142-
func extractAnnotationsToValidate(o map[string]string) map[string]string {
142+
// These annotations are allowed to be changed during restore.
143+
var allowedRestoreFlagAnnotations = []string{
144+
annotationFlagPrefix + "debug",
145+
annotationFlagPrefix + "debug-log",
146+
annotationFlagPrefix + "debug-command",
147+
annotationFlagPrefix + "debug-log-format",
148+
annotationFlagPrefix + "strace",
149+
annotationFlagPrefix + "strace-syscalls",
150+
annotationFlagPrefix + "strace-log-size",
151+
annotationFlagPrefix + "log-packets",
152+
}
153+
154+
func shouldValidateAnnotation(key string) bool {
143155
const (
144-
gvisorPrefix = "dev.gvisor."
145-
internalPrefix = "dev.gvisor.internal."
146-
mntPrefix = "dev.gvisor.spec.mount."
147-
containerNameRemapPrefix = "dev.gvisor.container-name-remap."
156+
gvisorPrefix = "dev.gvisor."
157+
internalPrefix = "dev.gvisor.internal."
158+
mntPrefix = "dev.gvisor.spec.mount."
148159
)
160+
// Only validate gVisor annotations.
161+
if !strings.HasPrefix(key, gvisorPrefix) {
162+
return false
163+
}
164+
// Do not validate internal annotations. They might container
165+
// checkpoint/restore specific information which ought to change.
166+
if strings.HasPrefix(key, internalPrefix) {
167+
return false
168+
}
169+
// Do not validate container name remap annotations. These are only set
170+
// during restore.
171+
if strings.HasPrefix(key, annotationContainerNameRemap) {
172+
return false
173+
}
174+
// The source of a mount can change during restore.
175+
if strings.HasPrefix(key, mntPrefix) && strings.HasSuffix(key, ".source") {
176+
return false
177+
}
178+
// Flag annotations controlling debug logging can change. They don't impact
179+
// the restorability of the snapshot.
180+
if strings.HasPrefix(key, annotationFlagPrefix) {
181+
for _, allowed := range allowedRestoreFlagAnnotations {
182+
if key == allowed {
183+
return false
184+
}
185+
}
186+
}
187+
return true
188+
}
149189

190+
func extractAnnotationsToValidate(o map[string]string) map[string]string {
150191
n := make(map[string]string)
151192
for key, val := range o {
152-
if strings.HasPrefix(key, internalPrefix) || strings.HasPrefix(key, containerNameRemapPrefix) || (strings.HasPrefix(key, mntPrefix) && strings.HasSuffix(key, ".source")) {
153-
continue
154-
}
155-
156-
if strings.HasPrefix(key, gvisorPrefix) {
193+
if shouldValidateAnnotation(key) {
157194
n[key] = val
158195
}
159196
}

0 commit comments

Comments
 (0)