@@ -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