非常简单的provisioner,我们可以学习下如何实现一个provisioner
https://github.com/kubernetes-retired/external-storage/blob/master/nfs-client/cmd/nfs-client-provisioner/provisioner.go
核心函数
const (mountPath = "/persistentvolumes")func (p *nfsProvisioner) Provision(options controller.VolumeOptions) (*v1.PersistentVolume, error) {if options.PVC.Spec.Selector != nil {return nil, fmt.Errorf("claim Selector is not supported")}glog.V(4).Infof("nfs provisioner: VolumeOptions %v", options)pvcNamespace := options.PVC.NamespacepvcName := options.PVC.NamepvName := strings.Join([]string{pvcNamespace, pvcName, options.PVName}, "-")fullPath := filepath.Join(mountPath, pvName)glog.V(4).Infof("creating path %s", fullPath)if err := os.MkdirAll(fullPath, 0777); err != nil {return nil, errors.New("unable to create directory to provision new pv: " + err.Error())}os.Chmod(fullPath, 0777)path := filepath.Join(p.path, pvName)pv := &v1.PersistentVolume{ObjectMeta: metav1.ObjectMeta{Name: options.PVName,},Spec: v1.PersistentVolumeSpec{PersistentVolumeReclaimPolicy: options.PersistentVolumeReclaimPolicy,AccessModes: options.PVC.Spec.AccessModes,MountOptions: options.MountOptions,Capacity: v1.ResourceList{v1.ResourceName(v1.ResourceStorage): options.PVC.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)],},PersistentVolumeSource: v1.PersistentVolumeSource{NFS: &v1.NFSVolumeSource{Server: p.server,Path: path,ReadOnly: false,},},},}return pv, nil}
非常简洁,判断下目录是否存在,,如果不存在就把目录创建出来,然后把元信息返回出去就行了。
