code: func newContainerAnnotations(container *v1.Container, pod *v1.Pod, restartCount int, opts *kubecontainer.RunContainerOptions) map[string]string {
  	annotations := map[string]string{}
  
  	// Kubelet always overrides device plugin annotations if they are conflicting
  	for _, a := range opts.Annotations {
  		annotations[a.Name] = a.Value
  	}
  
  	annotations[containerHashLabel] = strconv.FormatUint(kubecontainer.HashContainer(container), 16)
  	annotations[containerRestartCountLabel] = strconv.Itoa(restartCount)
  	annotations[containerTerminationMessagePathLabel] = container.TerminationMessagePath
  	annotations[containerTerminationMessagePolicyLabel] = string(container.TerminationMessagePolicy)
  
  	if pod.DeletionGracePeriodSeconds != nil {
  		annotations[podDeletionGracePeriodLabel] = strconv.FormatInt(*pod.DeletionGracePeriodSeconds, 10)
  	}
  	if pod.Spec.TerminationGracePeriodSeconds != nil {
  		annotations[podTerminationGracePeriodLabel] = strconv.FormatInt(*pod.Spec.TerminationGracePeriodSeconds, 10)
  	}
  
  	if container.Lifecycle != nil && container.Lifecycle.PreStop != nil {
  		// Using json encoding so that the PreStop handler object is readable after writing as a label
  		rawPreStop, err := json.Marshal(container.Lifecycle.PreStop)
  		if err != nil {
  			klog.Errorf("Unable to marshal lifecycle PreStop handler for container %q of pod %q: %v", container.Name, format.Pod(pod), err)
  		} else {
  			annotations[containerPreStopHandlerLabel] = string(rawPreStop)
  		}
  	}
  
  	if len(container.Ports) > 0 {
  		rawContainerPorts, err := json.Marshal(container.Ports)
  		if err != nil {
  			klog.Errorf("Unable to marshal container ports for container %q for pod %q: %v", container.Name, format.Pod(pod), err)
  		} else {
  			annotations[containerPortsLabel] = string(rawContainerPorts)
  		}
  	}
  
  	return annotations
  }
docs: // newContainerAnnotations creates container annotations from v1.Container and v1.Pod.