Unverified Commit 23794089 by Kubernetes Prow Robot Committed by GitHub

Merge pull request #176 from humblec/new

Handle error and also correct error strings.
parents 69979f8f 7c23a7dd
# See the OWNERS docs at https://go.k8s.io/owners # See the OWNERS docs at https://go.k8s.io/owners
approvers: approvers:
- wongma7 - ashishranjan738
- humblec
- jackielii
- jsafrane - jsafrane
- kmova - kmova
- jackielii
- ashishranjan738
- yonatankahana - yonatankahana
- wongma7
...@@ -62,13 +62,14 @@ func (meta *pvcMetadata) stringParser(str string) string { ...@@ -62,13 +62,14 @@ func (meta *pvcMetadata) stringParser(str string) string {
for _, r := range result { for _, r := range result {
switch r[2] { switch r[2] {
case "labels": case "labels":
str = strings.Replace(str, r[0], meta.labels[r[3]], -1) str = strings.ReplaceAll(str, r[0], meta.labels[r[3]])
case "annotations": case "annotations":
str = strings.Replace(str, r[0], meta.annotations[r[3]], -1) str = strings.ReplaceAll(str, r[0], meta.annotations[r[3]])
default: default:
str = strings.Replace(str, r[0], meta.data[r[1]], -1) str = strings.ReplaceAll(str, r[0], meta.data[r[1]])
} }
} }
return str return str
} }
...@@ -111,10 +112,13 @@ func (p *nfsProvisioner) Provision(ctx context.Context, options controller.Provi ...@@ -111,10 +112,13 @@ func (p *nfsProvisioner) Provision(ctx context.Context, options controller.Provi
} }
glog.V(4).Infof("creating path %s", fullPath) glog.V(4).Infof("creating path %s", fullPath)
if err := os.MkdirAll(fullPath, 0777); err != nil { if err := os.MkdirAll(fullPath, 0o777); err != nil {
return nil, controller.ProvisioningFinished, errors.New("unable to create directory to provision new pv: " + err.Error()) return nil, controller.ProvisioningFinished, errors.New("unable to create directory to provision new pv: " + err.Error())
} }
os.Chmod(fullPath, 0777) err := os.Chmod(fullPath, 0o777)
if err != nil {
return nil, "", err
}
pv := &v1.PersistentVolume{ pv := &v1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
...@@ -155,14 +159,12 @@ func (p *nfsProvisioner) Delete(ctx context.Context, volume *v1.PersistentVolume ...@@ -155,14 +159,12 @@ func (p *nfsProvisioner) Delete(ctx context.Context, volume *v1.PersistentVolume
} }
// Determine if the "onDelete" parameter exists. // Determine if the "onDelete" parameter exists.
// If it exists and has a delete value, delete the directory. // If it exists and has a `delete` value, delete the directory.
// If it exists and has a retain value, safe the directory. // If it exists and has a `retain` value, safe the directory.
onDelete := storageClass.Parameters["onDelete"] onDelete := storageClass.Parameters["onDelete"]
switch onDelete { switch onDelete {
case "delete": case "delete":
return os.RemoveAll(oldPath) return os.RemoveAll(oldPath)
case "retain": case "retain":
return nil return nil
} }
...@@ -186,19 +188,20 @@ func (p *nfsProvisioner) Delete(ctx context.Context, volume *v1.PersistentVolume ...@@ -186,19 +188,20 @@ func (p *nfsProvisioner) Delete(ctx context.Context, volume *v1.PersistentVolume
return os.Rename(oldPath, archivePath) return os.Rename(oldPath, archivePath)
} }
// getClassForVolume returns StorageClass // getClassForVolume returns StorageClass.
func (p *nfsProvisioner) getClassForVolume(ctx context.Context, pv *v1.PersistentVolume) (*storage.StorageClass, error) { func (p *nfsProvisioner) getClassForVolume(ctx context.Context, pv *v1.PersistentVolume) (*storage.StorageClass, error) {
if p.client == nil { if p.client == nil {
return nil, fmt.Errorf("Cannot get kube client") return nil, fmt.Errorf("cannot get kube client")
} }
className := helper.GetPersistentVolumeClass(pv) className := helper.GetPersistentVolumeClass(pv)
if className == "" { if className == "" {
return nil, fmt.Errorf("Volume has no storage class") return nil, fmt.Errorf("volume has no storage class")
} }
class, err := p.client.StorageV1().StorageClasses().Get(ctx, className, metav1.GetOptions{}) class, err := p.client.StorageV1().StorageClasses().Get(ctx, className, metav1.GetOptions{})
if err != nil { if err != nil {
return nil, err return nil, err
} }
return class, nil return class, nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment