Handle error in a some conditions and also correct error message
This commit also does: `Replace` string method changed to `ReplaceALL` Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
parent
2417ea0219
commit
e53fbc3d59
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,7 +115,10 @@ func (p *nfsProvisioner) Provision(ctx context.Context, options controller.Provi
|
||||||
if err := os.MkdirAll(fullPath, 0777); err != nil {
|
if err := os.MkdirAll(fullPath, 0777); 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, 0777)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
|
||||||
pv := &v1.PersistentVolume{
|
pv := &v1.PersistentVolume{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
|
@ -189,11 +193,11 @@ func (p *nfsProvisioner) Delete(ctx context.Context, volume *v1.PersistentVolume
|
||||||
// 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 {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue