func (ec *ephemeralController) handleVolume(pod *v1.Pod, vol v1.Volume) error {
	klog.V(5).Infof("ephemeral: checking volume %s", vol.Name)
	ephemeral := vol.Ephemeral
	if ephemeral == nil {
		return nil
	}

	pvcName := pod.Name + "-" + vol.Name
	pvc, err := ec.pvcLister.PersistentVolumeClaims(pod.Namespace).Get(pvcName)
	if err != nil && !errors.IsNotFound(err) {
		return err
	}
	if pvc != nil {
		if metav1.IsControlledBy(pvc, pod) {
			// Already created, nothing more to do.
			klog.V(5).Infof("ephemeral: volume %s: PVC %s already created", vol.Name, pvcName)
			return nil
		}
		return fmt.Errorf("PVC %q (uid: %q) was not created for the pod",
			util.GetPersistentVolumeClaimQualifiedName(pvc), pvc.UID)
	}

	// Create the PVC with pod as owner.
	isTrue := true
	pvc = &v1.PersistentVolumeClaim{
		ObjectMeta: metav1.ObjectMeta{
			Name: pvcName,
			OwnerReferences: []metav1.OwnerReference{
				{
					APIVersion:         "v1",
					Kind:               "Pod",
					Name:               pod.Name,
					UID:                pod.UID,
					Controller:         &isTrue,
					BlockOwnerDeletion: &isTrue,
				},
			},
			Annotations: ephemeral.VolumeClaimTemplate.Annotations,
			Labels:      ephemeral.VolumeClaimTemplate.Labels,
		},
		Spec: ephemeral.VolumeClaimTemplate.Spec,
	}
	_, err = ec.kubeClient.CoreV1().PersistentVolumeClaims(pod.Namespace).Create(context.TODO(), pvc, metav1.CreateOptions{})
	if err != nil {
		return fmt.Errorf("create PVC %s: %v", pvcName, err)
	}
	return nil
}
// handleEphemeralVolume is invoked for each volume of a pod.
handleEphemeralVolume is invoked for each volume of a pod.
// handleEphemeralVolume is invoked for each volume of a pod .
func (ec *ephemeralController) handleVolume(pod *v1.Pod, vol v1.Volume) error {
	klog.V(5).Infof("ephemeral: checking volume %s", vol.Name)
	ephemeral := vol.Ephemeral
	if ephemeral == nil {
		return nil
	}
	pvcName := pod.Name + "-" + vol.Name
	pvc, err := ec.pvcLister.PersistentVolumeClaims(pod.Namespace).Get(pvcName)
	if err != nil && !errors.IsNotFound(err) {
		return err
	}
	if pvc != nil {
		if metav1.IsControlledBy(pvc, pod) {
			klog.V(5).Infof("ephemeral: volume %s: PVC %s already created", vol.Name, pvcName)
			return nil
		}
		return fmt.Errorf("PVC %q (uid: %q) was not created for the pod",
			util.GetPersistentVolumeClaimQualifiedName(pvc), pvc.UID)
	}
	isTrue := true
	pvc = &v1.PersistentVolumeClaim{
		ObjectMeta: metav1.ObjectMeta{
			Name: pvcName,
			OwnerReferences: []metav1.OwnerReference{
				{
					APIVersion:         "v1",
					Kind:               "Pod",
					Name:               pod.Name,
					UID:                pod.UID,
					Controller:         &isTrue,
					BlockOwnerDeletion: &isTrue,
				},
			},
			Annotations: ephemeral.VolumeClaimTemplate.Annotations,
			Labels:      ephemeral.VolumeClaimTemplate.Labels,
		},
		Spec: ephemeral.VolumeClaimTemplate.Spec,
	}
	_, err = ec.kubeClient.CoreV1().PersistentVolumeClaims(pod.Namespace).Create(context.TODO(), pvc, metav1.CreateOptions{})
	if err != nil {
		return fmt.Errorf("create PVC %s: %v", pvcName, err)
	}
	return nil
}
func ( ec * ephemeralController ) handleVolume ( pod * v1 . Pod , vol v1 . Volume ) error { klog . V ( 5 ) . Infof ( " " , vol . Name ) ephemeral := vol . Ephemeral if ephemeral == nil { return nil } pvcName := pod . Name + " " + vol . Name pvc , err := ec . pvcLister . PersistentVolumeClaims ( pod . Namespace ) . Get ( pvcName ) if err != nil && ! errors . IsNotFound ( err ) { return err } if pvc != nil { if metav1 . IsControlledBy ( pvc , pod ) { klog . V ( 5 ) . Infof ( " " , vol . Name , pvcName ) return nil } return fmt . Errorf ( " " , util . GetPersistentVolumeClaimQualifiedName ( pvc ) , pvc . UID ) } isTrue := true pvc = & v1 . PersistentVolumeClaim { ObjectMeta : metav1 . ObjectMeta { Name : pvcName , OwnerReferences : [ ] metav1 . OwnerReference { { APIVersion : " " , Kind : " " , Name : pod . Name , UID : pod . UID , Controller : & isTrue , BlockOwnerDeletion : & isTrue , } , } , Annotations : ephemeral . VolumeClaimTemplate . Annotations , Labels : ephemeral . VolumeClaimTemplate . Labels , } , Spec : ephemeral . VolumeClaimTemplate . Spec , } _ , err = ec . kubeClient . CoreV1 ( ) . PersistentVolumeClaims ( pod . Namespace ) . Create ( context . TODO ( ) , pvc , metav1 . CreateOptions { } ) if err != nil { return fmt . Errorf ( " " , pvcName , err ) } return nil }
handleEphemeralVolume is invoked for each volume of a pod.
handleEphemeralVolume is invoked for each volume of a pod .
// Already created, nothing more to do. // Create the PVC with pod as owner.