grdata for sts

This commit is contained in:
GLYASAI 2020-03-25 19:28:37 +08:00
parent 2762542cbf
commit 6b7992262d
8 changed files with 42 additions and 9 deletions

View File

@ -53,6 +53,7 @@ type Config struct {
LeaderElectionNamespace string LeaderElectionNamespace string
LeaderElectionIdentity string LeaderElectionIdentity string
RBDNamespace string RBDNamespace string
GrdataPVCName string
RBDDNSName 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.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.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.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") flag.StringVar(&a.RBDDNSName, "rbd-dns", "rbd-dns", "rbd dns endpoint name")
} }

View File

@ -788,4 +788,4 @@ func getVariableKey(source string) (key, value string) {
return re[0], "" return re[0], ""
} }
return k, "" return k, ""
} }

View File

@ -69,9 +69,6 @@ func (v *ShareFileVolume) CreateVolume(define *Define) error {
} }
} }
hostPath := v.svm.HostPath hostPath := v.svm.HostPath
if v.as.IsWindowsService {
hostPath = RewriteHostPathInWindows(hostPath)
}
vo := corev1.Volume{Name: volumeMountName} vo := corev1.Volume{Name: volumeMountName}
hostPathType := corev1.HostPathDirectoryOrCreate hostPathType := corev1.HostPathDirectoryOrCreate
vo.HostPath = &corev1.HostPathVolumeSource{ vo.HostPath = &corev1.HostPathVolumeSource{

View File

@ -77,7 +77,7 @@ func NewMasterController(conf option.Config, store store.Storer) (*Controller, e
rainbondsslcProvisioner := provider.NewRainbondsslcProvisioner(conf.KubeClient, store) rainbondsslcProvisioner := provider.NewRainbondsslcProvisioner(conf.KubeClient, store)
// Start the provision controller which will dynamically provision hostPath // Start the provision controller which will dynamically provision hostPath
// PVs // PVs
pc := controller.NewProvisionController(conf.KubeClient, map[string]controller.Provisioner{ pc := controller.NewProvisionController(conf.KubeClient, &conf, map[string]controller.Provisioner{
rainbondssscProvisioner.Name(): rainbondssscProvisioner, rainbondssscProvisioner.Name(): rainbondssscProvisioner,
rainbondsslcProvisioner.Name(): rainbondsslcProvisioner, rainbondsslcProvisioner.Name(): rainbondsslcProvisioner,
}, serverVersion.GitVersion) }, serverVersion.GitVersion)

View File

@ -21,6 +21,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/goodrain/rainbond/cmd/worker/option"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os" "os"
@ -79,6 +80,7 @@ const annSelectedNode = "volume.kubernetes.io/selected-node"
// PersistentVolumeClaims. // PersistentVolumeClaims.
type ProvisionController struct { type ProvisionController struct {
client kubernetes.Interface client kubernetes.Interface
cfg *option.Config
// The provisioner the controller will use to provision and delete volumes. // The provisioner the controller will use to provision and delete volumes.
// Presumably this implementer of Provisioner carries its own // 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. // the given configuration parameters and with private (non-shared) informers.
func NewProvisionController( func NewProvisionController(
client kubernetes.Interface, client kubernetes.Interface,
cfg *option.Config,
provisioners map[string]Provisioner, provisioners map[string]Provisioner,
kubeVersion string, kubeVersion string,
options ...func(*ProvisionController) error, options ...func(*ProvisionController) error,
@ -429,6 +432,7 @@ func NewProvisionController(
controller := &ProvisionController{ controller := &ProvisionController{
client: client, client: client,
cfg: cfg,
provisioners: provisioners, provisioners: provisioners,
kubeVersion: utilversion.MustParseSemantic(kubeVersion), kubeVersion: utilversion.MustParseSemantic(kubeVersion),
id: id, 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{ options := VolumeOptions{
PersistentVolumeReclaimPolicy: reclaimPolicy, PersistentVolumeReclaimPolicy: reclaimPolicy,
PVName: pvName, PVName: pvName,
PVC: claim, PVC: claim,
NFS: grdatapv.Spec.NFS,
MountOptions: mountOptions, MountOptions: mountOptions,
Parameters: parameters, Parameters: parameters,
SelectedNode: selectedNode, SelectedNode: selectedNode,
@ -1094,6 +1108,18 @@ func (ctrl *ProvisionController) provisionClaimOperation(claim *v1.PersistentVol
return nil 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 // deleteVolumeOperation attempts to delete the volume backing the given
// volume. Returns error, which indicates whether deletion should be retried // volume. Returns error, which indicates whether deletion should be retried
// (requeue the volume) or not // (requeue the volume) or not

View File

@ -650,7 +650,7 @@ func TestControllerExternalSharedInformers(t *testing.T) {
newClaim("claim-1", "uid-1-1", "class-1", "foo.bar/baz", "", nil), newClaim("claim-1", "uid-1-1", "class-1", "foo.bar/baz", "", nil),
}, },
provisionerName: "foo.bar/baz", provisionerName: "foo.bar/baz",
serverVersion: "v1.8.0", serverVersion: "v1.8.0",w
expectedVolumes: []v1.PersistentVolume{ expectedVolumes: []v1.PersistentVolume{
*newProvisionedVolumeWithSpecifiedReclaimPolicy(newStorageClassWithSpecifiedReclaimPolicy("class-1", "foo.bar/baz", v1.PersistentVolumeReclaimDelete), newClaim("claim-1", "uid-1-1", "class-1", "foo.bar/baz", "", nil)), *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 provisionCalls chan provisionParams
} }
func (t *testProvisioner) Name() string{
return ""
}
// Provisioner -
var _ Provisioner = &testProvisioner{} var _ Provisioner = &testProvisioner{}
func newTestQualifiedProvisioner(answer bool) *testQualifiedProvisioner { func newTestQualifiedProvisioner(answer bool) *testQualifiedProvisioner {

View File

@ -86,6 +86,8 @@ type VolumeOptions struct {
// i.e. with required capacity, accessMode, labels matching PVC.Selector and // i.e. with required capacity, accessMode, labels matching PVC.Selector and
// so on. // so on.
PVC *v1.PersistentVolumeClaim PVC *v1.PersistentVolumeClaim
// NFS
NFS *v1.NFSVolumeSource
// Volume provisioning parameters from StorageClass // Volume provisioning parameters from StorageClass
Parameters map[string]string Parameters map[string]string

View File

@ -81,6 +81,9 @@ func (p *rainbondssscProvisioner) Provision(options controller.VolumeOptions) (*
if err := util.CheckAndCreateDirByMode(hostpath, 0777); err != nil { if err := util.CheckAndCreateDirByMode(hostpath, 0777); err != nil {
return nil, err return nil, err
} }
// new nfs path
options.NFS.Path = strings.Replace(hostpath, "/grdata", options.NFS.Path, 1)
pv := &v1.PersistentVolume{ pv := &v1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: options.PVName, 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)], v1.ResourceName(v1.ResourceStorage): options.PVC.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)],
}, },
PersistentVolumeSource: v1.PersistentVolumeSource{ PersistentVolumeSource: v1.PersistentVolumeSource{
HostPath: &v1.HostPathVolumeSource{ NFS: options.NFS,
Path: hostpath,
},
}, },
}, },
} }