mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-02 03:37:46 +08:00
feat(worker): support csi interface
This commit is contained in:
parent
a09edcba31
commit
9f3875417e
@ -330,6 +330,11 @@ func createEnv(as *v1.AppService, dbmanager db.Manager, envVarSecrets []*corev1.
|
||||
FieldPath: "status.podIP",
|
||||
},
|
||||
}})
|
||||
envs = append(envs, corev1.EnvVar{Name: "POD_NAME", ValueFrom: &corev1.EnvVarSource{
|
||||
FieldRef: &corev1.ObjectFieldSelector{
|
||||
FieldPath: "metadata.name",
|
||||
},
|
||||
}})
|
||||
var config = make(map[string]string, len(envs))
|
||||
for _, sec := range envVarSecrets {
|
||||
for k, v := range sec.Data {
|
||||
|
@ -20,10 +20,12 @@ package volume
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
v1 "github.com/goodrain/rainbond/worker/appm/types/v1"
|
||||
"github.com/sirupsen/logrus"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ShareFileVolume nfs volume struct
|
||||
@ -36,6 +38,7 @@ func (v *ShareFileVolume) CreateVolume(define *Define) error {
|
||||
volumeMountName := fmt.Sprintf("manual%d", v.svm.ID)
|
||||
volumeMountPath := v.svm.VolumePath
|
||||
volumeReadOnly := v.svm.IsReadOnly
|
||||
existShareStoragePVC := v.getExistShareStoragePVC()
|
||||
|
||||
var vm *corev1.VolumeMount
|
||||
if v.as.GetStatefulSet() != nil {
|
||||
@ -44,17 +47,19 @@ func (v *ShareFileVolume) CreateVolume(define *Define) error {
|
||||
labels := v.as.GetCommonLabels(map[string]string{"volume_name": volumeMountName})
|
||||
annotations := map[string]string{"volume_name": v.svm.VolumeName}
|
||||
claim := newVolumeClaim(volumeMountName, volumeMountPath, v.svm.AccessMode, v1.RainbondStatefuleShareStorageClass, v.svm.VolumeCapacity, labels, annotations)
|
||||
v.as.SetClaim(claim)
|
||||
|
||||
statefulset.Spec.VolumeClaimTemplates = append(statefulset.Spec.VolumeClaimTemplates, *claim)
|
||||
vo := corev1.Volume{Name: volumeMountName}
|
||||
vo.PersistentVolumeClaim = &corev1.PersistentVolumeClaimVolumeSource{ClaimName: claim.GetName(), ReadOnly: volumeReadOnly}
|
||||
define.volumes = append(define.volumes, vo)
|
||||
vm = &corev1.VolumeMount{
|
||||
Name: volumeMountName,
|
||||
MountPath: volumeMountPath,
|
||||
ReadOnly: volumeReadOnly,
|
||||
}
|
||||
if _, exist := existShareStoragePVC[claim.GetName()]; !exist {
|
||||
v.as.SetClaim(claim)
|
||||
statefulset.Spec.VolumeClaimTemplates = append(statefulset.Spec.VolumeClaimTemplates, *claim)
|
||||
vo := corev1.Volume{Name: volumeMountName}
|
||||
vo.PersistentVolumeClaim = &corev1.PersistentVolumeClaimVolumeSource{ClaimName: claim.GetName(), ReadOnly: volumeReadOnly}
|
||||
define.volumes = append(define.volumes, vo)
|
||||
}
|
||||
v.generateVolumeSubPath(vm)
|
||||
} else {
|
||||
for _, m := range define.volumeMounts {
|
||||
if m.MountPath == volumeMountPath { // TODO move to prepare
|
||||
@ -69,16 +74,19 @@ func (v *ShareFileVolume) CreateVolume(define *Define) error {
|
||||
})
|
||||
annotations := map[string]string{"volume_name": v.svm.VolumeName}
|
||||
claim := newVolumeClaim(volumeMountName, volumeMountPath, v.svm.AccessMode, v1.RainbondStatefuleShareStorageClass, v.svm.VolumeCapacity, labels, annotations)
|
||||
v.as.SetClaim(claim)
|
||||
v.as.SetClaimManually(claim)
|
||||
vo := corev1.Volume{Name: volumeMountName}
|
||||
vo.PersistentVolumeClaim = &corev1.PersistentVolumeClaimVolumeSource{ClaimName: claim.GetName(), ReadOnly: volumeReadOnly}
|
||||
define.volumes = append(define.volumes, vo)
|
||||
vm = &corev1.VolumeMount{
|
||||
Name: volumeMountName,
|
||||
MountPath: volumeMountPath,
|
||||
ReadOnly: volumeReadOnly,
|
||||
}
|
||||
if _, exist := existShareStoragePVC[claim.GetName()]; !exist {
|
||||
v.as.SetClaim(claim)
|
||||
v.as.SetClaimManually(claim)
|
||||
vo := corev1.Volume{Name: volumeMountName}
|
||||
vo.PersistentVolumeClaim = &corev1.PersistentVolumeClaimVolumeSource{ClaimName: claim.GetName(), ReadOnly: volumeReadOnly}
|
||||
define.volumes = append(define.volumes, vo)
|
||||
}
|
||||
v.generateVolumeSubPath(vm)
|
||||
}
|
||||
define.volumeMounts = append(define.volumeMounts, *vm)
|
||||
|
||||
@ -100,11 +108,39 @@ func (v *ShareFileVolume) CreateDependVolume(define *Define) error {
|
||||
claimName := fmt.Sprintf("manual%d", v.svm.ID)
|
||||
vo.PersistentVolumeClaim = &corev1.PersistentVolumeClaimVolumeSource{ClaimName: claimName, ReadOnly: false}
|
||||
define.volumes = append(define.volumes, vo)
|
||||
vm := corev1.VolumeMount{
|
||||
vm := &corev1.VolumeMount{
|
||||
Name: volumeMountName,
|
||||
MountPath: volumeMountPath,
|
||||
ReadOnly: false,
|
||||
}
|
||||
define.volumeMounts = append(define.volumeMounts, vm)
|
||||
v.generateVolumeSubPath(vm)
|
||||
define.volumeMounts = append(define.volumeMounts, *vm)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *ShareFileVolume) getExistShareStoragePVC() map[string]struct{} {
|
||||
existShareStoragePVC := make(map[string]struct{})
|
||||
for _, pvc := range v.as.GetClaims() {
|
||||
if *pvc.Spec.StorageClassName != v1.RainbondStatefuleShareStorageClass {
|
||||
continue
|
||||
}
|
||||
if _, ok := existShareStoragePVC[pvc.GetName()]; ok {
|
||||
continue
|
||||
}
|
||||
existShareStoragePVC[pvc.GetName()] = struct{}{}
|
||||
}
|
||||
return existShareStoragePVC
|
||||
}
|
||||
|
||||
func (v *ShareFileVolume) generateVolumeSubPath(vm *corev1.VolumeMount) *corev1.VolumeMount {
|
||||
if os.Getenv("ENABLE_SUBPATH") != "true" {
|
||||
return vm
|
||||
}
|
||||
if v.as.GetStatefulSet() != nil {
|
||||
subPathExpr := path.Join(strings.TrimPrefix(v.svm.HostPath, "/grdata/"), "$(POD_NAME)")
|
||||
vm.SubPathExpr = subPathExpr
|
||||
return vm
|
||||
}
|
||||
vm.SubPath = strings.TrimPrefix(v.svm.HostPath, "/grdata/")
|
||||
return vm
|
||||
}
|
||||
|
@ -212,6 +212,8 @@ func updatePathForPersistentVolumeSource(persistentVolumeSource *v1.PersistentVo
|
||||
Path: newPath(persistentVolumeSource.HostPath.Path),
|
||||
Type: persistentVolumeSource.HostPath.Type,
|
||||
}
|
||||
case persistentVolumeSource.CSI != nil :
|
||||
source.CSI = persistentVolumeSource.CSI
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported persistence volume source")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user