Merge pull request #124 from Madhu-1/fix-eff

Fix golint issues
This commit is contained in:
Huamin Chen 2019-01-15 15:07:15 -05:00 committed by GitHub
commit 7b5b9772ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 63 additions and 68 deletions

View File

@ -82,7 +82,7 @@ func getCephUser(adminCr *credentials, volId volumeID) (*cephEntity, error) {
func createCephUser(volOptions *volumeOptions, adminCr *credentials, volId volumeID) (*cephEntity, error) { func createCephUser(volOptions *volumeOptions, adminCr *credentials, volId volumeID) (*cephEntity, error) {
caps := cephEntityCaps{ caps := cephEntityCaps{
Mds: fmt.Sprintf("allow rw path=%s", getVolumeRootPath_ceph(volId)), Mds: fmt.Sprintf("allow rw path=%s", getVolumeRootPathCeph(volId)),
Mon: "allow r", Mon: "allow r",
Osd: fmt.Sprintf("allow rw pool=%s namespace=%s", volOptions.Pool, getVolumeNamespace(volId)), Osd: fmt.Sprintf("allow rw pool=%s namespace=%s", volOptions.Pool, getVolumeNamespace(volId)),
} }

View File

@ -35,7 +35,7 @@ type nodeServer struct {
func getCredentialsForVolume(volOptions *volumeOptions, volId volumeID, req *csi.NodeStageVolumeRequest) (*credentials, error) { func getCredentialsForVolume(volOptions *volumeOptions, volId volumeID, req *csi.NodeStageVolumeRequest) (*credentials, error) {
var ( var (
userCr = &credentials{} userCr *credentials
err error err error
) )
@ -95,7 +95,7 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
if volOptions.ProvisionVolume { if volOptions.ProvisionVolume {
// Dynamically provisioned volumes don't have their root path set, do it here // Dynamically provisioned volumes don't have their root path set, do it here
volOptions.RootPath = getVolumeRootPath_ceph(volId) volOptions.RootPath = getVolumeRootPathCeph(volId)
} }
if err = createMountPoint(stagingTargetPath); err != nil { if err = createMountPoint(stagingTargetPath); err != nil {

View File

@ -92,11 +92,9 @@ func storeCephCredentials(volId volumeID, cr *credentials) error {
VolumeID: volId, VolumeID: volId,
} }
if err := secret.writeToFile(); err != nil { err := secret.writeToFile()
return err
}
return nil return err
} }
// //

View File

@ -29,15 +29,15 @@ const (
namespacePrefix = "ns-" namespacePrefix = "ns-"
) )
func getCephRootPath_local(volId volumeID) string { func getCephRootPathLocal(volId volumeID) string {
return cephRootPrefix + string(volId) return cephRootPrefix + string(volId)
} }
func getCephRootVolumePath_local(volId volumeID) string { func getCephRootVolumePathLocal(volId volumeID) string {
return path.Join(getCephRootPath_local(volId), cephVolumesRoot, string(volId)) return path.Join(getCephRootPathLocal(volId), cephVolumesRoot, string(volId))
} }
func getVolumeRootPath_ceph(volId volumeID) string { func getVolumeRootPathCeph(volId volumeID) string {
return path.Join("/", cephVolumesRoot, string(volId)) return path.Join("/", cephVolumesRoot, string(volId))
} }
@ -50,7 +50,7 @@ func setVolumeAttribute(root, attrName, attrValue string) error {
} }
func createVolume(volOptions *volumeOptions, adminCr *credentials, volId volumeID, bytesQuota int64) error { func createVolume(volOptions *volumeOptions, adminCr *credentials, volId volumeID, bytesQuota int64) error {
cephRoot := getCephRootPath_local(volId) cephRoot := getCephRootPathLocal(volId)
if err := createMountPoint(cephRoot); err != nil { if err := createMountPoint(cephRoot); err != nil {
return err return err
@ -74,8 +74,8 @@ func createVolume(volOptions *volumeOptions, adminCr *credentials, volId volumeI
os.Remove(cephRoot) os.Remove(cephRoot)
}() }()
volOptions.RootPath = getVolumeRootPath_ceph(volId) volOptions.RootPath = getVolumeRootPathCeph(volId)
localVolRoot := getCephRootVolumePath_local(volId) localVolRoot := getCephRootVolumePathLocal(volId)
if err := createMountPoint(localVolRoot); err != nil { if err := createMountPoint(localVolRoot); err != nil {
return err return err
@ -91,17 +91,15 @@ func createVolume(volOptions *volumeOptions, adminCr *credentials, volId volumeI
return fmt.Errorf("%v\ncephfs: Does pool '%s' exist?", err, volOptions.Pool) return fmt.Errorf("%v\ncephfs: Does pool '%s' exist?", err, volOptions.Pool)
} }
if err := setVolumeAttribute(localVolRoot, "ceph.dir.layout.pool_namespace", getVolumeNamespace(volId)); err != nil { err = setVolumeAttribute(localVolRoot, "ceph.dir.layout.pool_namespace", getVolumeNamespace(volId))
return err
}
return nil return err
} }
func purgeVolume(volId volumeID, adminCr *credentials, volOptions *volumeOptions) error { func purgeVolume(volId volumeID, adminCr *credentials, volOptions *volumeOptions) error {
var ( var (
cephRoot = getCephRootPath_local(volId) cephRoot = getCephRootPathLocal(volId)
volRoot = getCephRootVolumePath_local(volId) volRoot = getCephRootVolumePathLocal(volId)
volRootDeleting = volRoot + "-deleting" volRootDeleting = volRoot + "-deleting"
) )

View File

@ -24,8 +24,8 @@ import (
) )
const ( const (
volumeMounter_fuse = "fuse" volumeMounterFuse = "fuse"
volumeMounter_kernel = "kernel" volumeMounterKernel = "kernel"
) )
var ( var (
@ -39,11 +39,11 @@ func loadAvailableMounters() error {
kernelMounterProbe := exec.Command("mount.ceph") kernelMounterProbe := exec.Command("mount.ceph")
if fuseMounterProbe.Run() == nil { if fuseMounterProbe.Run() == nil {
availableMounters = append(availableMounters, volumeMounter_fuse) availableMounters = append(availableMounters, volumeMounterFuse)
} }
if kernelMounterProbe.Run() == nil { if kernelMounterProbe.Run() == nil {
availableMounters = append(availableMounters, volumeMounter_kernel) availableMounters = append(availableMounters, volumeMounterKernel)
} }
if len(availableMounters) == 0 { if len(availableMounters) == 0 {
@ -87,9 +87,9 @@ func newMounter(volOptions *volumeOptions) (volumeMounter, error) {
// Create the mounter // Create the mounter
switch chosenMounter { switch chosenMounter {
case volumeMounter_fuse: case volumeMounterFuse:
return &fuseMounter{}, nil return &fuseMounter{}, nil
case volumeMounter_kernel: case volumeMounterKernel:
return &kernelMounter{}, nil return &kernelMounter{}, nil
} }

View File

@ -17,7 +17,6 @@ limitations under the License.
package cephfs package cephfs
import ( import (
"errors"
"fmt" "fmt"
"strconv" "strconv"
) )
@ -70,18 +69,18 @@ func (o *volumeOptions) validate() error {
} }
func extractOption(dest *string, optionLabel string, options map[string]string) error { func extractOption(dest *string, optionLabel string, options map[string]string) error {
if opt, ok := options[optionLabel]; !ok { opt, ok := options[optionLabel]
return errors.New("Missing required field " + optionLabel) if !ok {
} else { return fmt.Errorf("Missing required field %s", optionLabel)
}
*dest = opt *dest = opt
return nil return nil
}
} }
func validateMounter(m string) error { func validateMounter(m string) error {
switch m { switch m {
case volumeMounter_fuse: case volumeMounterFuse:
case volumeMounter_kernel: case volumeMounterKernel:
default: default:
return fmt.Errorf("Unknown mounter '%s'. Valid options are 'fuse' and 'kernel'", m) return fmt.Errorf("Unknown mounter '%s'. Valid options are 'fuse' and 'kernel'", m)
} }

View File

@ -24,6 +24,7 @@ import (
"time" "time"
"github.com/ceph/ceph-csi/pkg/util" "github.com/ceph/ceph-csi/pkg/util"
"github.com/container-storage-interface/spec/lib/go/csi/v0" "github.com/container-storage-interface/spec/lib/go/csi/v0"
"github.com/golang/glog" "github.com/golang/glog"
"github.com/kubernetes-csi/drivers/pkg/csi-common" "github.com/kubernetes-csi/drivers/pkg/csi-common"
@ -89,10 +90,10 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
// check for the requested capacity and already allocated capacity // check for the requested capacity and already allocated capacity
if exVol, err := getRBDVolumeByName(req.GetName()); err == nil { if exVol, err := getRBDVolumeByName(req.GetName()); err == nil {
// Since err is nil, it means the volume with the same name already exists // Since err is nil, it means the volume with the same name already exists
// need to check if the size of exisiting volume is the same as in new // need to check if the size of existing volume is the same as in new
// request // request
if exVol.VolSize >= int64(req.GetCapacityRange().GetRequiredBytes()) { if exVol.VolSize >= int64(req.GetCapacityRange().GetRequiredBytes()) {
// exisiting volume is compatible with new request and should be reused. // existing volume is compatible with new request and should be reused.
// TODO (sbezverk) Do I need to make sure that RBD volume still exists? // TODO (sbezverk) Do I need to make sure that RBD volume still exists?
return &csi.CreateVolumeResponse{ return &csi.CreateVolumeResponse{
Volume: &csi.Volume{ Volume: &csi.Volume{
@ -102,7 +103,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
}, },
}, nil }, nil
} }
return nil, status.Error(codes.AlreadyExists, fmt.Sprintf("Volume with the same name: %s but with different size already exist", req.GetName())) return nil, status.Errorf(codes.AlreadyExists, "Volume with the same name: %s but with different size already exist", req.GetName())
} }
// TODO (sbezverk) Last check for not exceeding total storage capacity // TODO (sbezverk) Last check for not exceeding total storage capacity
@ -268,7 +269,7 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
}, },
}, nil }, nil
} }
return nil, status.Error(codes.AlreadyExists, fmt.Sprintf("Snapshot with the same name: %s but with different source volume id already exist", req.GetName())) return nil, status.Errorf(codes.AlreadyExists, "Snapshot with the same name: %s but with different source volume id already exist", req.GetName())
} }
rbdSnap, err := getRBDSnapshotOptions(req.GetParameters()) rbdSnap, err := getRBDSnapshotOptions(req.GetParameters())
@ -281,7 +282,7 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
uniqueID := uuid.NewUUID().String() uniqueID := uuid.NewUUID().String()
rbdVolume, err := getRBDVolumeByID(req.GetSourceVolumeId()) rbdVolume, err := getRBDVolumeByID(req.GetSourceVolumeId())
if err != nil { if err != nil {
return nil, status.Error(codes.NotFound, fmt.Sprintf("Source Volume ID %s cannot found", req.GetSourceVolumeId())) return nil, status.Errorf(codes.NotFound, "Source Volume ID %s cannot found", req.GetSourceVolumeId())
} }
if !hasSnapshotFeature(rbdVolume.ImageFeatures) { if !hasSnapshotFeature(rbdVolume.ImageFeatures) {
return nil, fmt.Errorf("Volume(%s) has not snapshot feature(layering)", req.GetSourceVolumeId()) return nil, fmt.Errorf("Volume(%s) has not snapshot feature(layering)", req.GetSourceVolumeId())
@ -322,7 +323,7 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
if err != nil { if err != nil {
return nil, fmt.Errorf("snapshot is created but failed to protect and delete snapshot: %v", err) return nil, fmt.Errorf("snapshot is created but failed to protect and delete snapshot: %v", err)
} }
return nil, fmt.Errorf("Snapshot is created but failed to protect snapshot") return nil, errors.New("snapshot is created but failed to protect snapshot")
} }
} }
@ -333,12 +334,12 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
// Unprotect snapshot // Unprotect snapshot
err := unprotectSnapshot(rbdSnap, rbdSnap.AdminId, req.GetCreateSnapshotSecrets()) err := unprotectSnapshot(rbdSnap, rbdSnap.AdminId, req.GetCreateSnapshotSecrets())
if err != nil { if err != nil {
return nil, status.Error(codes.Unknown, fmt.Sprintf("This Snapshot should be removed but failed to unprotect snapshot: %s/%s with error: %v", rbdSnap.Pool, rbdSnap.SnapName, err)) return nil, status.Errorf(codes.Unknown, "This Snapshot should be removed but failed to unprotect snapshot: %s/%s with error: %v", rbdSnap.Pool, rbdSnap.SnapName, err)
} }
// Deleting snapshot // Deleting snapshot
glog.V(4).Infof("deleting Snaphot %s", rbdSnap.SnapName) glog.V(4).Infof("deleting Snaphot %s", rbdSnap.SnapName)
if err := deleteSnapshot(rbdSnap, rbdSnap.AdminId, req.GetCreateSnapshotSecrets()); err != nil { if err := deleteSnapshot(rbdSnap, rbdSnap.AdminId, req.GetCreateSnapshotSecrets()); err != nil {
return nil, status.Error(codes.Unknown, fmt.Sprintf("This Snapshot should be removed but failed to delete snapshot: %s/%s with error: %v", rbdSnap.Pool, rbdSnap.SnapName, err)) return nil, status.Errorf(codes.Unknown, "This Snapshot should be removed but failed to delete snapshot: %s/%s with error: %v", rbdSnap.Pool, rbdSnap.SnapName, err)
} }
return nil, err return nil, err
} }
@ -378,13 +379,13 @@ func (cs *controllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS
// Unprotect snapshot // Unprotect snapshot
err := unprotectSnapshot(rbdSnap, rbdSnap.AdminId, req.GetDeleteSnapshotSecrets()) err := unprotectSnapshot(rbdSnap, rbdSnap.AdminId, req.GetDeleteSnapshotSecrets())
if err != nil { if err != nil {
return nil, status.Error(codes.FailedPrecondition, fmt.Sprintf("failed to unprotect snapshot: %s/%s with error: %v", rbdSnap.Pool, rbdSnap.SnapName, err)) return nil, status.Errorf(codes.FailedPrecondition, "failed to unprotect snapshot: %s/%s with error: %v", rbdSnap.Pool, rbdSnap.SnapName, err)
} }
// Deleting snapshot // Deleting snapshot
glog.V(4).Infof("deleting Snaphot %s", rbdSnap.SnapName) glog.V(4).Infof("deleting Snaphot %s", rbdSnap.SnapName)
if err := deleteSnapshot(rbdSnap, rbdSnap.AdminId, req.GetDeleteSnapshotSecrets()); err != nil { if err := deleteSnapshot(rbdSnap, rbdSnap.AdminId, req.GetDeleteSnapshotSecrets()); err != nil {
return nil, status.Error(codes.FailedPrecondition, fmt.Sprintf("failed to delete snapshot: %s/%s with error: %v", rbdSnap.Pool, rbdSnap.SnapName, err)) return nil, status.Errorf(codes.FailedPrecondition, "failed to delete snapshot: %s/%s with error: %v", rbdSnap.Pool, rbdSnap.SnapName, err)
} }
if err := cs.MetadataStore.Delete(snapshotID); err != nil { if err := cs.MetadataStore.Delete(snapshotID); err != nil {
@ -412,7 +413,7 @@ func (cs *controllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnap
if rbdSnap, ok := rbdSnapshots[snapshotID]; ok { if rbdSnap, ok := rbdSnapshots[snapshotID]; ok {
// if source volume ID also set, check source volume id on the cache. // if source volume ID also set, check source volume id on the cache.
if len(sourceVolumeId) != 0 && rbdSnap.SourceVolumeID != sourceVolumeId { if len(sourceVolumeId) != 0 && rbdSnap.SourceVolumeID != sourceVolumeId {
return nil, status.Error(codes.Unknown, fmt.Sprintf("Requested Source Volume ID %s is different from %s", sourceVolumeId, rbdSnap.SourceVolumeID)) return nil, status.Errorf(codes.Unknown, "Requested Source Volume ID %s is different from %s", sourceVolumeId, rbdSnap.SourceVolumeID)
} }
return &csi.ListSnapshotsResponse{ return &csi.ListSnapshotsResponse{
Entries: []*csi.ListSnapshotsResponse_Entry{ Entries: []*csi.ListSnapshotsResponse_Entry{
@ -429,9 +430,8 @@ func (cs *controllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnap
}, },
}, },
}, nil }, nil
} else {
return nil, status.Error(codes.NotFound, fmt.Sprintf("Snapshot ID %s cannot found", snapshotID))
} }
return nil, status.Errorf(codes.NotFound, "Snapshot ID %s cannot found", snapshotID)
} }
entries := []*csi.ListSnapshotsResponse_Entry{} entries := []*csi.ListSnapshotsResponse_Entry{}

View File

@ -104,7 +104,7 @@ func (rbd *rbd) Run(driverName, nodeID, endpoint string, containerized bool, cac
rbd.ids = NewIdentityServer(rbd.driver) rbd.ids = NewIdentityServer(rbd.driver)
rbd.ns, err = NewNodeServer(rbd.driver, containerized) rbd.ns, err = NewNodeServer(rbd.driver, containerized)
if err != nil { if err != nil {
glog.Fatalln("failed to start node server, err %v", err) glog.Fatalf("failed to start node server, err %v \n", err)
} }
rbd.cs = NewControllerServer(rbd.driver, cachePersister) rbd.cs = NewControllerServer(rbd.driver, cachePersister)

View File

@ -61,15 +61,15 @@ func getDevFromImageAndPool(pool, image string) (string, bool) {
// Search /sys/bus for rbd device that matches given pool and image. // Search /sys/bus for rbd device that matches given pool and image.
func getRbdDevFromImageAndPool(pool string, image string) (string, bool) { func getRbdDevFromImageAndPool(pool string, image string) (string, bool) {
// /sys/bus/rbd/devices/X/name and /sys/bus/rbd/devices/X/pool // /sys/bus/rbd/devices/X/name and /sys/bus/rbd/devices/X/pool
sys_path := "/sys/bus/rbd/devices" sysPath := "/sys/bus/rbd/devices"
if dirs, err := ioutil.ReadDir(sys_path); err == nil { if dirs, err := ioutil.ReadDir(sysPath); err == nil {
for _, f := range dirs { for _, f := range dirs {
// Pool and name format: // Pool and name format:
// see rbd_pool_show() and rbd_name_show() at // see rbd_pool_show() and rbd_name_show() at
// https://github.com/torvalds/linux/blob/master/drivers/block/rbd.c // https://github.com/torvalds/linux/blob/master/drivers/block/rbd.c
name := f.Name() name := f.Name()
// First match pool, then match name. // First match pool, then match name.
poolFile := path.Join(sys_path, name, "pool") poolFile := path.Join(sysPath, name, "pool")
poolBytes, err := ioutil.ReadFile(poolFile) poolBytes, err := ioutil.ReadFile(poolFile)
if err != nil { if err != nil {
glog.V(4).Infof("error reading %s: %v", poolFile, err) glog.V(4).Infof("error reading %s: %v", poolFile, err)
@ -79,7 +79,7 @@ func getRbdDevFromImageAndPool(pool string, image string) (string, bool) {
glog.V(4).Infof("device %s is not %q: %q", name, pool, string(poolBytes)) glog.V(4).Infof("device %s is not %q: %q", name, pool, string(poolBytes))
continue continue
} }
imgFile := path.Join(sys_path, name, "name") imgFile := path.Join(sysPath, name, "name")
imgBytes, err := ioutil.ReadFile(imgFile) imgBytes, err := ioutil.ReadFile(imgFile)
if err != nil { if err != nil {
glog.V(4).Infof("error reading %s: %v", imgFile, err) glog.V(4).Infof("error reading %s: %v", imgFile, err)

View File

@ -102,13 +102,14 @@ func getMon(pOpts *rbdVolume, credentials map[string]string) (string, error) {
// if mons are set in secret, retrieve them // if mons are set in secret, retrieve them
if len(pOpts.MonValueFromSecret) == 0 { if len(pOpts.MonValueFromSecret) == 0 {
// yet another sanity check // yet another sanity check
return "", fmt.Errorf("either monitors or monValueFromSecret must be set") return "", errors.New("either monitors or monValueFromSecret must be set")
} }
if val, ok := credentials[pOpts.MonValueFromSecret]; !ok { val, ok := credentials[pOpts.MonValueFromSecret]
if !ok {
return "", fmt.Errorf("mon data %s is not set in secret", pOpts.MonValueFromSecret) return "", fmt.Errorf("mon data %s is not set in secret", pOpts.MonValueFromSecret)
} else {
mon = val
} }
mon = val
} }
return mon, nil return mon, nil
} }
@ -187,10 +188,9 @@ func rbdStatus(pOpts *rbdVolume, userId string, credentials map[string]string) (
if strings.Contains(output, imageWatcherStr) { if strings.Contains(output, imageWatcherStr) {
glog.V(4).Infof("rbd: watchers on %s: %s", image, output) glog.V(4).Infof("rbd: watchers on %s: %s", image, output)
return true, output, nil return true, output, nil
} else { }
glog.Warningf("rbd: no watchers on %s", image) glog.Warningf("rbd: no watchers on %s", image)
return false, output, nil return false, output, nil
}
} }
// DeleteImage deletes a ceph image with provision and volume options. // DeleteImage deletes a ceph image with provision and volume options.
@ -234,13 +234,13 @@ func getRBDVolumeOptions(volOptions map[string]string) (*rbdVolume, error) {
rbdVol := &rbdVolume{} rbdVol := &rbdVolume{}
rbdVol.Pool, ok = volOptions["pool"] rbdVol.Pool, ok = volOptions["pool"]
if !ok { if !ok {
return nil, fmt.Errorf("Missing required parameter pool") return nil, errors.New("Missing required parameter pool")
} }
rbdVol.Monitors, ok = volOptions["monitors"] rbdVol.Monitors, ok = volOptions["monitors"]
if !ok { if !ok {
// if mons are not set in options, check if they are set in secret // if mons are not set in options, check if they are set in secret
if rbdVol.MonValueFromSecret, ok = volOptions["monValueFromSecret"]; !ok { if rbdVol.MonValueFromSecret, ok = volOptions["monValueFromSecret"]; !ok {
return nil, fmt.Errorf("Either monitors or monValueFromSecret must be set") return nil, errors.New("Either monitors or monValueFromSecret must be set")
} }
} }
rbdVol.ImageFormat, ok = volOptions["imageFormat"] rbdVol.ImageFormat, ok = volOptions["imageFormat"]
@ -282,13 +282,13 @@ func getRBDSnapshotOptions(snapOptions map[string]string) (*rbdSnapshot, error)
rbdSnap := &rbdSnapshot{} rbdSnap := &rbdSnapshot{}
rbdSnap.Pool, ok = snapOptions["pool"] rbdSnap.Pool, ok = snapOptions["pool"]
if !ok { if !ok {
return nil, fmt.Errorf("Missing required parameter pool") return nil, errors.New("Missing required parameter pool")
} }
rbdSnap.Monitors, ok = snapOptions["monitors"] rbdSnap.Monitors, ok = snapOptions["monitors"]
if !ok { if !ok {
// if mons are not set in options, check if they are set in secret // if mons are not set in options, check if they are set in secret
if rbdSnap.MonValueFromSecret, ok = snapOptions["monValueFromSecret"]; !ok { if rbdSnap.MonValueFromSecret, ok = snapOptions["monValueFromSecret"]; !ok {
return nil, fmt.Errorf("Either monitors or monValueFromSecret must be set") return nil, errors.New("Either monitors or monValueFromSecret must be set")
} }
} }
rbdSnap.AdminId, ok = snapOptions["adminid"] rbdSnap.AdminId, ok = snapOptions["adminid"]
@ -344,13 +344,13 @@ func getSnapMon(pOpts *rbdSnapshot, credentials map[string]string) (string, erro
// if mons are set in secret, retrieve them // if mons are set in secret, retrieve them
if len(pOpts.MonValueFromSecret) == 0 { if len(pOpts.MonValueFromSecret) == 0 {
// yet another sanity check // yet another sanity check
return "", fmt.Errorf("either monitors or monValueFromSecret must be set") return "", errors.New("either monitors or monValueFromSecret must be set")
} }
if val, ok := credentials[pOpts.MonValueFromSecret]; !ok { val, ok := credentials[pOpts.MonValueFromSecret]
if !ok {
return "", fmt.Errorf("mon data %s is not set in secret", pOpts.MonValueFromSecret) return "", fmt.Errorf("mon data %s is not set in secret", pOpts.MonValueFromSecret)
} else {
mon = val
} }
mon = val
} }
return mon, nil return mon, nil
} }

View File

@ -65,7 +65,7 @@ func (nc *NodeCache) ForAll(pattern string, destObj interface{}, f ForAllFunc) e
} }
fp, err := os.Open(path.Join(nc.BasePath, cacheDir, file.Name())) fp, err := os.Open(path.Join(nc.BasePath, cacheDir, file.Name()))
if err != nil { if err != nil {
glog.Infof("node-cache: open file: %s err %%v", file.Name(), err) glog.Infof("node-cache: open file: %s err %v", file.Name(), err)
continue continue
} }
decoder := json.NewDecoder(fp) decoder := json.NewDecoder(fp)