Repository: google/gvisor
File: runsc/specutils/specutils.go (Go)

Code before:
				if parts[0] == name {
					name = parts[1]
					break
				}
			}
		}
	}
	return name
}

func containerNameNoRemap(spec *specs.Spec) string {
	return spec.Annotations[ContainerdContainerNameAnnotation]
}

// RootfsTarUpperPath returns the path to the rootfs upper tar file, or empty
// string if not set. In multi-container mode, only container-specific
// annotations are used.
func RootfsTarUpperPath(spec *specs.Spec) string {
	if spec == nil || spec.Annotations == nil {
		return ""
	}
	containerSpecificPrefix := AnnotationRootfsUpperTar + "."
	if name := ContainerName(spec); name != "" {
		if path := spec.Annotations[containerSpecificPrefix+name]; path != "" {
			return path
		}
	}
	// If any container-specific annotation exists, don't fallback to the base
	// annotation. This indicates multi-container intent where loading the same
	// TAR into multiple containers is not meaningful.
	for key := range spec.Annotations {
		if strings.HasPrefix(key, containerSpecificPrefix) {
			return ""
		}
	}
	// Sub-containers must use container-specific annotations.
	if SpecContainerType(spec) == ContainerTypeContainer {
		return ""
	}
	return spec.Annotations[AnnotationRootfsUpperTar]
}

// AnnotationToBool parses the annotation value as a bool. On failure, it logs a warning and
// returns false.
func AnnotationToBool(spec *specs.Spec, annotation string) bool {
	val, ok := spec.Annotations[annotation]
	if !ok {
		return false
	}
	ret, err := strconv.ParseBool(val)
	if err != nil {

Review comment (suggestion):
Just `return spec.Annotations[containerSpecificPrefix+name]` here? The `io.kubernetes.cri.container-name` is always set in Pods, and never set in single-container use-cases (like Docker, Podman, etc).

I think this function can be simplified down to:
```
// RootfsTarUpperPath returns the path to the rootfs upper tar file, or empty
// string if not set. In multi-container mode, only container-specific
// annotations are used.
func RootfsTarUpperPath(spec *specs.Spec) string {
	if spec == nil || spec.Annotations == nil {
		return ""
	}
	if name := ContainerName(spec); name != "" {
		return spec.Annotations[AnnotationRootfsUpperTar + "." +name]
	}
	// Multi-container sandbox must use container-specific annotations.
	if cType := SpecContainerType(spec); cType == ContainerTypeContainer || cType == ContainerTypeSandbox {
		return ""
	}
	return spec.Annotations[AnnotationRootfsUpperTar]
}
```

Code after:
				if parts[0] == name {
					name = parts[1]
					break
				}
			}
		}
	}
	return name
}

func containerNameNoRemap(spec *specs.Spec) string {
	return spec.Annotations[ContainerdContainerNameAnnotation]
}

// RootfsTarUpperPath returns the path to the rootfs upper tar file, or empty
// string if not set. In multi-container mode, only container-specific
// annotations are used.
func RootfsTarUpperPath(spec *specs.Spec) string {
	if spec == nil || spec.Annotations == nil {
		return ""
	}
	if name := ContainerName(spec); name != "" {
		return spec.Annotations[AnnotationRootfsUpperTar+"."+name]
	}
	// Multi-container sandbox must use container-specific annotations.
	cType := SpecContainerType(spec)
	if cType == ContainerTypeContainer || cType == ContainerTypeSandbox {
		return ""
	}
	return spec.Annotations[AnnotationRootfsUpperTar]
}

// AnnotationToBool parses the annotation value as a bool. On failure, it logs a warning and
// returns false.
func AnnotationToBool(spec *specs.Spec, annotation string) bool {
	val, ok := spec.Annotations[annotation]
	if !ok {
		return false
	}
	ret, err := strconv.ParseBool(val)
	if err != nil {
		log.Warningf("Failed to parse annotation %q=%q as a bool: %v", annotation, val, err)
		return false
	}
	return ret
}