27 lines
853 B
Go
27 lines
853 B
Go
package k8s
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
)
|
|
|
|
func (c *Client) ResolvePVCVolume(ctx context.Context, namespace, pvcName string) (string, *corev1.PersistentVolumeClaim, *corev1.PersistentVolume, error) {
|
|
pvc, err := c.Clientset.CoreV1().PersistentVolumeClaims(namespace).Get(ctx, pvcName, metav1.GetOptions{})
|
|
if err != nil {
|
|
return "", nil, nil, fmt.Errorf("get pvc %s/%s: %w", namespace, pvcName, err)
|
|
}
|
|
if pvc.Spec.VolumeName == "" {
|
|
return "", pvc, nil, fmt.Errorf("pvc %s/%s has no bound volume", namespace, pvcName)
|
|
}
|
|
|
|
pv, err := c.Clientset.CoreV1().PersistentVolumes().Get(ctx, pvc.Spec.VolumeName, metav1.GetOptions{})
|
|
if err != nil {
|
|
return "", pvc, nil, fmt.Errorf("get pv %s: %w", pvc.Spec.VolumeName, err)
|
|
}
|
|
|
|
return pvc.Spec.VolumeName, pvc, pv, nil
|
|
}
|