Skip to content

Commit

Permalink
normalize function return, if block ends with a return statement, so …
Browse files Browse the repository at this point in the history
…drop this else and outdent its block (#827)
  • Loading branch information
sivanzcw authored and k8s-ci-robot committed Nov 27, 2019
1 parent 0bd11ab commit 0dfdb1c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 46 deletions.
22 changes: 11 additions & 11 deletions pkg/csi/manila/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,21 @@ func NewDriver(nodeID, driverName, endpoint, fwdEndpoint, shareProto string, man

var supportsNodeStage bool

if nodeCapsMap, err := d.initProxiedDriver(); err != nil {
nodeCapsMap, err := d.initProxiedDriver()
if err != nil {
return nil, fmt.Errorf("failed to initialize proxied CSI driver: %v", err)
} else {
var nscaps []csi.NodeServiceCapability_RPC_Type
for c := range nodeCapsMap {
nscaps = append(nscaps, c)

if c == csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME {
supportsNodeStage = true
}
}
}
var nscaps []csi.NodeServiceCapability_RPC_Type
for c := range nodeCapsMap {
nscaps = append(nscaps, c)

d.addNodeServiceCapabilities(nscaps)
if c == csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME {
supportsNodeStage = true
}
}

d.addNodeServiceCapabilities(nscaps)

d.ids = &identityServer{d: d}
d.cs = &controllerServer{d: d}
d.ns = &nodeServer{d: d, supportsNodeStage: supportsNodeStage, nodeStageCache: make(map[volumeID]stageCacheEntry)}
Expand Down
10 changes: 4 additions & 6 deletions pkg/flexvolume/flexvolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,12 @@ func (d *FlexVolumeDriver) doRun(args []string) (map[string]interface{}, error)
if cmdInfo, found := commands[op]; found {
if cmdInfo.numArgs == nArgs {
return cmdInfo.run(d, args[1:])
} else {
return nil, fmt.Errorf("unexpected number of args %d (expected %d) for operation %q", nArgs, cmdInfo.numArgs, op)
}
} else {
return map[string]interface{}{
"status": "Not supported",
}, nil
return nil, fmt.Errorf("unexpected number of args %d (expected %d) for operation %q", nArgs, cmdInfo.numArgs, op)
}
return map[string]interface{}{
"status": "Not supported",
}, nil
}

func (d *FlexVolumeDriver) Run(args []string) string {
Expand Down
36 changes: 16 additions & 20 deletions pkg/identity/keystone/authorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,44 +59,40 @@ func getAllowed(definition string, str string) (sets.String, error) {
// "!namespace"
if definition[1:] == str || definition[1:] == "*" {
return nil, fmt.Errorf("")
} else {
allowed.Insert(str)
}
allowed.Insert(str)
} else if strings.Index(definition, "[") == 0 && strings.Index(definition, "]") == (len(definition)-1) {
// "['namespace1', 'namespace2']"
var items []string
if err := json.Unmarshal([]byte(strings.Replace(definition, "'", "\"", -1)), &items); err != nil {
klog.V(4).Infof("Skip the permission definition %s", definition)
return nil, fmt.Errorf("")
} else {
for _, val := range items {
if val == "*" {
allowed.Insert(str)
continue
}
allowed.Insert(val)
}
for _, val := range items {
if val == "*" {
allowed.Insert(str)
continue
}
allowed.Insert(val)
}
} else if strings.Index(definition, "!") == 0 && strings.Index(definition, "[") == 1 && strings.Index(definition, "]") == (len(definition)-1) {
// "!['namespace1', 'namespace2']"
var items []string
if err := json.Unmarshal([]byte(strings.Replace(definition[1:], "'", "\"", -1)), &items); err != nil {
klog.V(4).Infof("Skip the permission definition %s", definition)
return nil, fmt.Errorf("")
} else {
found := false
for _, val := range items {
if val == str || val == "*" {
found = true
}
}
found := false
for _, val := range items {
if val == str || val == "*" {
found = true
}
}

if found {
return nil, fmt.Errorf("")
} else {
allowed.Insert(str)
}
if found {
return nil, fmt.Errorf("")
}
allowed.Insert(str)
}

return allowed, nil
Expand Down
16 changes: 7 additions & 9 deletions pkg/util/mount/mount_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,16 +494,14 @@ func (mounter *SafeFormatAndMount) formatAndMount(source string, target string,
}
klog.Errorf("format of disk %q failed: type:(%q) target:(%q) options:(%q)error:(%v)", source, fstype, target, options, err)
return err
} else {
// Disk is already formatted and failed to mount
if len(fstype) == 0 || fstype == existingFormat {
// This is mount error
return mountErr
} else {
// Block device is formatted with unexpected filesystem, let the user know
return fmt.Errorf("failed to mount the volume as %q, it already contains %s. Mount error: %v", fstype, existingFormat, mountErr)
}
}
// Disk is already formatted and failed to mount
if len(fstype) == 0 || fstype == existingFormat {
// This is mount error
return mountErr
}
// Block device is formatted with unexpected filesystem, let the user know
return fmt.Errorf("failed to mount the volume as %q, it already contains %s. Mount error: %v", fstype, existingFormat, mountErr)
}
return mountErr
}
Expand Down

0 comments on commit 0dfdb1c

Please sign in to comment.