mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-02 03:37:46 +08:00
grdata for sts
This commit is contained in:
parent
2762542cbf
commit
6b7992262d
@ -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")
|
||||
}
|
||||
|
||||
|
@ -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{
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
||||
|
@ -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,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user