mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-10 08:20:23 +00:00
76 lines
1.8 KiB
Go
76 lines
1.8 KiB
Go
/*
|
|
Copyright 2018 The Kubernetes Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package cephfs
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
type volumeOptions struct {
|
|
Monitors string `json:"monitors"`
|
|
RootPath string `json:"rootPath"`
|
|
User string `json:"user"`
|
|
Mounter string `json:"mounter"`
|
|
}
|
|
|
|
func extractOption(dest *string, optionLabel string, options map[string]string) error {
|
|
if opt, ok := options[optionLabel]; !ok {
|
|
return errors.New("Missing required parameter " + optionLabel)
|
|
} else {
|
|
*dest = opt
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func validateMounter(m string) error {
|
|
switch m {
|
|
case volumeMounter_fuse:
|
|
case volumeMounter_kernel:
|
|
default:
|
|
return fmt.Errorf("Unknown mounter '%s'. Valid options are 'fuse' and 'kernel'", m)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func newVolumeOptions(volOptions map[string]string) (*volumeOptions, error) {
|
|
var opts volumeOptions
|
|
|
|
if err := extractOption(&opts.Monitors, "monitors", volOptions); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := extractOption(&opts.RootPath, "rootPath", volOptions); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := extractOption(&opts.User, "user", volOptions); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := extractOption(&opts.Mounter, "mounter", volOptions); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := validateMounter(opts.Mounter); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &opts, nil
|
|
}
|