This commit is contained in:
yangk 2021-12-09 23:15:09 +08:00
parent 4366acc00a
commit 7b6cf11b0b
5 changed files with 48 additions and 23 deletions

View File

@ -1,9 +1,9 @@
package app_governance_mode
package appgovernancemode
import (
"github.com/goodrain/rainbond/api/handler/app_governance_mode/build_in"
"github.com/goodrain/rainbond/api/handler/app_governance_mode/istio"
"github.com/goodrain/rainbond/api/handler/app_governance_mode/kubernetes_native"
kubernetesnative "github.com/goodrain/rainbond/api/handler/app_governance_mode/kubernetes_native"
"github.com/goodrain/rainbond/api/util/bcode"
"github.com/goodrain/rainbond/db/model"
clientset "k8s.io/client-go/kubernetes"
@ -19,13 +19,11 @@ type AppGoveranceModeHandler interface {
func NewAppGoveranceModeHandler(governanceMode string, kubeClient clientset.Interface) (AppGoveranceModeHandler, error) {
switch governanceMode {
case model.GovernanceModeIstioServiceMesh:
return &istio.IstioServiceMeshMode{
KubeClient: kubeClient,
}, nil
return istio.New(kubeClient), nil
case model.GovernanceModeBuildInServiceMesh:
return &build_in.BuildInServiceMeshMode{}, nil
return buildin.New(), nil
case model.GovernanceModeKubernetesNativeService:
return &kubernetes_native.KubernetesNativeMode{}, nil
return kubernetesnative.New(), nil
default:
return nil, bcode.ErrInvalidGovernanceMode
}

View File

@ -1,12 +1,20 @@
package build_in
package buildin
type BuildInServiceMeshMode struct {
import appgovernancemode "github.com/goodrain/rainbond/api/handler/app_governance_mode"
type buildInServiceMeshMode struct{}
// New Build In ServiceMeshMode Handler
func New() appgovernancemode.AppGoveranceModeHandler {
return &buildInServiceMeshMode{}
}
func (b *BuildInServiceMeshMode) IsInstalledControlPlane() bool {
// IsInstalledControlPlane -
func (b *buildInServiceMeshMode) IsInstalledControlPlane() bool {
return true
}
func (b *BuildInServiceMeshMode) GetInjectLabels() map[string]string {
// GetInjectLabels -
func (b *buildInServiceMeshMode) GetInjectLabels() map[string]string {
return nil
}

View File

@ -2,30 +2,40 @@ package istio
import (
"context"
appgovernancemode "github.com/goodrain/rainbond/api/handler/app_governance_mode"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes"
"os"
"time"
)
type IstioServiceMeshMode struct {
KubeClient clientset.Interface
type istioServiceMeshMode struct {
kubeClient clientset.Interface
}
func (i *IstioServiceMeshMode) IsInstalledControlPlane() bool {
// New Istio Goverance Mode Handler
func New(kubeClient clientset.Interface) appgovernancemode.AppGoveranceModeHandler{
return &istioServiceMeshMode{
kubeClient: kubeClient,
}
}
// IsInstalledControlPlane -
func (i *istioServiceMeshMode) IsInstalledControlPlane() bool {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
cmName := os.Getenv("ISTIO_CM")
if cmName == "" {
cmName = "istio-ca-root-cert"
}
_, err := i.KubeClient.CoreV1().ConfigMaps("default").Get(ctx, cmName, metav1.GetOptions{})
_, err := i.kubeClient.CoreV1().ConfigMaps("default").Get(ctx, cmName, metav1.GetOptions{})
if err != nil {
return false
}
return true
}
func (i *IstioServiceMeshMode) GetInjectLabels() map[string]string {
// GetInjectLabels -
func (i *istioServiceMeshMode) GetInjectLabels() map[string]string {
return map[string]string{"sidecar.istio.io/inject": "true"}
}

View File

@ -1,12 +1,21 @@
package kubernetes_native
package kubernetesnative
type KubernetesNativeMode struct {
import appgovernancemode "github.com/goodrain/rainbond/api/handler/app_governance_mode"
type kubernetesNativeMode struct {
}
func (k *KubernetesNativeMode) IsInstalledControlPlane() bool {
// New Kubernetes Native Mode Handler
func New() appgovernancemode.AppGoveranceModeHandler {
return &kubernetesNativeMode{}
}
// IsInstalledControlPlane -
func (k *kubernetesNativeMode) IsInstalledControlPlane() bool {
return true
}
func (k *KubernetesNativeMode) GetInjectLabels() map[string]string {
// GetInjectLabels-
func (k *kubernetesNativeMode) GetInjectLabels() map[string]string {
return nil
}

View File

@ -902,11 +902,11 @@ func (s *ServiceAction) ServiceUpdate(sc map[string]interface{}) error {
if appID, ok := sc["app_id"].(string); ok && appID != "" {
ts.AppID = appID
}
if k8s_component_name, ok := sc["k8s_component_name"].(string); ok && k8s_component_name != "" {
if db.GetManager().TenantServiceDao().IsK8sComponentNameDuplicate(ts.AppID, ts.ServiceID, k8s_component_name) {
if k8sComponentName, ok := sc["k8s_component_name"].(string); ok && k8sComponentName != "" {
if db.GetManager().TenantServiceDao().IsK8sComponentNameDuplicate(ts.AppID, ts.ServiceID, k8sComponentName) {
return bcode.ErrK8sComponentNameExists
}
ts.K8sComponentName = k8s_component_name
ts.K8sComponentName = k8sComponentName
}
if sc["extend_method"] != nil {
extendMethod := sc["extend_method"].(string)