diff --git a/cmd/worker/option/option.go b/cmd/worker/option/option.go index 1fceab57f..6fcd4cd1c 100644 --- a/cmd/worker/option/option.go +++ b/cmd/worker/option/option.go @@ -53,6 +53,7 @@ type Config struct { LeaderElectionNamespace string LeaderElectionIdentity string RBDNamespace string + GrdataPVCName string RBDDNSName string } @@ -93,6 +94,7 @@ func (a *Worker) AddFlags(fs *pflag.FlagSet) { flag.StringVar(&a.LeaderElectionNamespace, "leader-election-namespace", "rainbond", "Namespace where this attacher runs.") flag.StringVar(&a.LeaderElectionIdentity, "leader-election-identity", "", "Unique idenity of this attcher. Typically name of the pod where the attacher runs.") flag.StringVar(&a.RBDNamespace, "rbd-system-namespace", "rbd-system", "rbd components kubernetes namespace") + flag.StringVar(&a.GrdataPVCName, "grdata-pvc-name", "rbd-cpt-grdata", "The name of grdata persistent volume claim") flag.StringVar(&a.RBDDNSName, "rbd-dns", "rbd-dns", "rbd dns endpoint name") } diff --git a/util/comman.go b/util/comman.go index 084dcf029..d894da05d 100644 --- a/util/comman.go +++ b/util/comman.go @@ -788,4 +788,4 @@ func getVariableKey(source string) (key, value string) { return re[0], "" } return k, "" -} \ No newline at end of file +} diff --git a/worker/appm/volume/share-file.go b/worker/appm/volume/share-file.go index 049c7eda9..5e286e0b2 100644 --- a/worker/appm/volume/share-file.go +++ b/worker/appm/volume/share-file.go @@ -69,9 +69,6 @@ func (v *ShareFileVolume) CreateVolume(define *Define) error { } } hostPath := v.svm.HostPath - if v.as.IsWindowsService { - hostPath = RewriteHostPathInWindows(hostPath) - } vo := corev1.Volume{Name: volumeMountName} hostPathType := corev1.HostPathDirectoryOrCreate vo.HostPath = &corev1.HostPathVolumeSource{ diff --git a/worker/master/master.go b/worker/master/master.go index 085ab5e46..dce86a793 100644 --- a/worker/master/master.go +++ b/worker/master/master.go @@ -77,7 +77,7 @@ func NewMasterController(conf option.Config, store store.Storer) (*Controller, e rainbondsslcProvisioner := provider.NewRainbondsslcProvisioner(conf.KubeClient, store) // Start the provision controller which will dynamically provision hostPath // PVs - pc := controller.NewProvisionController(conf.KubeClient, map[string]controller.Provisioner{ + pc := controller.NewProvisionController(conf.KubeClient, &conf, map[string]controller.Provisioner{ rainbondssscProvisioner.Name(): rainbondssscProvisioner, rainbondsslcProvisioner.Name(): rainbondsslcProvisioner, }, serverVersion.GitVersion) diff --git a/worker/master/volumes/provider/lib/controller/controller.go b/worker/master/volumes/provider/lib/controller/controller.go index 35cbd14ff..f173027c4 100644 --- a/worker/master/volumes/provider/lib/controller/controller.go +++ b/worker/master/volumes/provider/lib/controller/controller.go @@ -21,6 +21,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/goodrain/rainbond/cmd/worker/option" "io/ioutil" "net/http" "os" @@ -79,6 +80,7 @@ const annSelectedNode = "volume.kubernetes.io/selected-node" // PersistentVolumeClaims. type ProvisionController struct { client kubernetes.Interface + cfg *option.Config // The provisioner the controller will use to provision and delete volumes. // Presumably this implementer of Provisioner carries its own @@ -409,6 +411,7 @@ func (ctrl *ProvisionController) HasRun() bool { // the given configuration parameters and with private (non-shared) informers. func NewProvisionController( client kubernetes.Interface, + cfg *option.Config, provisioners map[string]Provisioner, kubeVersion string, options ...func(*ProvisionController) error, @@ -429,6 +432,7 @@ func NewProvisionController( controller := &ProvisionController{ client: client, + cfg: cfg, provisioners: provisioners, kubeVersion: utilversion.MustParseSemantic(kubeVersion), id: id, @@ -1000,10 +1004,20 @@ func (ctrl *ProvisionController) provisionClaimOperation(claim *v1.PersistentVol } } + // Find pv for grdata + grdatapv, err := ctrl.persistentVolumeForGrdata() + if err != nil { + return fmt.Errorf("pv for grdata: %v", err) + } + if grdatapv.Spec.NFS == nil { + return fmt.Errorf("%s/%s; nfs not found for grdata pv", grdatapv.Name) + } + options := VolumeOptions{ PersistentVolumeReclaimPolicy: reclaimPolicy, PVName: pvName, PVC: claim, + NFS: grdatapv.Spec.NFS, MountOptions: mountOptions, Parameters: parameters, SelectedNode: selectedNode, @@ -1094,6 +1108,18 @@ func (ctrl *ProvisionController) provisionClaimOperation(claim *v1.PersistentVol return nil } +func (ctrl *ProvisionController) persistentVolumeForGrdata() (*v1.PersistentVolume, error) { + pvc, err := ctrl.client.CoreV1().PersistentVolumeClaims(ctrl.cfg.RBDNamespace).Get(ctrl.cfg.GrdataPVCName, metav1.GetOptions{}) + if err != nil { + return nil, fmt.Errorf("find pvc for grdata: %v", err) + } + pv, err := ctrl.client.CoreV1().PersistentVolumes().Get(pvc.Spec.VolumeName, metav1.GetOptions{}) + if err != nil { + return nil, fmt.Errorf("find pv for grdata: %v", err) + } + return pv, nil +} + // deleteVolumeOperation attempts to delete the volume backing the given // volume. Returns error, which indicates whether deletion should be retried // (requeue the volume) or not diff --git a/worker/master/volumes/provider/lib/controller/controller_test.go b/worker/master/volumes/provider/lib/controller/controller_test.go index 85f0b4dc8..db36f322a 100644 --- a/worker/master/volumes/provider/lib/controller/controller_test.go +++ b/worker/master/volumes/provider/lib/controller/controller_test.go @@ -650,7 +650,7 @@ func TestControllerExternalSharedInformers(t *testing.T) { newClaim("claim-1", "uid-1-1", "class-1", "foo.bar/baz", "", nil), }, provisionerName: "foo.bar/baz", - serverVersion: "v1.8.0", + serverVersion: "v1.8.0",w expectedVolumes: []v1.PersistentVolume{ *newProvisionedVolumeWithSpecifiedReclaimPolicy(newStorageClassWithSpecifiedReclaimPolicy("class-1", "foo.bar/baz", v1.PersistentVolumeReclaimDelete), newClaim("claim-1", "uid-1-1", "class-1", "foo.bar/baz", "", nil)), }, @@ -940,6 +940,11 @@ type testProvisioner struct { provisionCalls chan provisionParams } +func (t *testProvisioner) Name() string{ + return "" +} + +// Provisioner - var _ Provisioner = &testProvisioner{} func newTestQualifiedProvisioner(answer bool) *testQualifiedProvisioner { diff --git a/worker/master/volumes/provider/lib/controller/volume.go b/worker/master/volumes/provider/lib/controller/volume.go index 2a116b0fa..b6e8a7336 100644 --- a/worker/master/volumes/provider/lib/controller/volume.go +++ b/worker/master/volumes/provider/lib/controller/volume.go @@ -86,6 +86,8 @@ type VolumeOptions struct { // i.e. with required capacity, accessMode, labels matching PVC.Selector and // so on. PVC *v1.PersistentVolumeClaim + // NFS + NFS *v1.NFSVolumeSource // Volume provisioning parameters from StorageClass Parameters map[string]string diff --git a/worker/master/volumes/provider/rainbondsssc.go b/worker/master/volumes/provider/rainbondsssc.go index 61f6e49a9..dbf96fea8 100644 --- a/worker/master/volumes/provider/rainbondsssc.go +++ b/worker/master/volumes/provider/rainbondsssc.go @@ -81,6 +81,9 @@ func (p *rainbondssscProvisioner) Provision(options controller.VolumeOptions) (* if err := util.CheckAndCreateDirByMode(hostpath, 0777); err != nil { return nil, err } + // new nfs path + options.NFS.Path = strings.Replace(hostpath, "/grdata", options.NFS.Path, 1) + pv := &v1.PersistentVolume{ ObjectMeta: metav1.ObjectMeta{ Name: options.PVName, @@ -93,9 +96,7 @@ func (p *rainbondssscProvisioner) Provision(options controller.VolumeOptions) (* v1.ResourceName(v1.ResourceStorage): options.PVC.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)], }, PersistentVolumeSource: v1.PersistentVolumeSource{ - HostPath: &v1.HostPathVolumeSource{ - Path: hostpath, - }, + NFS: options.NFS, }, }, }