Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the OSSFS pod name visible in VolumeAttachment #1221

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions pkg/mounter/fuse_pod_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (fpm *FusePodManager) labelsAndListOptionsFor(c *FusePodContext, target str
return labels, listOptions
}

func (fpm *FusePodManager) Create(c *FusePodContext, target string, atomic bool) error {
func (fpm *FusePodManager) Create(c *FusePodContext, target string, atomic bool) (*corev1.Pod, error) {
ctx, cancel := context.WithTimeout(c, fusePodManagerTimeout)
defer cancel()

Expand All @@ -219,10 +219,9 @@ func (fpm *FusePodManager) Create(c *FusePodContext, target string, atomic bool)
labels, listOptions := fpm.labelsAndListOptionsFor(c, target)
podList, err := podClient.List(ctx, listOptions)
if err != nil {
return err
return nil, err
}

ready := false
var startingPods []corev1.Pod
for _, pod := range podList.Items {
// compare target path to avoid hash conflict
Expand All @@ -236,25 +235,22 @@ func (fpm *FusePodManager) Create(c *FusePodContext, target string, atomic bool)
logger.V(1).Info("fuse pod exited, will be cleaned when unmount", "pod", pod.Name)
case corev1.PodRunning:
if isFusePodReady(&pod) {
ready = true
logger.V(2).Info("already mounted by pod", "pod", pod.Name, "target", target)
return &pod, nil
} else {
startingPods = append(startingPods, pod)
}
default:
startingPods = append(startingPods, pod)
}
}
if ready {
return nil
}

var fusePod *corev1.Pod
if len(startingPods) == 0 {
// create fuse pod for target
template, err := fpm.PodTemplateSpec(c, target)
if err != nil {
return err
return nil, err
}
rawPod := corev1.Pod{
ObjectMeta: template.ObjectMeta,
Expand All @@ -281,14 +277,14 @@ func (fpm *FusePodManager) Create(c *FusePodContext, target string, atomic bool)
if rawPod.Spec.ServiceAccountName != "" {
_, err := fpm.client.CoreV1().ServiceAccounts(c.Namespace).Get(c, rawPod.Spec.ServiceAccountName, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("check service account %s for RRSA: %w", rawPod.Spec.ServiceAccountName, err)
return nil, fmt.Errorf("check service account %s for RRSA: %w", rawPod.Spec.ServiceAccountName, err)
}
}

logger.V(2).Info("creating fuse pod", "target", target)
createdPod, err := podClient.Create(ctx, &rawPod, metav1.CreateOptions{})
if err != nil {
return err
return nil, err
}
logger.V(2).Info("created fuse pod", "pod", createdPod.Name, "target", target)
fusePod = createdPod
Expand Down Expand Up @@ -320,6 +316,7 @@ func (fpm *FusePodManager) Create(c *FusePodContext, target string, atomic bool)
if !ok {
return false, errors.New("failed to cast event Object to Pod")
}
fusePod = pod
if pod.Status.Phase == corev1.PodSucceeded || pod.Status.Phase == corev1.PodFailed {
return false, fmt.Errorf("fuse pod %s exited", pod.Name)
}
Expand All @@ -333,10 +330,10 @@ func (fpm *FusePodManager) Create(c *FusePodContext, target string, atomic bool)
logger.Error(deleteErr, "delete fuse pod", "pod", fusePod.Name)
}
}
return err
return nil, err
}
logger.V(2).Info("fuse pod is ready", "pod", fusePod.Name)
return nil
return fusePod, nil
}

func (fpm *FusePodManager) Delete(c *FusePodContext, target string) error {
Expand Down
4 changes: 3 additions & 1 deletion pkg/oss/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (cs *controllerServer) ControllerPublishVolume(ctx context.Context, req *cs
return nil, err
}
// launch ossfs pod
err = cs.fusePodManager.Create(&mounter.FusePodContext{
ossfsPod, err := cs.fusePodManager.Create(&mounter.FusePodContext{
Context: ctx,
Namespace: fusePodNamespace,
NodeName: nodeName,
Expand All @@ -178,6 +178,8 @@ func (cs *controllerServer) ControllerPublishVolume(ctx context.Context, req *cs
return &csi.ControllerPublishVolumeResponse{
PublishContext: map[string]string{
mountProxySocket: mounter.GetOssfsMountProxySocketPath(req.VolumeId),
// make the OSSFS pod name visible in the VolumeAttachment status
"ossfsPod": fmt.Sprintf("%s/%s", ossfsPod.Namespace, ossfsPod.Name),
},
}, nil
}
Expand Down