mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-11-29 18:27:58 +08:00
chart cache
This commit is contained in:
parent
53219eeed1
commit
253f8b96a3
@ -32,7 +32,7 @@ func (a *ApplicationController) CreateApp(w http.ResponseWriter, r *http.Request
|
||||
httputil.ReturnBcodeError(r, w, bcode.NewBadRequest("the field 'app_template_name' is required"))
|
||||
return
|
||||
}
|
||||
if tenantReq.AppTemplateName == "" {
|
||||
if tenantReq.AppName == "" {
|
||||
httputil.ReturnBcodeError(r, w, bcode.NewBadRequest("the field 'helm_app_name' is required"))
|
||||
return
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ import (
|
||||
"github.com/goodrain/rainbond/cmd/api/option"
|
||||
"github.com/goodrain/rainbond/db"
|
||||
"github.com/goodrain/rainbond/event"
|
||||
"github.com/goodrain/rainbond/util/commonutil"
|
||||
"github.com/goodrain/rainbond/worker/client"
|
||||
"github.com/goodrain/rainbond/worker/discover/model"
|
||||
"github.com/goodrain/rainbond/worker/server"
|
||||
@ -762,7 +761,7 @@ func (s *ServiceAction) ServiceCreate(sc *api_model.ServiceStruct) error {
|
||||
func (s *ServiceAction) openInnerPorts(componentID string, ports []dbmodel.TenantServicesPort) {
|
||||
// TODO: support open multiple ports in one task.
|
||||
for _, port := range ports {
|
||||
if !commonutil.BoolValue(port.IsInnerService) {
|
||||
if !port.IsOpen(){
|
||||
continue
|
||||
}
|
||||
|
||||
@ -2062,17 +2061,6 @@ func (s *ServiceAction) isServiceClosed(serviceID string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteComponentInBatch deletes components in batch.
|
||||
func (s *ServiceAction) DeleteComponentInBatch(tx *gorm.DB, components []*dbmodel.TenantServices) error {
|
||||
for _, cpt := range components {
|
||||
err := s.deleteComponent(tx, cpt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *ServiceAction) deleteComponent(tx *gorm.DB, service *dbmodel.TenantServices) error {
|
||||
delService := service.ChangeDelete()
|
||||
delService.ID = 0
|
||||
|
@ -25,7 +25,6 @@ import (
|
||||
dbmodel "github.com/goodrain/rainbond/db/model"
|
||||
"github.com/goodrain/rainbond/worker/discover/model"
|
||||
"github.com/goodrain/rainbond/worker/server/pb"
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
//ServiceHandler service handler
|
||||
@ -77,7 +76,6 @@ type ServiceHandler interface {
|
||||
GetServiceCheckInfo(uuid string) (*exector.ServiceCheckResult, *util.APIHandleError)
|
||||
GetServiceDeployInfo(tenantID, serviceID string) (*pb.DeployInfo, *util.APIHandleError)
|
||||
ListVersionInfo(serviceID string) (*api_model.BuildListRespVO, error)
|
||||
DeleteComponentInBatch(tx *gorm.DB, components []*dbmodel.TenantServices) error
|
||||
|
||||
AddAutoscalerRule(req *api_model.AutoscalerRuleReq) error
|
||||
UpdAutoscalerRule(req *api_model.AutoscalerRuleReq) error
|
||||
|
@ -61,6 +61,7 @@ type Helm struct {
|
||||
DataDir string
|
||||
RepoFile string
|
||||
RepoCache string
|
||||
ChartCache string
|
||||
}
|
||||
|
||||
//Worker worker server
|
||||
@ -107,6 +108,7 @@ func (a *Worker) AddFlags(fs *pflag.FlagSet) {
|
||||
}
|
||||
a.Helm.RepoFile = path.Join(a.Helm.DataDir, "repo/repositories.yaml")
|
||||
a.Helm.RepoCache = path.Join(a.Helm.DataDir, "cache")
|
||||
a.Helm.ChartCache = path.Join(a.Helm.DataDir, "chart")
|
||||
}
|
||||
|
||||
//SetLog 设置log
|
||||
|
@ -23,6 +23,8 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/goodrain/rainbond/util/commonutil"
|
||||
)
|
||||
|
||||
//Model 默认字段
|
||||
@ -324,6 +326,11 @@ func (t *TenantServicesPort) TableName() string {
|
||||
return "tenant_services_port"
|
||||
}
|
||||
|
||||
// IsOpen checks if the port is opened.
|
||||
func (t *TenantServicesPort) IsOpen() bool {
|
||||
return commonutil.BoolValue(t.IsOuterService) || commonutil.BoolValue(t.IsInnerService)
|
||||
}
|
||||
|
||||
//TenantServiceLBMappingPort stream应用端口映射情况
|
||||
type TenantServiceLBMappingPort struct {
|
||||
Model
|
||||
|
2
go.mod
2
go.mod
@ -121,6 +121,7 @@ replace (
|
||||
github.com/coreos/etcd => github.com/coreos/etcd v3.2.31+incompatible
|
||||
github.com/docker/distribution => github.com/docker/distribution v0.0.0-20191216044856-a8371794149d
|
||||
github.com/docker/docker => github.com/docker/docker v17.12.0-ce-rc1.0.20200916142827-bd33bbf0497b+incompatible
|
||||
github.com/godbus/dbus => github.com/godbus/dbus/v5 v5.0.4
|
||||
google.golang.org/grpc => google.golang.org/grpc v1.29.0
|
||||
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.20.0
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.20.0
|
||||
@ -129,5 +130,4 @@ replace (
|
||||
k8s.io/client-go => k8s.io/client-go v0.20.0
|
||||
k8s.io/code-generator => k8s.io/code-generator v0.20.0
|
||||
k8s.io/component-base => k8s.io/component-base v0.20.0
|
||||
github.com/godbus/dbus => github.com/godbus/dbus/v5 v5.0.4
|
||||
)
|
||||
|
10
localcheck.sh
Executable file
10
localcheck.sh
Executable file
@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
TARGET_BRANCH=${TARGET_BRANCH:-'master'}
|
||||
|
||||
CHANGED_MARKDOWN_FILES=$(git diff --name-only ${TARGET_BRANCH} | grep .go)
|
||||
for file in ${CHANGED_MARKDOWN_FILES}; do
|
||||
echo "golint ${file}"
|
||||
golint -set_exit_status=true ${file} || exit 1
|
||||
done
|
||||
|
||||
echo "code golint check success"
|
@ -68,7 +68,7 @@ func (a *App) Chart() string {
|
||||
}
|
||||
|
||||
// NewApp creates a new app.
|
||||
func NewApp(ctx context.Context, kubeClient clientset.Interface, rainbondClient versioned.Interface, helmApp *v1alpha1.HelmApp, repoFile, repoCache string) (*App, error) {
|
||||
func NewApp(ctx context.Context, kubeClient clientset.Interface, rainbondClient versioned.Interface, helmApp *v1alpha1.HelmApp, repoFile, repoCache, chartCache string) (*App, error) {
|
||||
helmCmd, err := helm.NewHelm(helmApp.GetNamespace(), repoFile, repoCache)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -93,7 +93,7 @@ func NewApp(ctx context.Context, kubeClient clientset.Interface, rainbondClient
|
||||
overrides: helmApp.Spec.Overrides,
|
||||
helmCmd: helmCmd,
|
||||
repo: repo,
|
||||
chartDir: path.Join("/tmp/helm/chart", helmApp.Namespace, helmApp.Name, helmApp.Spec.Version),
|
||||
chartDir: path.Join(chartCache, helmApp.Namespace, helmApp.Name, helmApp.Spec.Version),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -38,13 +38,13 @@ type Controller struct {
|
||||
|
||||
// NewController creates a new helm app controller.
|
||||
func NewController(ctx context.Context, stopCh chan struct{}, kubeClient clientset.Interface, clientset versioned.Interface, resyncPeriod time.Duration,
|
||||
repoFile, repoCache string) *Controller {
|
||||
repoFile, repoCache, chartCache string) *Controller {
|
||||
workQueue := workqueue.New()
|
||||
finalizerQueue := workqueue.New()
|
||||
storer := NewStorer(clientset, resyncPeriod, workQueue, finalizerQueue)
|
||||
|
||||
controlLoop := NewControlLoop(ctx, kubeClient, clientset, storer, workQueue, repoFile, repoCache)
|
||||
finalizer := NewFinalizer(ctx, kubeClient, clientset, finalizerQueue, repoFile, repoCache)
|
||||
controlLoop := NewControlLoop(ctx, kubeClient, clientset, storer, workQueue, repoFile, repoCache, chartCache)
|
||||
finalizer := NewFinalizer(ctx, kubeClient, clientset, finalizerQueue, repoFile, repoCache, chartCache)
|
||||
|
||||
return &Controller{
|
||||
storer: storer,
|
||||
|
@ -52,6 +52,7 @@ type ControlLoop struct {
|
||||
repo *helm.Repo
|
||||
repoFile string
|
||||
repoCache string
|
||||
chartCache string
|
||||
}
|
||||
|
||||
// NewControlLoop -
|
||||
@ -62,6 +63,7 @@ func NewControlLoop(ctx context.Context,
|
||||
workQueue workqueue.Interface,
|
||||
repoFile string,
|
||||
repoCache string,
|
||||
chartCache string,
|
||||
) *ControlLoop {
|
||||
repo := helm.NewRepo(repoFile, repoCache)
|
||||
return &ControlLoop{
|
||||
@ -74,6 +76,7 @@ func NewControlLoop(ctx context.Context,
|
||||
repo: repo,
|
||||
repoFile: repoFile,
|
||||
repoCache: repoCache,
|
||||
chartCache: chartCache,
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,7 +127,7 @@ func nameNamespace(key string) (string, string) {
|
||||
|
||||
// Reconcile -
|
||||
func (c *ControlLoop) Reconcile(helmApp *v1alpha1.HelmApp) error {
|
||||
app, err := NewApp(c.ctx, c.kubeClient, c.clientset, helmApp, c.repoFile, c.repoCache)
|
||||
app, err := NewApp(c.ctx, c.kubeClient, c.clientset, helmApp, c.repoFile, c.repoCache, c.chartCache)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ type Finalizer struct {
|
||||
queue workqueue.Interface
|
||||
repoFile string
|
||||
repoCache string
|
||||
chartCache string
|
||||
}
|
||||
|
||||
// NewFinalizer creates a new finalizer.
|
||||
@ -46,6 +47,7 @@ func NewFinalizer(ctx context.Context,
|
||||
workQueue workqueue.Interface,
|
||||
repoFile string,
|
||||
repoCache string,
|
||||
chartCache string,
|
||||
) *Finalizer {
|
||||
return &Finalizer{
|
||||
ctx: ctx,
|
||||
@ -55,6 +57,7 @@ func NewFinalizer(ctx context.Context,
|
||||
queue: workQueue,
|
||||
repoFile: repoFile,
|
||||
repoCache: repoCache,
|
||||
chartCache: chartCache,
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,7 +92,7 @@ func (c *Finalizer) run(obj interface{}) error {
|
||||
|
||||
logrus.Infof("start uninstall helm app: %s/%s", helmApp.Name, helmApp.Namespace)
|
||||
|
||||
app, err := NewApp(c.ctx, c.kubeClient, c.clientset, helmApp, c.repoFile, c.repoCache)
|
||||
app, err := NewApp(c.ctx, c.kubeClient, c.clientset, helmApp, c.repoFile, c.repoCache, c.chartCache)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ var _ = BeforeSuite(func() {
|
||||
rainbondClient = versioned.NewForConfigOrDie(restConfig)
|
||||
kubeClient = clientset.NewForConfigOrDie(restConfig)
|
||||
|
||||
ctrl := NewController(ctx, stopCh, kubeClient, rainbondClient, 5*time.Second, "/tmp/helm/repo/repositories.yaml", "/tmp/helm/cache")
|
||||
ctrl := NewController(ctx, stopCh, kubeClient, rainbondClient, 5*time.Second, "/tmp/helm/repo/repositories.yaml", "/tmp/helm/cache", "/tmp/helm/chart")
|
||||
go ctrl.Start()
|
||||
|
||||
// create namespace
|
||||
|
@ -91,7 +91,7 @@ func NewMasterController(conf option.Config, store store.Storer, kubeClient kube
|
||||
}, serverVersion.GitVersion)
|
||||
stopCh := make(chan struct{})
|
||||
|
||||
helmAppController := helmapp.NewController(ctx, stopCh, kubeClient, rainbondClient, 5*time.Second, conf.Helm.RepoFile, conf.Helm.RepoCache)
|
||||
helmAppController := helmapp.NewController(ctx, stopCh, kubeClient, rainbondClient, 5*time.Second, conf.Helm.RepoFile, conf.Helm.RepoCache, conf.Helm.RepoCache)
|
||||
|
||||
return &Controller{
|
||||
conf: conf,
|
||||
|
Loading…
Reference in New Issue
Block a user