[REV] remove some log

This commit is contained in:
barnett 2018-11-29 20:57:02 +08:00
parent b52a6c5849
commit 217891516d
3 changed files with 52 additions and 46 deletions

View File

@ -305,7 +305,11 @@ func createVolumes(as *v1.AppService, version *dbmodel.VersionInfo, dbmanager db
}
os.Chmod(v.HostPath, 0777)
}
vd.SetVolume(dbmodel.VolumeType(v.VolumeType), fmt.Sprintf("manual%d", v.ID), v.VolumePath, v.HostPath, v.IsReadOnly)
if as.GetStatefulSet() != nil {
vd.SetPV(dbmodel.VolumeType(v.VolumeType), fmt.Sprintf("manual%d", v.ID), v.VolumePath, v.HostPath, v.IsReadOnly)
} else {
vd.SetVolume(dbmodel.VolumeType(v.VolumeType), fmt.Sprintf("manual%d", v.ID), v.VolumePath, v.HostPath, v.IsReadOnly)
}
}
}
//handle Shared storage
@ -347,6 +351,39 @@ func (v *volumeDefine) GetVolumes() []corev1.Volume {
func (v *volumeDefine) GetVolumeMounts() []corev1.VolumeMount {
return v.volumeMounts
}
func (v *volumeDefine) SetPV(VolumeType dbmodel.VolumeType, name, mountPath, hostPath string, readOnly bool) {
switch VolumeType {
case dbmodel.ShareFileVolumeType:
if statefulset := v.as.GetStatefulSet(); statefulset != nil {
resourceStorage, _ := resource.ParseQuantity("40g")
statefulset.Spec.VolumeClaimTemplates = append(
statefulset.Spec.VolumeClaimTemplates,
corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Labels: v.as.GetCommonLabels(map[string]string{
"tenant_id": v.as.TenantID,
}),
},
Spec: corev1.PersistentVolumeClaimSpec{
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteMany},
StorageClassName: &v1.RainbondStatefuleShareStorageClass,
Resources: corev1.ResourceRequirements{
Requests: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceStorage: resourceStorage,
},
},
},
},
)
v.volumeMounts = append(v.volumeMounts, corev1.VolumeMount{
Name: name,
MountPath: mountPath,
ReadOnly: readOnly,
})
}
}
}
func (v *volumeDefine) SetVolume(VolumeType dbmodel.VolumeType, name, mountPath, hostPath string, readOnly bool) {
for _, m := range v.volumeMounts {
if m.MountPath == mountPath {
@ -371,46 +408,21 @@ func (v *volumeDefine) SetVolume(VolumeType dbmodel.VolumeType, name, mountPath,
}
case dbmodel.ShareFileVolumeType:
if hostPath != "" {
if v.as.ServiceType == v1.TypeStatefulSet {
if statefulset := v.as.GetStatefulSet(); statefulset != nil {
statefulset.Spec.VolumeClaimTemplates = append(
statefulset.Spec.VolumeClaimTemplates,
corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Labels: v.as.GetCommonLabels(map[string]string{
"tenant_id": v.as.TenantID,
}),
},
Spec: corev1.PersistentVolumeClaimSpec{
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteMany},
StorageClassName: &v1.RainbondStatefuleShareStorageClass,
},
},
)
v.volumeMounts = append(v.volumeMounts, corev1.VolumeMount{
Name: name,
MountPath: mountPath,
ReadOnly: readOnly,
})
}
} else {
vo := corev1.Volume{
Name: name,
}
vo.HostPath = &corev1.HostPathVolumeSource{
Path: hostPath,
}
v.volumes = append(v.volumes, vo)
if mountPath != "" {
vm := corev1.VolumeMount{
MountPath: mountPath,
Name: name,
ReadOnly: readOnly,
SubPath: "",
}
v.volumeMounts = append(v.volumeMounts, vm)
vo := corev1.Volume{
Name: name,
}
vo.HostPath = &corev1.HostPathVolumeSource{
Path: hostPath,
}
v.volumes = append(v.volumes, vo)
if mountPath != "" {
vm := corev1.VolumeMount{
MountPath: mountPath,
Name: name,
ReadOnly: readOnly,
SubPath: "",
}
v.volumeMounts = append(v.volumeMounts, vm)
}
}
case dbmodel.LocalVolumeType:

View File

@ -194,7 +194,6 @@ func (a *appRuntimeStore) OnAdd(obj interface{}) {
if serviceID != "" && version != "" && createrID != "" {
appservice := a.getAppService(serviceID, version, createrID, true)
if appservice != nil {
fmt.Printf("set statefulset %s \n", statefulset.Name)
appservice.SetStatefulSet(statefulset)
return
}

View File

@ -22,8 +22,6 @@ import (
"fmt"
"strconv"
"github.com/Sirupsen/logrus"
"github.com/goodrain/rainbond/event"
v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
@ -157,7 +155,6 @@ func (a AppService) GetDeployment() *v1.Deployment {
//SetDeployment set kubernetes deployment model
func (a *AppService) SetDeployment(d *v1.Deployment) {
logrus.Debugf("cache deployment %s to app service %s", d.Name, a.ServiceAlias)
a.deployment = d
}
@ -173,7 +170,6 @@ func (a AppService) GetStatefulSet() *v1.StatefulSet {
//SetStatefulSet set kubernetes statefulset model
func (a *AppService) SetStatefulSet(d *v1.StatefulSet) {
logrus.Debugf("cache statefulset %s to app service %s", d.Name, a.ServiceAlias)
a.statefulset = d
}
@ -390,7 +386,6 @@ func (a *AppService) GetSecrets() []*corev1.Secret {
//SetPods set pod
func (a *AppService) SetPods(d *corev1.Pod) {
logrus.Debugf("cache pod %s to service %s", d.Name, a.ServiceAlias)
if len(a.pods) > 0 {
for i, pod := range a.pods {
if pod.GetName() == d.GetName() {