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

added support for secretName in PV volumeAttributes to override the default #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
31 changes: 23 additions & 8 deletions pkg/rclone/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
mountOptions = append(mountOptions, "ro")
}

// Load default connection settings from secret
secret, e := getSecret("rclone-secret")

remote, remotePath, flags, e := extractFlags(req.GetVolumeContext(), secret)
remote, remotePath, flags, e := extractFlags(req.GetVolumeContext())
if e != nil {
klog.Warningf("storage parameter error: %s", e)
return nil, e
Expand All @@ -97,13 +94,30 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
return &csi.NodePublishVolumeResponse{}, nil
}

func extractFlags(volumeContext map[string]string, secret *v1.Secret) (string, string, map[string]string, error) {
func extractFlags(volumeContext map[string]string) (string, string, map[string]string, error) {

// Load default connection settings from secret

var secret *v1.Secret

if secretName, ok := volumeContext["secretName"]; ok {
// Load the secret that the PV spec defines
var e error
secret, e = getSecret(secretName)
if e != nil {
// if the user explicitly requested a secret and there is an error fetching it, bail with an error
return "", "", nil, e
}
} else {
// use rclone-secret as the default secret if none was defined
secret, _ = getSecret("rclone-secret")
}

// Empty argument list
flags := make(map[string]string)

// Secret values are default, gets merged and overriden by corresponding PV values
if secret !=nil && secret.Data != nil && len(secret.Data) > 0 {
if secret != nil && secret.Data != nil && len(secret.Data) > 0 {

// Needs byte to string casting for map values
for k, v := range secret.Data {
Expand Down Expand Up @@ -133,6 +147,7 @@ func extractFlags(volumeContext map[string]string, secret *v1.Secret) (string, s

delete(flags, "remote")
delete(flags, "remotePath")
delete(flags, "secretName")

return remote, remotePath, flags, nil
}
Expand All @@ -152,10 +167,10 @@ func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
if err != nil && !mount.IsCorruptedMnt(err) {
return nil, status.Error(codes.Internal, err.Error())
}

if notMnt && !mount.IsCorruptedMnt(err) {
klog.Infof("Volume not mounted")

} else {
err = util.UnmountPath(req.GetTargetPath(), m)
if err != nil {
Expand Down