mirror of
https://github.com/kubevela/kubevela.git
synced 2026-02-14 18:10:21 +00:00
Chore: optimize the package dependencies (#5596)
* Chore: optimize the package dependces Signed-off-by: barnettZQG <barnett.zqg@gmail.com> * Fix: the code style Signed-off-by: barnettZQG <barnett.zqg@gmail.com> * Fix: remove the repetitive context Signed-off-by: barnettZQG <barnett.zqg@gmail.com> * Fix: change the context key Signed-off-by: barnettZQG <barnett.zqg@gmail.com> * Fix: Optimize the e2e test case Signed-off-by: barnettZQG <barnett.zqg@gmail.com> --------- Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
This commit is contained in:
@@ -186,3 +186,17 @@ const (
|
|||||||
// VelaCoreConfig is to mark application, config and its secret or Terraform provider lelong to a KubeVela config
|
// VelaCoreConfig is to mark application, config and its secret or Terraform provider lelong to a KubeVela config
|
||||||
VelaCoreConfig = "velacore-config"
|
VelaCoreConfig = "velacore-config"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// LabelSourceOfTruth describes the source of this app
|
||||||
|
LabelSourceOfTruth = "app.oam.dev/source-of-truth"
|
||||||
|
|
||||||
|
// FromCR means the data source of truth is from k8s CR
|
||||||
|
FromCR = "from-k8s-resource"
|
||||||
|
// FromUX means the data source of truth is from velaux data store
|
||||||
|
FromUX = "from-velaux"
|
||||||
|
// FromInner means the data source of truth is from KubeVela inner usage
|
||||||
|
// the configuration that don't want to be synced
|
||||||
|
// the addon application should be synced, but set to readonly mode
|
||||||
|
FromInner = "from-inner-system"
|
||||||
|
)
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ import (
|
|||||||
common2 "github.com/oam-dev/kubevela/apis/core.oam.dev/common"
|
common2 "github.com/oam-dev/kubevela/apis/core.oam.dev/common"
|
||||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
||||||
"github.com/oam-dev/kubevela/apis/types"
|
"github.com/oam-dev/kubevela/apis/types"
|
||||||
apiutils "github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
|
||||||
"github.com/oam-dev/kubevela/pkg/config"
|
"github.com/oam-dev/kubevela/pkg/config"
|
||||||
"github.com/oam-dev/kubevela/pkg/cue/script"
|
"github.com/oam-dev/kubevela/pkg/cue/script"
|
||||||
"github.com/oam-dev/kubevela/pkg/definition"
|
"github.com/oam-dev/kubevela/pkg/definition"
|
||||||
@@ -1086,7 +1085,7 @@ func (h *Installer) checkDependency(addon *InstallPackage) ([]string, error) {
|
|||||||
// createOrUpdate will return true if updated
|
// createOrUpdate will return true if updated
|
||||||
func (h *Installer) createOrUpdate(app *v1beta1.Application) (bool, error) {
|
func (h *Installer) createOrUpdate(app *v1beta1.Application) (bool, error) {
|
||||||
// Set the publish version for the addon application
|
// Set the publish version for the addon application
|
||||||
oam.SetPublishVersion(app, apiutils.GenerateVersion("addon"))
|
oam.SetPublishVersion(app, util.GenerateVersion("addon"))
|
||||||
var existApp v1beta1.Application
|
var existApp v1beta1.Application
|
||||||
err := h.cli.Get(h.ctx, client.ObjectKey{Name: app.Name, Namespace: app.Namespace}, &existApp)
|
err := h.cli.Get(h.ctx, client.ObjectKey{Name: app.Name, Namespace: app.Namespace}, &existApp)
|
||||||
if apierrors.IsNotFound(err) {
|
if apierrors.IsNotFound(err) {
|
||||||
|
|||||||
@@ -20,15 +20,15 @@ import (
|
|||||||
"github.com/getkin/kin-openapi/openapi3"
|
"github.com/getkin/kin-openapi/openapi3"
|
||||||
|
|
||||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
"github.com/oam-dev/kubevela/pkg/utils/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UIData contains all information represent an addon for UI
|
// UIData contains all information represent an addon for UI
|
||||||
type UIData struct {
|
type UIData struct {
|
||||||
Meta
|
Meta
|
||||||
|
|
||||||
APISchema *openapi3.Schema `json:"schema"`
|
APISchema *openapi3.Schema `json:"schema"`
|
||||||
UISchema []*utils.UIParameter `json:"uiSchema"`
|
UISchema []*schema.UIParameter `json:"uiSchema"`
|
||||||
|
|
||||||
// Detail is README.md in an addon
|
// Detail is README.md in an addon
|
||||||
Detail string `json:"detail,omitempty"`
|
Detail string `json:"detail,omitempty"`
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import (
|
|||||||
workflowv1alpha1 "github.com/kubevela/workflow/api/v1alpha1"
|
workflowv1alpha1 "github.com/kubevela/workflow/api/v1alpha1"
|
||||||
|
|
||||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/common"
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/common"
|
||||||
|
"github.com/oam-dev/kubevela/apis/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -83,8 +84,8 @@ func (a *Application) IsSynced() bool {
|
|||||||
if a.Labels == nil {
|
if a.Labels == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
sot := a.Labels[LabelSourceOfTruth]
|
sot := a.Labels[types.LabelSourceOfTruth]
|
||||||
if sot == FromCR || sot == FromInner {
|
if sot == types.FromCR || sot == types.FromInner {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@@ -96,8 +97,8 @@ func (a *Application) IsReadOnly() bool {
|
|||||||
if a.Labels == nil {
|
if a.Labels == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
sot := a.Labels[LabelSourceOfTruth]
|
sot := a.Labels[types.LabelSourceOfTruth]
|
||||||
return sot == FromInner
|
return sot == types.FromInner
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClusterSelector cluster selector
|
// ClusterSelector cluster selector
|
||||||
|
|||||||
@@ -44,20 +44,6 @@ const (
|
|||||||
LabelSyncNamespace = "ux.oam.dev/from-namespace"
|
LabelSyncNamespace = "ux.oam.dev/from-namespace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
// LabelSourceOfTruth describes the source of this app
|
|
||||||
LabelSourceOfTruth = "app.oam.dev/source-of-truth"
|
|
||||||
|
|
||||||
// FromCR means the data source of truth is from k8s CR
|
|
||||||
FromCR = "from-k8s-resource"
|
|
||||||
// FromUX means the data source of truth is from velaux data store
|
|
||||||
FromUX = "from-velaux"
|
|
||||||
// FromInner means the data source of truth is from KubeVela inner usage
|
|
||||||
// the configuration that don't want to be synced
|
|
||||||
// the addon application should be synced, but set to readonly mode
|
|
||||||
FromInner = "from-inner-system"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
||||||
// DefaultInitName is default object name for initialization
|
// DefaultInitName is default object name for initialization
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ import (
|
|||||||
pkgaddon "github.com/oam-dev/kubevela/pkg/addon"
|
pkgaddon "github.com/oam-dev/kubevela/pkg/addon"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/clients"
|
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/clients"
|
||||||
apis "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
apis "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils/bcode"
|
"github.com/oam-dev/kubevela/pkg/apiserver/utils/bcode"
|
||||||
"github.com/oam-dev/kubevela/pkg/definition"
|
"github.com/oam-dev/kubevela/pkg/definition"
|
||||||
"github.com/oam-dev/kubevela/pkg/multicluster"
|
"github.com/oam-dev/kubevela/pkg/multicluster"
|
||||||
@@ -51,6 +50,7 @@ import (
|
|||||||
addonutil "github.com/oam-dev/kubevela/pkg/utils/addon"
|
addonutil "github.com/oam-dev/kubevela/pkg/utils/addon"
|
||||||
"github.com/oam-dev/kubevela/pkg/utils/apply"
|
"github.com/oam-dev/kubevela/pkg/utils/apply"
|
||||||
velaerr "github.com/oam-dev/kubevela/pkg/utils/errors"
|
velaerr "github.com/oam-dev/kubevela/pkg/utils/errors"
|
||||||
|
"github.com/oam-dev/kubevela/pkg/utils/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddonService handle CRUD and installation of addons
|
// AddonService handle CRUD and installation of addons
|
||||||
@@ -539,7 +539,7 @@ func convertAppStateToAddonPhase(state common2.ApplicationPhase) apis.AddonPhase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderAddonCustomUISchema(ctx context.Context, cli client.Client, addonName string, defaultSchema []*utils.UIParameter) []*utils.UIParameter {
|
func renderAddonCustomUISchema(ctx context.Context, cli client.Client, addonName string, defaultSchema []*schema.UIParameter) []*schema.UIParameter {
|
||||||
var cm v1.ConfigMap
|
var cm v1.ConfigMap
|
||||||
if err := cli.Get(ctx, k8stypes.NamespacedName{
|
if err := cli.Get(ctx, k8stypes.NamespacedName{
|
||||||
Namespace: types.DefaultKubeVelaNS,
|
Namespace: types.DefaultKubeVelaNS,
|
||||||
@@ -554,7 +554,7 @@ func renderAddonCustomUISchema(ctx context.Context, cli client.Client, addonName
|
|||||||
if !ok {
|
if !ok {
|
||||||
return defaultSchema
|
return defaultSchema
|
||||||
}
|
}
|
||||||
schema := []*utils.UIParameter{}
|
schema := []*schema.UIParameter{}
|
||||||
if err := json.Unmarshal([]byte(data), &schema); err != nil {
|
if err := json.Unmarshal([]byte(data), &schema); err != nil {
|
||||||
klog.Errorf("unmarshal ui schema failure %s", err.Error())
|
klog.Errorf("unmarshal ui schema failure %s", err.Error())
|
||||||
return defaultSchema
|
return defaultSchema
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/oam-dev/kubevela/pkg/oam/util"
|
"github.com/oam-dev/kubevela/pkg/oam/util"
|
||||||
|
"github.com/oam-dev/kubevela/pkg/utils/schema"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
@@ -30,7 +31,6 @@ import (
|
|||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
|
|
||||||
"github.com/oam-dev/kubevela/apis/types"
|
"github.com/oam-dev/kubevela/apis/types"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("addon service test", func() {
|
var _ = Describe("addon service test", func() {
|
||||||
@@ -56,7 +56,7 @@ var _ = Describe("addon service test", func() {
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
Expect(k8sClient.Create(ctx, &cm)).Should(BeNil())
|
Expect(k8sClient.Create(ctx, &cm)).Should(BeNil())
|
||||||
defaultSchema := []*utils.UIParameter{
|
defaultSchema := []*schema.UIParameter{
|
||||||
{
|
{
|
||||||
JSONKey: "version",
|
JSONKey: "version",
|
||||||
Sort: 3,
|
Sort: 3,
|
||||||
@@ -81,7 +81,7 @@ var _ = Describe("addon service test", func() {
|
|||||||
|
|
||||||
It("Test render without ui-schema", func() {
|
It("Test render without ui-schema", func() {
|
||||||
addonName := "test-without-schema"
|
addonName := "test-without-schema"
|
||||||
defaultSchema := []*utils.UIParameter{
|
defaultSchema := []*schema.UIParameter{
|
||||||
{
|
{
|
||||||
JSONKey: "version",
|
JSONKey: "version",
|
||||||
Sort: 3,
|
Sort: 3,
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ import (
|
|||||||
apisv1 "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
apisv1 "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
"github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils/bcode"
|
"github.com/oam-dev/kubevela/pkg/apiserver/utils/bcode"
|
||||||
|
"github.com/oam-dev/kubevela/pkg/appfile"
|
||||||
"github.com/oam-dev/kubevela/pkg/appfile/dryrun"
|
"github.com/oam-dev/kubevela/pkg/appfile/dryrun"
|
||||||
"github.com/oam-dev/kubevela/pkg/oam"
|
"github.com/oam-dev/kubevela/pkg/oam"
|
||||||
"github.com/oam-dev/kubevela/pkg/oam/discoverymapper"
|
"github.com/oam-dev/kubevela/pkg/oam/discoverymapper"
|
||||||
@@ -555,8 +556,8 @@ func (c *applicationServiceImpl) UpdateApplication(ctx context.Context, app *mod
|
|||||||
req.Labels[model.LabelSyncNamespace] = app.Labels[model.LabelSyncNamespace]
|
req.Labels[model.LabelSyncNamespace] = app.Labels[model.LabelSyncNamespace]
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, exist := app.Labels[model.LabelSourceOfTruth]; exist {
|
if _, exist := app.Labels[velatypes.LabelSourceOfTruth]; exist {
|
||||||
req.Labels[model.LabelSourceOfTruth] = app.Labels[model.LabelSourceOfTruth]
|
req.Labels[velatypes.LabelSourceOfTruth] = app.Labels[velatypes.LabelSourceOfTruth]
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, exist := app.Labels[model.LabelSyncGeneration]; exist {
|
if _, exist := app.Labels[model.LabelSyncGeneration]; exist {
|
||||||
@@ -803,7 +804,7 @@ func (c *applicationServiceImpl) Deploy(ctx context.Context, app *model.Applicat
|
|||||||
if app.Labels == nil {
|
if app.Labels == nil {
|
||||||
app.Labels = make(map[string]string)
|
app.Labels = make(map[string]string)
|
||||||
}
|
}
|
||||||
app.Labels[model.LabelSourceOfTruth] = model.FromUX
|
app.Labels[velatypes.LabelSourceOfTruth] = velatypes.FromUX
|
||||||
if err := c.Store.Put(ctx, app); err != nil {
|
if err := c.Store.Put(ctx, app); err != nil {
|
||||||
klog.Warningf("failed to update app %s", err.Error())
|
klog.Warningf("failed to update app %s", err.Error())
|
||||||
}
|
}
|
||||||
@@ -853,7 +854,7 @@ func (c *applicationServiceImpl) renderOAMApplication(ctx context.Context, appMo
|
|||||||
}
|
}
|
||||||
labels[oam.AnnotationAppName] = appModel.Name
|
labels[oam.AnnotationAppName] = appModel.Name
|
||||||
// To take over the application
|
// To take over the application
|
||||||
labels[model.LabelSourceOfTruth] = model.FromUX
|
labels[velatypes.LabelSourceOfTruth] = velatypes.FromUX
|
||||||
|
|
||||||
deployAppName := envbinding.AppDeployName
|
deployAppName := envbinding.AppDeployName
|
||||||
if deployAppName == "" {
|
if deployAppName == "" {
|
||||||
@@ -1671,7 +1672,7 @@ func (c *applicationServiceImpl) resetApp(ctx context.Context, targetApp *v1beta
|
|||||||
|
|
||||||
for _, comp := range targetComps {
|
for _, comp := range targetComps {
|
||||||
// add or update new app's components from old app
|
// add or update new app's components from old app
|
||||||
if utils.StringsContain(readyToAdd, comp.Name) || utils.StringsContain(readyToUpdate, comp.Name) {
|
if pkgUtils.StringsContain(readyToAdd, comp.Name) || pkgUtils.StringsContain(readyToUpdate, comp.Name) {
|
||||||
compModel, err := convert.FromCRComponent(appPrimaryKey, comp)
|
compModel, err := convert.FromCRComponent(appPrimaryKey, comp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &apisv1.AppResetResponse{}, bcode.ErrInvalidProperties
|
return &apisv1.AppResetResponse{}, bcode.ErrInvalidProperties
|
||||||
@@ -1714,7 +1715,7 @@ func (c *applicationServiceImpl) RollbackWithRevision(ctx context.Context, appli
|
|||||||
if revision.RevisionCRName == revision.Version || revision.RevisionCRName == "" {
|
if revision.RevisionCRName == revision.Version || revision.RevisionCRName == "" {
|
||||||
noRevision = true
|
noRevision = true
|
||||||
} else {
|
} else {
|
||||||
_, appCR, err := app.RollbackApplicationWithRevision(ctx, c.KubeClient, appCR.Name, appCR.Namespace, revision.RevisionCRName, publishVersion)
|
_, appCR, err := app.RollbackApplicationWithRevision(context.WithValue(ctx, &app.RevisionContextKey, utils.WithProject(ctx, "")), c.KubeClient, appCR.Name, appCR.Namespace, revision.RevisionCRName, publishVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, app.ErrNotMatchRevision):
|
case errors.Is(err, app.ErrNotMatchRevision):
|
||||||
@@ -1795,6 +1796,10 @@ func dryRunApplication(ctx context.Context, c commonutil.Args, app *v1beta1.Appl
|
|||||||
return buff, err
|
return buff, err
|
||||||
}
|
}
|
||||||
dryRunOpt := dryrun.NewDryRunOption(newClient, config, dm, pd, objects, true)
|
dryRunOpt := dryrun.NewDryRunOption(newClient, config, dm, pd, objects, true)
|
||||||
|
dryRunOpt.GenerateAppFile = func(ctx context.Context, app *v1beta1.Application) (*appfile.Appfile, error) {
|
||||||
|
generateCtx := utils.WithProject(ctx, "")
|
||||||
|
return dryRunOpt.Parser.GenerateAppFileFromApp(generateCtx, app)
|
||||||
|
}
|
||||||
comps, policies, err := dryRunOpt.ExecuteDryRun(ctx, app)
|
comps, policies, err := dryRunOpt.ExecuteDryRun(ctx, app)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return buff, err
|
return buff, err
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -42,7 +41,9 @@ import (
|
|||||||
"github.com/oam-dev/kubevela/pkg/apiserver/domain/model"
|
"github.com/oam-dev/kubevela/pkg/apiserver/domain/model"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/datastore"
|
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/datastore"
|
||||||
apisv1 "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
apisv1 "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
||||||
|
apiutils "github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils/bcode"
|
"github.com/oam-dev/kubevela/pkg/apiserver/utils/bcode"
|
||||||
|
"github.com/oam-dev/kubevela/pkg/oam"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -379,28 +380,8 @@ func restartDex(ctx context.Context, kubeClient client.Client) error {
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for i, comp := range dexApp.Spec.Components {
|
oam.SetPublishVersion(dexApp, apiutils.GenerateVersion("addon"))
|
||||||
if comp.Name == keyDex {
|
return kubeClient.Update(ctx, dexApp)
|
||||||
var v model.JSONStruct
|
|
||||||
err := json.Unmarshal(comp.Properties.Raw, &v)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// restart the dex server
|
|
||||||
if _, ok := v["values"]; ok {
|
|
||||||
v["values"].(map[string]interface{})["env"] = map[string]string{
|
|
||||||
"TIME_STAMP": time.Now().Format(time.RFC3339),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dexApp.Spec.Components[i].Properties = v.RawExtension()
|
|
||||||
if err := kubeClient.Update(ctx, dexApp); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDexConfig(ctx context.Context, kubeClient client.Client) (*model.DexConfig, error) {
|
func getDexConfig(ctx context.Context, kubeClient client.Client) (*model.DexConfig, error) {
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ import (
|
|||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
"github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils/bcode"
|
"github.com/oam-dev/kubevela/pkg/apiserver/utils/bcode"
|
||||||
"github.com/oam-dev/kubevela/pkg/auth"
|
"github.com/oam-dev/kubevela/pkg/auth"
|
||||||
|
pkgutils "github.com/oam-dev/kubevela/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -259,7 +260,7 @@ func (c *cloudShellServiceImpl) prepareKubeConfig(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
groups = append(groups, utils.TemplateReaderGroup)
|
groups = append(groups, utils.TemplateReaderGroup)
|
||||||
|
|
||||||
if utils.StringsContain(user.UserRoles, "admin") {
|
if pkgutils.StringsContain(user.UserRoles, "admin") {
|
||||||
groups = append(groups, utils.KubeVelaAdminGroupPrefix+"admin")
|
groups = append(groups, utils.KubeVelaAdminGroupPrefix+"admin")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import (
|
|||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
"github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils/bcode"
|
"github.com/oam-dev/kubevela/pkg/apiserver/utils/bcode"
|
||||||
"github.com/oam-dev/kubevela/pkg/auth"
|
"github.com/oam-dev/kubevela/pkg/auth"
|
||||||
|
pkgutils "github.com/oam-dev/kubevela/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("Test cloudshell service function", func() {
|
var _ = Describe("Test cloudshell service function", func() {
|
||||||
@@ -179,8 +180,8 @@ var _ = Describe("Test cloudshell service function", func() {
|
|||||||
var identity auth.Identity
|
var identity auth.Identity
|
||||||
err = yaml.Unmarshal([]byte(cm.Data["identity"]), &identity)
|
err = yaml.Unmarshal([]byte(cm.Data["identity"]), &identity)
|
||||||
Expect(err).Should(BeNil())
|
Expect(err).Should(BeNil())
|
||||||
Expect(utils.StringsContain(identity.Groups, utils.KubeVelaAdminGroupPrefix+"admin")).Should(BeTrue())
|
Expect(pkgutils.StringsContain(identity.Groups, utils.KubeVelaAdminGroupPrefix+"admin")).Should(BeTrue())
|
||||||
Expect(utils.StringsContain(identity.Groups, utils.TemplateReaderGroup)).Should(BeTrue())
|
Expect(pkgutils.StringsContain(identity.Groups, utils.TemplateReaderGroup)).Should(BeTrue())
|
||||||
}
|
}
|
||||||
|
|
||||||
checkConfig()
|
checkConfig()
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import (
|
|||||||
|
|
||||||
"github.com/oam-dev/kubevela/pkg/utils/addon"
|
"github.com/oam-dev/kubevela/pkg/utils/addon"
|
||||||
"github.com/oam-dev/kubevela/pkg/utils/filters"
|
"github.com/oam-dev/kubevela/pkg/utils/filters"
|
||||||
|
"github.com/oam-dev/kubevela/pkg/utils/schema"
|
||||||
|
|
||||||
"github.com/getkin/kin-openapi/openapi3"
|
"github.com/getkin/kin-openapi/openapi3"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@@ -40,8 +41,8 @@ import (
|
|||||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
||||||
"github.com/oam-dev/kubevela/apis/types"
|
"github.com/oam-dev/kubevela/apis/types"
|
||||||
apisv1 "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
apisv1 "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils/bcode"
|
"github.com/oam-dev/kubevela/pkg/apiserver/utils/bcode"
|
||||||
|
"github.com/oam-dev/kubevela/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefinitionService definition service, Implement the management of ComponentDefinition、TraitDefinition and WorkflowStepDefinition.
|
// DefinitionService definition service, Implement the management of ComponentDefinition、TraitDefinition and WorkflowStepDefinition.
|
||||||
@@ -51,7 +52,7 @@ type DefinitionService interface {
|
|||||||
// DetailDefinition get definition detail
|
// DetailDefinition get definition detail
|
||||||
DetailDefinition(ctx context.Context, name, defType string) (*apisv1.DetailDefinitionResponse, error)
|
DetailDefinition(ctx context.Context, name, defType string) (*apisv1.DetailDefinitionResponse, error)
|
||||||
// AddDefinitionUISchema add or update custom definition ui schema
|
// AddDefinitionUISchema add or update custom definition ui schema
|
||||||
AddDefinitionUISchema(ctx context.Context, name, defType string, schema []*utils.UIParameter) ([]*utils.UIParameter, error)
|
AddDefinitionUISchema(ctx context.Context, name, defType string, schema []*schema.UIParameter) ([]*schema.UIParameter, error)
|
||||||
// UpdateDefinitionStatus update the status of definition
|
// UpdateDefinitionStatus update the status of definition
|
||||||
UpdateDefinitionStatus(ctx context.Context, name string, status apisv1.UpdateDefinitionStatusRequest) (*apisv1.DetailDefinitionResponse, error)
|
UpdateDefinitionStatus(ctx context.Context, name string, status apisv1.UpdateDefinitionStatusRequest) (*apisv1.DetailDefinitionResponse, error)
|
||||||
}
|
}
|
||||||
@@ -278,7 +279,7 @@ func (d *definitionServiceImpl) DetailDefinition(ctx context.Context, name, defT
|
|||||||
return definition, nil
|
return definition, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderCustomUISchema(ctx context.Context, cli client.Client, name, defType string, defaultSchema []*utils.UIParameter) []*utils.UIParameter {
|
func renderCustomUISchema(ctx context.Context, cli client.Client, name, defType string, defaultSchema []*schema.UIParameter) []*schema.UIParameter {
|
||||||
var cm v1.ConfigMap
|
var cm v1.ConfigMap
|
||||||
if err := cli.Get(ctx, k8stypes.NamespacedName{
|
if err := cli.Get(ctx, k8stypes.NamespacedName{
|
||||||
Namespace: types.DefaultKubeVelaNS,
|
Namespace: types.DefaultKubeVelaNS,
|
||||||
@@ -293,7 +294,7 @@ func renderCustomUISchema(ctx context.Context, cli client.Client, name, defType
|
|||||||
if !ok {
|
if !ok {
|
||||||
return defaultSchema
|
return defaultSchema
|
||||||
}
|
}
|
||||||
schema := []*utils.UIParameter{}
|
schema := []*schema.UIParameter{}
|
||||||
if err := json.Unmarshal([]byte(data), &schema); err != nil {
|
if err := json.Unmarshal([]byte(data), &schema); err != nil {
|
||||||
klog.Errorf("unmarshal ui schema failure %s", err.Error())
|
klog.Errorf("unmarshal ui schema failure %s", err.Error())
|
||||||
return defaultSchema
|
return defaultSchema
|
||||||
@@ -302,7 +303,7 @@ func renderCustomUISchema(ctx context.Context, cli client.Client, name, defType
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddDefinitionUISchema add definition custom ui schema config
|
// AddDefinitionUISchema add definition custom ui schema config
|
||||||
func (d *definitionServiceImpl) AddDefinitionUISchema(ctx context.Context, name, defType string, schema []*utils.UIParameter) ([]*utils.UIParameter, error) {
|
func (d *definitionServiceImpl) AddDefinitionUISchema(ctx context.Context, name, defType string, schema []*schema.UIParameter) ([]*schema.UIParameter, error) {
|
||||||
dataBate, err := json.Marshal(schema)
|
dataBate, err := json.Marshal(schema)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("json marshal failure %s", err.Error())
|
klog.Errorf("json marshal failure %s", err.Error())
|
||||||
@@ -376,8 +377,8 @@ func (d *definitionServiceImpl) UpdateDefinitionStatus(ctx context.Context, name
|
|||||||
return d.DetailDefinition(ctx, name, update.DefinitionType)
|
return d.DetailDefinition(ctx, name, update.DefinitionType)
|
||||||
}
|
}
|
||||||
|
|
||||||
func patchSchema(defaultSchema, customSchema []*utils.UIParameter) []*utils.UIParameter {
|
func patchSchema(defaultSchema, customSchema []*schema.UIParameter) []*schema.UIParameter {
|
||||||
var customSchemaMap = make(map[string]*utils.UIParameter, len(customSchema))
|
var customSchemaMap = make(map[string]*schema.UIParameter, len(customSchema))
|
||||||
for i, custom := range customSchema {
|
for i, custom := range customSchema {
|
||||||
customSchemaMap[custom.JSONKey] = customSchema[i]
|
customSchemaMap[custom.JSONKey] = customSchema[i]
|
||||||
}
|
}
|
||||||
@@ -428,14 +429,14 @@ func patchSchema(defaultSchema, customSchema []*utils.UIParameter) []*utils.UIPa
|
|||||||
return defaultSchema
|
return defaultSchema
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderDefaultUISchema(apiSchema *openapi3.Schema) []*utils.UIParameter {
|
func renderDefaultUISchema(apiSchema *openapi3.Schema) []*schema.UIParameter {
|
||||||
if apiSchema == nil {
|
if apiSchema == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var params []*utils.UIParameter
|
var params []*schema.UIParameter
|
||||||
for key, property := range apiSchema.Properties {
|
for key, property := range apiSchema.Properties {
|
||||||
if property.Value != nil {
|
if property.Value != nil {
|
||||||
param := renderUIParameter(key, utils.FirstUpper(key), property, apiSchema.Required)
|
param := renderUIParameter(key, schema.FirstUpper(key), property, apiSchema.Required)
|
||||||
params = append(params, param)
|
params = append(params, param)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -449,7 +450,7 @@ func renderDefaultUISchema(apiSchema *openapi3.Schema) []*utils.UIParameter {
|
|||||||
// 3.If validate.required or subParameters is equal, sort by Label
|
// 3.If validate.required or subParameters is equal, sort by Label
|
||||||
//
|
//
|
||||||
// The sort number starts with 100.
|
// The sort number starts with 100.
|
||||||
func sortDefaultUISchema(params []*utils.UIParameter) {
|
func sortDefaultUISchema(params []*schema.UIParameter) {
|
||||||
sort.Slice(params, func(i, j int) bool {
|
sort.Slice(params, func(i, j int) bool {
|
||||||
switch {
|
switch {
|
||||||
case params[i].Validate.Required && !params[j].Validate.Required:
|
case params[i].Validate.Required && !params[j].Validate.Required:
|
||||||
@@ -472,8 +473,8 @@ func sortDefaultUISchema(params []*utils.UIParameter) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderUIParameter(key, label string, property *openapi3.SchemaRef, required []string) *utils.UIParameter {
|
func renderUIParameter(key, label string, property *openapi3.SchemaRef, required []string) *schema.UIParameter {
|
||||||
var parameter utils.UIParameter
|
var parameter schema.UIParameter
|
||||||
subType := ""
|
subType := ""
|
||||||
if property.Value.Items != nil {
|
if property.Value.Items != nil {
|
||||||
if property.Value.Items.Value != nil {
|
if property.Value.Items.Value != nil {
|
||||||
@@ -488,18 +489,18 @@ func renderUIParameter(key, label string, property *openapi3.SchemaRef, required
|
|||||||
parameter.SubParameters = renderDefaultUISchema(property.Value.AdditionalProperties.Value)
|
parameter.SubParameters = renderDefaultUISchema(property.Value.AdditionalProperties.Value)
|
||||||
var enable = true
|
var enable = true
|
||||||
value := property.Value.AdditionalProperties.Value
|
value := property.Value.AdditionalProperties.Value
|
||||||
parameter.AdditionalParameter = renderUIParameter(value.Title, utils.FirstUpper(value.Title), property.Value.AdditionalProperties, value.Required)
|
parameter.AdditionalParameter = renderUIParameter(value.Title, schema.FirstUpper(value.Title), property.Value.AdditionalProperties, value.Required)
|
||||||
parameter.Additional = &enable
|
parameter.Additional = &enable
|
||||||
}
|
}
|
||||||
parameter.Validate = &utils.Validate{}
|
parameter.Validate = &schema.Validate{}
|
||||||
parameter.Validate.DefaultValue = property.Value.Default
|
parameter.Validate.DefaultValue = property.Value.Default
|
||||||
for _, enum := range property.Value.Enum {
|
for _, enum := range property.Value.Enum {
|
||||||
parameter.Validate.Options = append(parameter.Validate.Options, utils.Option{Label: utils.RenderLabel(enum), Value: enum})
|
parameter.Validate.Options = append(parameter.Validate.Options, schema.Option{Label: schema.RenderLabel(enum), Value: enum})
|
||||||
}
|
}
|
||||||
parameter.JSONKey = key
|
parameter.JSONKey = key
|
||||||
parameter.Description = property.Value.Description
|
parameter.Description = property.Value.Description
|
||||||
parameter.Label = label
|
parameter.Label = label
|
||||||
parameter.UIType = utils.GetDefaultUIType(property.Value.Type, len(parameter.Validate.Options) != 0, subType, len(property.Value.Properties) > 0)
|
parameter.UIType = schema.GetDefaultUIType(property.Value.Type, len(parameter.Validate.Options) != 0, subType, len(property.Value.Properties) > 0)
|
||||||
parameter.Validate.Max = property.Value.Max
|
parameter.Validate.Max = property.Value.Max
|
||||||
parameter.Validate.MaxLength = property.Value.MaxLength
|
parameter.Validate.MaxLength = property.Value.MaxLength
|
||||||
parameter.Validate.Min = property.Value.Min
|
parameter.Validate.Min = property.Value.Min
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ import (
|
|||||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
||||||
"github.com/oam-dev/kubevela/apis/types"
|
"github.com/oam-dev/kubevela/apis/types"
|
||||||
v1 "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
v1 "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
|
||||||
"github.com/oam-dev/kubevela/pkg/oam/util"
|
"github.com/oam-dev/kubevela/pkg/oam/util"
|
||||||
|
"github.com/oam-dev/kubevela/pkg/utils/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("Test namespace service functions", func() {
|
var _ = Describe("Test namespace service functions", func() {
|
||||||
@@ -217,7 +217,7 @@ var _ = Describe("Test namespace service functions", func() {
|
|||||||
Expect(cmp.Diff(len(ddr.APISchema.Required), 3)).Should(BeEmpty())
|
Expect(cmp.Diff(len(ddr.APISchema.Required), 3)).Should(BeEmpty())
|
||||||
defaultschema := renderDefaultUISchema(ddr.APISchema)
|
defaultschema := renderDefaultUISchema(ddr.APISchema)
|
||||||
|
|
||||||
customschema := []*utils.UIParameter{}
|
customschema := []*schema.UIParameter{}
|
||||||
cdata, err := os.ReadFile("./testdata/ui-custom-schema.yaml")
|
cdata, err := os.ReadFile("./testdata/ui-custom-schema.yaml")
|
||||||
Expect(err).Should(Succeed())
|
Expect(err).Should(Succeed())
|
||||||
err = yaml.Unmarshal(cdata, &customschema)
|
err = yaml.Unmarshal(cdata, &customschema)
|
||||||
@@ -237,7 +237,7 @@ var _ = Describe("Test namespace service functions", func() {
|
|||||||
}
|
}
|
||||||
cdata, err := os.ReadFile("./testdata/workflowstep-apply-object.yaml")
|
cdata, err := os.ReadFile("./testdata/workflowstep-apply-object.yaml")
|
||||||
Expect(err).Should(Succeed())
|
Expect(err).Should(Succeed())
|
||||||
var schema utils.UISchema
|
var schema schema.UISchema
|
||||||
yaml.Unmarshal(cdata, &schema)
|
yaml.Unmarshal(cdata, &schema)
|
||||||
uiSchema, err := du.AddDefinitionUISchema(context.TODO(), "apply-object", "workflowstep", schema)
|
uiSchema, err := du.AddDefinitionUISchema(context.TODO(), "apply-object", "workflowstep", schema)
|
||||||
Expect(err).Should(Succeed())
|
Expect(err).Should(Succeed())
|
||||||
@@ -272,22 +272,22 @@ var _ = Describe("Test namespace service functions", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
func testSortDefaultUISchema() {
|
func testSortDefaultUISchema() {
|
||||||
var params = []*utils.UIParameter{
|
var params = []*schema.UIParameter{
|
||||||
{
|
{
|
||||||
Label: "P1",
|
Label: "P1",
|
||||||
Validate: &utils.Validate{
|
Validate: &schema.Validate{
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
SubParameters: []*utils.UIParameter{
|
SubParameters: []*schema.UIParameter{
|
||||||
{Label: "P1S1"},
|
{Label: "P1S1"},
|
||||||
},
|
},
|
||||||
Sort: 100,
|
Sort: 100,
|
||||||
}, {
|
}, {
|
||||||
Label: "T2",
|
Label: "T2",
|
||||||
Validate: &utils.Validate{
|
Validate: &schema.Validate{
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
SubParameters: []*utils.UIParameter{
|
SubParameters: []*schema.UIParameter{
|
||||||
{Label: "T2S1"},
|
{Label: "T2S1"},
|
||||||
{Label: "T2S2"},
|
{Label: "T2S2"},
|
||||||
{Label: "T2S3"},
|
{Label: "T2S3"},
|
||||||
@@ -295,32 +295,32 @@ func testSortDefaultUISchema() {
|
|||||||
Sort: 100,
|
Sort: 100,
|
||||||
}, {
|
}, {
|
||||||
Label: "T3",
|
Label: "T3",
|
||||||
Validate: &utils.Validate{
|
Validate: &schema.Validate{
|
||||||
Required: false,
|
Required: false,
|
||||||
},
|
},
|
||||||
Sort: 100,
|
Sort: 100,
|
||||||
}, {
|
}, {
|
||||||
Label: "P4",
|
Label: "P4",
|
||||||
Validate: &utils.Validate{
|
Validate: &schema.Validate{
|
||||||
Required: false,
|
Required: false,
|
||||||
},
|
},
|
||||||
Sort: 100,
|
Sort: 100,
|
||||||
}, {
|
}, {
|
||||||
Label: "T5",
|
Label: "T5",
|
||||||
Validate: &utils.Validate{
|
Validate: &schema.Validate{
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
SubParameters: []*utils.UIParameter{
|
SubParameters: []*schema.UIParameter{
|
||||||
{Label: "T5S1"},
|
{Label: "T5S1"},
|
||||||
{Label: "T5S2"},
|
{Label: "T5S2"},
|
||||||
},
|
},
|
||||||
Sort: 100,
|
Sort: 100,
|
||||||
}, {
|
}, {
|
||||||
Label: "P6",
|
Label: "P6",
|
||||||
Validate: &utils.Validate{
|
Validate: &schema.Validate{
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
SubParameters: []*utils.UIParameter{
|
SubParameters: []*schema.UIParameter{
|
||||||
{Label: "P6S1"},
|
{Label: "P6S1"},
|
||||||
{Label: "P6S2"},
|
{Label: "P6S2"},
|
||||||
{Label: "P6S3"},
|
{Label: "P6S3"},
|
||||||
@@ -329,32 +329,32 @@ func testSortDefaultUISchema() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var expectedParams = []*utils.UIParameter{
|
var expectedParams = []*schema.UIParameter{
|
||||||
{
|
{
|
||||||
Label: "P1",
|
Label: "P1",
|
||||||
Validate: &utils.Validate{
|
Validate: &schema.Validate{
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
SubParameters: []*utils.UIParameter{
|
SubParameters: []*schema.UIParameter{
|
||||||
{Label: "P1S1"},
|
{Label: "P1S1"},
|
||||||
},
|
},
|
||||||
Sort: 100,
|
Sort: 100,
|
||||||
}, {
|
}, {
|
||||||
Label: "T5",
|
Label: "T5",
|
||||||
Validate: &utils.Validate{
|
Validate: &schema.Validate{
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
SubParameters: []*utils.UIParameter{
|
SubParameters: []*schema.UIParameter{
|
||||||
{Label: "T5S1"},
|
{Label: "T5S1"},
|
||||||
{Label: "T5S2"},
|
{Label: "T5S2"},
|
||||||
},
|
},
|
||||||
Sort: 101,
|
Sort: 101,
|
||||||
}, {
|
}, {
|
||||||
Label: "P6",
|
Label: "P6",
|
||||||
Validate: &utils.Validate{
|
Validate: &schema.Validate{
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
SubParameters: []*utils.UIParameter{
|
SubParameters: []*schema.UIParameter{
|
||||||
{Label: "P6S1"},
|
{Label: "P6S1"},
|
||||||
{Label: "P6S2"},
|
{Label: "P6S2"},
|
||||||
{Label: "P6S3"},
|
{Label: "P6S3"},
|
||||||
@@ -362,10 +362,10 @@ func testSortDefaultUISchema() {
|
|||||||
Sort: 102,
|
Sort: 102,
|
||||||
}, {
|
}, {
|
||||||
Label: "T2",
|
Label: "T2",
|
||||||
Validate: &utils.Validate{
|
Validate: &schema.Validate{
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
SubParameters: []*utils.UIParameter{
|
SubParameters: []*schema.UIParameter{
|
||||||
{Label: "T2S1"},
|
{Label: "T2S1"},
|
||||||
{Label: "T2S2"},
|
{Label: "T2S2"},
|
||||||
{Label: "T2S3"},
|
{Label: "T2S3"},
|
||||||
@@ -373,13 +373,13 @@ func testSortDefaultUISchema() {
|
|||||||
Sort: 103,
|
Sort: 103,
|
||||||
}, {
|
}, {
|
||||||
Label: "P4",
|
Label: "P4",
|
||||||
Validate: &utils.Validate{
|
Validate: &schema.Validate{
|
||||||
Required: false,
|
Required: false,
|
||||||
},
|
},
|
||||||
Sort: 104,
|
Sort: 104,
|
||||||
}, {
|
}, {
|
||||||
Label: "T3",
|
Label: "T3",
|
||||||
Validate: &utils.Validate{
|
Validate: &schema.Validate{
|
||||||
Required: false,
|
Required: false,
|
||||||
},
|
},
|
||||||
Sort: 105,
|
Sort: 105,
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ func (p *envServiceImpl) UpdateEnv(ctx context.Context, name string, req apisv1.
|
|||||||
|
|
||||||
func (p *envServiceImpl) GetAppCountInEnv(ctx context.Context, env *model.Env) (int, error) {
|
func (p *envServiceImpl) GetAppCountInEnv(ctx context.Context, env *model.Env) (int, error) {
|
||||||
var appList v1beta1.ApplicationList
|
var appList v1beta1.ApplicationList
|
||||||
if err := p.KubeClient.List(ctx, &appList, client.InNamespace(env.Namespace), client.MatchingLabels{model.LabelSourceOfTruth: model.FromUX}); err != nil {
|
if err := p.KubeClient.List(ctx, &appList, client.InNamespace(env.Namespace), client.MatchingLabels{types.LabelSourceOfTruth: types.FromUX}); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return len(appList.Items), nil
|
return len(appList.Items), nil
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import (
|
|||||||
|
|
||||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/common"
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/common"
|
||||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
||||||
|
velatypes "github.com/oam-dev/kubevela/apis/types"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/domain/model"
|
"github.com/oam-dev/kubevela/pkg/apiserver/domain/model"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/datastore"
|
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/datastore"
|
||||||
apisv1 "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
apisv1 "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
||||||
@@ -132,7 +133,7 @@ var _ = Describe("Test env service functions", func() {
|
|||||||
Name: "env-app",
|
Name: "env-app",
|
||||||
Namespace: env.Namespace,
|
Namespace: env.Namespace,
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
model.LabelSourceOfTruth: model.FromUX,
|
velatypes.LabelSourceOfTruth: velatypes.FromUX,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Spec: v1beta1.ApplicationSpec{
|
Spec: v1beta1.ApplicationSpec{
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ import (
|
|||||||
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/datastore"
|
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/datastore"
|
||||||
assembler "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/assembler/v1"
|
assembler "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/assembler/v1"
|
||||||
apisv1 "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
apisv1 "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils/bcode"
|
"github.com/oam-dev/kubevela/pkg/apiserver/utils/bcode"
|
||||||
pkgUtils "github.com/oam-dev/kubevela/pkg/utils"
|
pkgUtils "github.com/oam-dev/kubevela/pkg/utils"
|
||||||
)
|
)
|
||||||
@@ -87,7 +86,7 @@ func (e *envBindingServiceImpl) GetEnvBinding(ctx context.Context, app *model.Ap
|
|||||||
func CheckAppEnvBindingsContainTarget(envBindings []*apisv1.EnvBindingBase, targetName string) (bool, error) {
|
func CheckAppEnvBindingsContainTarget(envBindings []*apisv1.EnvBindingBase, targetName string) (bool, error) {
|
||||||
var filteredList []*apisv1.EnvBindingBase
|
var filteredList []*apisv1.EnvBindingBase
|
||||||
for _, envBinding := range envBindings {
|
for _, envBinding := range envBindings {
|
||||||
if utils.StringsContain(envBinding.TargetNames, targetName) {
|
if pkgUtils.StringsContain(envBinding.TargetNames, targetName) {
|
||||||
filteredList = append(filteredList, envBinding)
|
filteredList = append(filteredList, envBinding)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ import (
|
|||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
types2 "github.com/oam-dev/kubevela/apis/types"
|
velatypes "github.com/oam-dev/kubevela/apis/types"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/domain/model"
|
"github.com/oam-dev/kubevela/pkg/apiserver/domain/model"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/datastore"
|
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/datastore"
|
||||||
apis "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
apis "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
||||||
@@ -491,7 +491,7 @@ func (p pipelineRunServiceImpl) GetPipelineRunLog(ctx context.Context, pipelineR
|
|||||||
switch {
|
switch {
|
||||||
case logConfig.Data:
|
case logConfig.Data:
|
||||||
logs, err = getResourceLogs(ctx, p.KubeConfig, p.KubeClient, []wfTypes.Resource{{
|
logs, err = getResourceLogs(ctx, p.KubeConfig, p.KubeClient, []wfTypes.Resource{{
|
||||||
Namespace: types2.DefaultKubeVelaNS,
|
Namespace: velatypes.DefaultKubeVelaNS,
|
||||||
LabelSelector: map[string]string{"app.kubernetes.io/name": "vela-workflow"},
|
LabelSelector: map[string]string{"app.kubernetes.io/name": "vela-workflow"},
|
||||||
}}, []string{fmt.Sprintf(`step_name="%s"`, step), fmt.Sprintf("%s/%s", project.GetNamespace(), pipelineRun.PipelineRunName), "cue logs"})
|
}}, []string{fmt.Sprintf(`step_name="%s"`, step), fmt.Sprintf("%s/%s", project.GetNamespace(), pipelineRun.PipelineRunName), "cue logs"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -767,8 +767,8 @@ func (p pipelineServiceImpl) RunPipeline(ctx context.Context, pipeline apis.Pipe
|
|||||||
run.Spec.Mode = &req.Mode
|
run.Spec.Mode = &req.Mode
|
||||||
|
|
||||||
run.SetLabels(map[string]string{
|
run.SetLabels(map[string]string{
|
||||||
labelPipeline: pipeline.Name,
|
labelPipeline: pipeline.Name,
|
||||||
model.LabelSourceOfTruth: model.FromUX,
|
velatypes.LabelSourceOfTruth: velatypes.FromUX,
|
||||||
})
|
})
|
||||||
if p.Version != "" {
|
if p.Version != "" {
|
||||||
if err := k8s.AddAnnotation(&run, wfTypes.AnnotationControllerRequirement, p.Version); err != nil {
|
if err := k8s.AddAnnotation(&run, wfTypes.AnnotationControllerRequirement, p.Version); err != nil {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import (
|
|||||||
|
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/clients"
|
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/clients"
|
||||||
apis "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
apis "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
||||||
|
"github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils/bcode"
|
"github.com/oam-dev/kubevela/pkg/apiserver/utils/bcode"
|
||||||
"github.com/oam-dev/kubevela/pkg/oam/discoverymapper"
|
"github.com/oam-dev/kubevela/pkg/oam/discoverymapper"
|
||||||
"github.com/oam-dev/kubevela/pkg/velaql"
|
"github.com/oam-dev/kubevela/pkg/velaql"
|
||||||
@@ -70,7 +71,7 @@ func (v *velaQLServiceImpl) QueryView(ctx context.Context, velaQL string) (*apis
|
|||||||
return nil, bcode.ErrParseVelaQL
|
return nil, bcode.ErrParseVelaQL
|
||||||
}
|
}
|
||||||
|
|
||||||
queryValue, err := velaql.NewViewHandler(v.KubeClient, v.KubeConfig, v.dm, v.pd).QueryView(ctx, query)
|
queryValue, err := velaql.NewViewHandler(v.KubeClient, v.KubeConfig, v.dm, v.pd).QueryView(utils.ContextWithUserInfo(ctx), query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("fail to query the view %s", err.Error())
|
klog.Errorf("fail to query the view %s", err.Error())
|
||||||
return nil, bcode.ErrViewQuery
|
return nil, bcode.ErrViewQuery
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import (
|
|||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
|
||||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
||||||
|
"github.com/oam-dev/kubevela/apis/types"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/domain/model"
|
"github.com/oam-dev/kubevela/pkg/apiserver/domain/model"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/datastore"
|
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/datastore"
|
||||||
"github.com/oam-dev/kubevela/pkg/oam"
|
"github.com/oam-dev/kubevela/pkg/oam"
|
||||||
@@ -67,11 +68,11 @@ func (c *CR2UX) initCache(ctx context.Context) error {
|
|||||||
func (c *CR2UX) shouldSync(ctx context.Context, targetApp *v1beta1.Application, del bool) bool {
|
func (c *CR2UX) shouldSync(ctx context.Context, targetApp *v1beta1.Application, del bool) bool {
|
||||||
if targetApp != nil && targetApp.Labels != nil {
|
if targetApp != nil && targetApp.Labels != nil {
|
||||||
// the source is inner and is not the addon application, ignore it.
|
// the source is inner and is not the addon application, ignore it.
|
||||||
if targetApp.Labels[model.LabelSourceOfTruth] == model.FromInner && targetApp.Labels[oam.LabelAddonName] == "" {
|
if targetApp.Labels[types.LabelSourceOfTruth] == types.FromInner && targetApp.Labels[oam.LabelAddonName] == "" {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// the source is UX, ignore it
|
// the source is UX, ignore it
|
||||||
if targetApp.Labels[model.LabelSourceOfTruth] == model.FromUX {
|
if targetApp.Labels[types.LabelSourceOfTruth] == types.FromUX {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import (
|
|||||||
|
|
||||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/common"
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/common"
|
||||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
||||||
|
velatypes "github.com/oam-dev/kubevela/apis/types"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/domain/model"
|
"github.com/oam-dev/kubevela/pkg/apiserver/domain/model"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/datastore"
|
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/datastore"
|
||||||
"github.com/oam-dev/kubevela/pkg/oam/util"
|
"github.com/oam-dev/kubevela/pkg/oam/util"
|
||||||
@@ -59,9 +60,9 @@ var _ = Describe("Test Cache", func() {
|
|||||||
}})).Should(BeNil())
|
}})).Should(BeNil())
|
||||||
|
|
||||||
Expect(ds.Add(ctx, &model.Application{Name: "app3", Labels: map[string]string{
|
Expect(ds.Add(ctx, &model.Application{Name: "app3", Labels: map[string]string{
|
||||||
model.LabelSyncGeneration: "1",
|
model.LabelSyncGeneration: "1",
|
||||||
model.LabelSyncNamespace: "app3-ns",
|
model.LabelSyncNamespace: "app3-ns",
|
||||||
model.LabelSourceOfTruth: model.FromUX,
|
velatypes.LabelSourceOfTruth: velatypes.FromUX,
|
||||||
}})).Should(BeNil())
|
}})).Should(BeNil())
|
||||||
|
|
||||||
Expect(cr2ux.initCache(ctx)).Should(BeNil())
|
Expect(cr2ux.initCache(ctx)).Should(BeNil())
|
||||||
@@ -87,7 +88,7 @@ var _ = Describe("Test Cache", func() {
|
|||||||
app3.Namespace = "app3-ns"
|
app3.Namespace = "app3-ns"
|
||||||
app3.ResourceVersion = "3"
|
app3.ResourceVersion = "3"
|
||||||
app3.Labels = map[string]string{
|
app3.Labels = map[string]string{
|
||||||
model.LabelSourceOfTruth: model.FromUX,
|
velatypes.LabelSourceOfTruth: velatypes.FromUX,
|
||||||
}
|
}
|
||||||
|
|
||||||
Expect(cr2ux.shouldSync(ctx, app3, false)).Should(BeEquivalentTo(false))
|
Expect(cr2ux.shouldSync(ctx, app3, false)).Should(BeEquivalentTo(false))
|
||||||
@@ -124,7 +125,7 @@ var _ = Describe("Test Cache", func() {
|
|||||||
app1.Generation = 1
|
app1.Generation = 1
|
||||||
app1.Spec.Components = []common.ApplicationComponent{}
|
app1.Spec.Components = []common.ApplicationComponent{}
|
||||||
app1.Labels = make(map[string]string)
|
app1.Labels = make(map[string]string)
|
||||||
app1.Labels[model.LabelSourceOfTruth] = model.FromInner
|
app1.Labels[velatypes.LabelSourceOfTruth] = velatypes.FromInner
|
||||||
Expect(k8sClient.Create(ctx, app1)).Should(BeNil())
|
Expect(k8sClient.Create(ctx, app1)).Should(BeNil())
|
||||||
Expect(cr2ux.shouldSync(ctx, app1, false)).Should(BeEquivalentTo(false))
|
Expect(cr2ux.shouldSync(ctx, app1, false)).Should(BeEquivalentTo(false))
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ import (
|
|||||||
"github.com/oam-dev/kubevela/pkg/apiserver/domain/model"
|
"github.com/oam-dev/kubevela/pkg/apiserver/domain/model"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/event/sync/convert"
|
"github.com/oam-dev/kubevela/pkg/apiserver/event/sync/convert"
|
||||||
v1 "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
v1 "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
|
||||||
"github.com/oam-dev/kubevela/pkg/oam"
|
"github.com/oam-dev/kubevela/pkg/oam"
|
||||||
|
pkgutils "github.com/oam-dev/kubevela/pkg/utils"
|
||||||
"github.com/oam-dev/kubevela/pkg/workflow/step"
|
"github.com/oam-dev/kubevela/pkg/workflow/step"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -44,10 +44,10 @@ func (c *CR2UX) ConvertApp2DatastoreApp(ctx context.Context, targetApp *v1beta1.
|
|||||||
project := v1.CreateProjectRequest{
|
project := v1.CreateProjectRequest{
|
||||||
Name: model.DefaultInitName,
|
Name: model.DefaultInitName,
|
||||||
}
|
}
|
||||||
sourceOfTruth := model.FromCR
|
sourceOfTruth := apitypes.FromCR
|
||||||
if _, ok := targetApp.Labels[oam.LabelAddonName]; ok && strings.HasPrefix(targetApp.Name, "addon-") && targetApp.Namespace == apitypes.DefaultKubeVelaNS {
|
if _, ok := targetApp.Labels[oam.LabelAddonName]; ok && strings.HasPrefix(targetApp.Name, "addon-") && targetApp.Namespace == apitypes.DefaultKubeVelaNS {
|
||||||
project = c.generateSystemProject(ctx, targetApp.Namespace)
|
project = c.generateSystemProject(ctx, targetApp.Namespace)
|
||||||
sourceOfTruth = model.FromInner
|
sourceOfTruth = apitypes.FromInner
|
||||||
}
|
}
|
||||||
|
|
||||||
appMeta := &model.Application{
|
appMeta := &model.Application{
|
||||||
@@ -56,10 +56,10 @@ func (c *CR2UX) ConvertApp2DatastoreApp(ctx context.Context, targetApp *v1beta1.
|
|||||||
Alias: targetApp.Name,
|
Alias: targetApp.Name,
|
||||||
Project: project.Name,
|
Project: project.Name,
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
model.LabelSyncNamespace: targetApp.Namespace,
|
model.LabelSyncNamespace: targetApp.Namespace,
|
||||||
model.LabelSyncGeneration: strconv.FormatInt(targetApp.Generation, 10),
|
model.LabelSyncGeneration: strconv.FormatInt(targetApp.Generation, 10),
|
||||||
model.LabelSyncRevision: getRevision(*targetApp),
|
model.LabelSyncRevision: getRevision(*targetApp),
|
||||||
model.LabelSourceOfTruth: sourceOfTruth,
|
apitypes.LabelSourceOfTruth: sourceOfTruth,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
appMeta.CreateTime = targetApp.CreationTimestamp.Time
|
appMeta.CreateTime = targetApp.CreationTimestamp.Time
|
||||||
@@ -186,7 +186,7 @@ func (c *CR2UX) generateEnv(ctx context.Context, defaultProject string, envNames
|
|||||||
if len(existEnvs) > 0 {
|
if len(existEnvs) > 0 {
|
||||||
env := existEnvs[0].(*model.Env)
|
env := existEnvs[0].(*model.Env)
|
||||||
for name, project := range envTargetNames {
|
for name, project := range envTargetNames {
|
||||||
if !utils.StringsContain(env.Targets, name) && project == env.Project {
|
if !pkgutils.StringsContain(env.Targets, name) && project == env.Project {
|
||||||
env.Targets = append(env.Targets, name)
|
env.Targets = append(env.Targets, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,10 +32,10 @@ import (
|
|||||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/domain/model"
|
"github.com/oam-dev/kubevela/pkg/apiserver/domain/model"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/datastore"
|
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/datastore"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
|
||||||
"github.com/oam-dev/kubevela/pkg/multicluster"
|
"github.com/oam-dev/kubevela/pkg/multicluster"
|
||||||
"github.com/oam-dev/kubevela/pkg/oam"
|
"github.com/oam-dev/kubevela/pkg/oam"
|
||||||
"github.com/oam-dev/kubevela/pkg/policy"
|
"github.com/oam-dev/kubevela/pkg/policy"
|
||||||
|
"github.com/oam-dev/kubevela/pkg/utils/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FromCRComponent concerts Application CR Component object into velaux data store component
|
// FromCRComponent concerts Application CR Component object into velaux data store component
|
||||||
@@ -97,7 +97,7 @@ func FromCRWorkflow(ctx context.Context, cli client.Client, appPrimaryKey string
|
|||||||
AppPrimaryKey: appPrimaryKey,
|
AppPrimaryKey: appPrimaryKey,
|
||||||
EnvName: envName,
|
EnvName: envName,
|
||||||
Name: name,
|
Name: name,
|
||||||
Alias: fmt.Sprintf("%s Workflow", utils.FirstUpper(envName)),
|
Alias: fmt.Sprintf("%s Workflow", schema.FirstUpper(envName)),
|
||||||
Description: model.AutoGenDesc,
|
Description: model.AutoGenDesc,
|
||||||
Default: &defaultWorkflow,
|
Default: &defaultWorkflow,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import (
|
|||||||
|
|
||||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/common"
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/common"
|
||||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
||||||
|
"github.com/oam-dev/kubevela/apis/types"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/domain/model"
|
"github.com/oam-dev/kubevela/pkg/apiserver/domain/model"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/domain/service"
|
"github.com/oam-dev/kubevela/pkg/apiserver/domain/service"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/datastore"
|
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/datastore"
|
||||||
@@ -86,7 +87,7 @@ var _ = Describe("Test CR convert to ux", func() {
|
|||||||
By("app get the created app")
|
By("app get the created app")
|
||||||
gotApp, gotAppName, err = cr2ux.getApp(context.Background(), apName1, appNS2)
|
gotApp, gotAppName, err = cr2ux.getApp(context.Background(), apName1, appNS2)
|
||||||
Expect(gotAppName).Should(BeEquivalentTo(apName1))
|
Expect(gotAppName).Should(BeEquivalentTo(apName1))
|
||||||
Expect(gotApp.Labels[model.LabelSourceOfTruth]).Should(BeEquivalentTo(model.FromCR))
|
Expect(gotApp.Labels[types.LabelSourceOfTruth]).Should(BeEquivalentTo(types.FromCR))
|
||||||
Expect(err).Should(BeNil())
|
Expect(err).Should(BeNil())
|
||||||
Expect(gotApp.IsSynced()).Should(BeEquivalentTo(true))
|
Expect(gotApp.IsSynced()).Should(BeEquivalentTo(true))
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ import (
|
|||||||
|
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/domain/service"
|
"github.com/oam-dev/kubevela/pkg/apiserver/domain/service"
|
||||||
apis "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
apis "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils/bcode"
|
"github.com/oam-dev/kubevela/pkg/apiserver/utils/bcode"
|
||||||
|
"github.com/oam-dev/kubevela/pkg/utils/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
type definition struct {
|
type definition struct {
|
||||||
@@ -69,7 +69,7 @@ func (d *definition) GetWebServiceRoute() *restful.WebService {
|
|||||||
Filter(d.RbacService.CheckPerm("definition", "update")).
|
Filter(d.RbacService.CheckPerm("definition", "update")).
|
||||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||||
Reads(apis.UpdateUISchemaRequest{}).
|
Reads(apis.UpdateUISchemaRequest{}).
|
||||||
Returns(200, "update successfully", utils.UISchema{}).
|
Returns(200, "update successfully", schema.UISchema{}).
|
||||||
Writes(apis.DetailDefinitionResponse{}).Do(returns200, returns500))
|
Writes(apis.DetailDefinitionResponse{}).Do(returns200, returns500))
|
||||||
|
|
||||||
ws.Route(ws.PUT("/{definitionName}/status").To(d.updateDefinitionStatus).
|
ws.Route(ws.PUT("/{definitionName}/status").To(d.updateDefinitionStatus).
|
||||||
@@ -77,7 +77,7 @@ func (d *definition) GetWebServiceRoute() *restful.WebService {
|
|||||||
Filter(d.RbacService.CheckPerm("definition", "update")).
|
Filter(d.RbacService.CheckPerm("definition", "update")).
|
||||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||||
Reads(apis.UpdateDefinitionStatusRequest{}).
|
Reads(apis.UpdateDefinitionStatusRequest{}).
|
||||||
Returns(200, "update successfully", utils.UISchema{}).
|
Returns(200, "update successfully", schema.UISchema{}).
|
||||||
Writes(apis.DetailDefinitionResponse{}).Do(returns200, returns500))
|
Writes(apis.DetailDefinitionResponse{}).Do(returns200, returns500))
|
||||||
|
|
||||||
ws.Filter(authCheckFilter)
|
ws.Filter(authCheckFilter)
|
||||||
|
|||||||
@@ -33,9 +33,9 @@ import (
|
|||||||
"github.com/oam-dev/kubevela/apis/types"
|
"github.com/oam-dev/kubevela/apis/types"
|
||||||
"github.com/oam-dev/kubevela/pkg/addon"
|
"github.com/oam-dev/kubevela/pkg/addon"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/domain/model"
|
"github.com/oam-dev/kubevela/pkg/apiserver/domain/model"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
|
||||||
"github.com/oam-dev/kubevela/pkg/cloudprovider"
|
"github.com/oam-dev/kubevela/pkg/cloudprovider"
|
||||||
"github.com/oam-dev/kubevela/pkg/config"
|
"github.com/oam-dev/kubevela/pkg/config"
|
||||||
|
"github.com/oam-dev/kubevela/pkg/utils/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -166,7 +166,7 @@ type DetailAddonResponse struct {
|
|||||||
addon.Meta
|
addon.Meta
|
||||||
|
|
||||||
APISchema *openapi3.Schema `json:"schema"`
|
APISchema *openapi3.Schema `json:"schema"`
|
||||||
UISchema utils.UISchema `json:"uiSchema"`
|
UISchema schema.UISchema `json:"uiSchema"`
|
||||||
|
|
||||||
// More details about the addon, e.g. README
|
// More details about the addon, e.g. README
|
||||||
Detail string `json:"detail,omitempty"`
|
Detail string `json:"detail,omitempty"`
|
||||||
@@ -238,7 +238,7 @@ type ConfigTemplate struct {
|
|||||||
type ConfigTemplateDetail struct {
|
type ConfigTemplateDetail struct {
|
||||||
ConfigTemplate
|
ConfigTemplate
|
||||||
APISchema *openapi3.Schema `json:"schema"`
|
APISchema *openapi3.Schema `json:"schema"`
|
||||||
UISchema utils.UISchema `json:"uiSchema"`
|
UISchema schema.UISchema `json:"uiSchema"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config define the metadata of a config
|
// Config define the metadata of a config
|
||||||
@@ -898,13 +898,13 @@ type ListDefinitionResponse struct {
|
|||||||
type DetailDefinitionResponse struct {
|
type DetailDefinitionResponse struct {
|
||||||
DefinitionBase
|
DefinitionBase
|
||||||
APISchema *openapi3.Schema `json:"schema"`
|
APISchema *openapi3.Schema `json:"schema"`
|
||||||
UISchema utils.UISchema `json:"uiSchema"`
|
UISchema schema.UISchema `json:"uiSchema"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUISchemaRequest the request body struct about updated ui schema
|
// UpdateUISchemaRequest the request body struct about updated ui schema
|
||||||
type UpdateUISchemaRequest struct {
|
type UpdateUISchemaRequest struct {
|
||||||
DefinitionType string `json:"type"`
|
DefinitionType string `json:"type"`
|
||||||
UISchema utils.UISchema `json:"uiSchema"`
|
UISchema schema.UISchema `json:"uiSchema"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateDefinitionStatusRequest the request body struct about updated definition
|
// UpdateDefinitionStatusRequest the request body struct about updated definition
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ import (
|
|||||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha1"
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha1"
|
||||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
||||||
"github.com/oam-dev/kubevela/apis/types"
|
"github.com/oam-dev/kubevela/apis/types"
|
||||||
apiutils "github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
|
||||||
"github.com/oam-dev/kubevela/pkg/appfile"
|
"github.com/oam-dev/kubevela/pkg/appfile"
|
||||||
"github.com/oam-dev/kubevela/pkg/cue/definition"
|
"github.com/oam-dev/kubevela/pkg/cue/definition"
|
||||||
"github.com/oam-dev/kubevela/pkg/oam"
|
"github.com/oam-dev/kubevela/pkg/oam"
|
||||||
@@ -59,16 +58,21 @@ type DryRun interface {
|
|||||||
|
|
||||||
// NewDryRunOption creates a dry-run option
|
// NewDryRunOption creates a dry-run option
|
||||||
func NewDryRunOption(c client.Client, cfg *rest.Config, dm discoverymapper.DiscoveryMapper, pd *packages.PackageDiscover, as []oam.Object, serverSideDryRun bool) *Option {
|
func NewDryRunOption(c client.Client, cfg *rest.Config, dm discoverymapper.DiscoveryMapper, pd *packages.PackageDiscover, as []oam.Object, serverSideDryRun bool) *Option {
|
||||||
return &Option{c, dm, pd, cfg, as, serverSideDryRun}
|
parser := appfile.NewDryRunApplicationParser(c, dm, pd, as)
|
||||||
|
return &Option{c, dm, pd, parser, parser.GenerateAppFileFromApp, cfg, as, serverSideDryRun}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GenerateAppFileFunc generate the app file model from an application
|
||||||
|
type GenerateAppFileFunc func(ctx context.Context, app *v1beta1.Application) (*appfile.Appfile, error)
|
||||||
|
|
||||||
// Option contains options to execute dry-run
|
// Option contains options to execute dry-run
|
||||||
type Option struct {
|
type Option struct {
|
||||||
Client client.Client
|
Client client.Client
|
||||||
DiscoveryMapper discoverymapper.DiscoveryMapper
|
DiscoveryMapper discoverymapper.DiscoveryMapper
|
||||||
PackageDiscover *packages.PackageDiscover
|
PackageDiscover *packages.PackageDiscover
|
||||||
|
Parser *appfile.Parser
|
||||||
cfg *rest.Config
|
GenerateAppFile GenerateAppFileFunc
|
||||||
|
cfg *rest.Config
|
||||||
// Auxiliaries are capability definitions used to parse application.
|
// Auxiliaries are capability definitions used to parse application.
|
||||||
// DryRun will use capabilities in Auxiliaries as higher priority than
|
// DryRun will use capabilities in Auxiliaries as higher priority than
|
||||||
// getting one from cluster.
|
// getting one from cluster.
|
||||||
@@ -137,12 +141,10 @@ func (d *Option) ValidateApp(ctx context.Context, filename string) error {
|
|||||||
// resources but not persist them into cluster.
|
// resources but not persist them into cluster.
|
||||||
func (d *Option) ExecuteDryRun(ctx context.Context, application *v1beta1.Application) ([]*types.ComponentManifest, []*unstructured.Unstructured, error) {
|
func (d *Option) ExecuteDryRun(ctx context.Context, application *v1beta1.Application) ([]*types.ComponentManifest, []*unstructured.Unstructured, error) {
|
||||||
app := application.DeepCopy()
|
app := application.DeepCopy()
|
||||||
parser := appfile.NewDryRunApplicationParser(d.Client, d.DiscoveryMapper, d.PackageDiscover, d.Auxiliaries)
|
|
||||||
if app.Namespace != "" {
|
if app.Namespace != "" {
|
||||||
ctx = oamutil.SetNamespaceInCtx(ctx, app.Namespace)
|
ctx = oamutil.SetNamespaceInCtx(ctx, app.Namespace)
|
||||||
}
|
}
|
||||||
generateCtx := apiutils.WithProject(ctx, "")
|
appFile, err := d.GenerateAppFile(ctx, app)
|
||||||
appFile, err := parser.GenerateAppFileFromApp(generateCtx, app)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, errors.WithMessage(err, "cannot generate appFile from application")
|
return nil, nil, errors.WithMessage(err, "cannot generate appFile from application")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,13 +42,12 @@ import (
|
|||||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha1"
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha1"
|
||||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
||||||
"github.com/oam-dev/kubevela/apis/types"
|
"github.com/oam-dev/kubevela/apis/types"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/domain/model"
|
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
|
||||||
icontext "github.com/oam-dev/kubevela/pkg/config/context"
|
icontext "github.com/oam-dev/kubevela/pkg/config/context"
|
||||||
"github.com/oam-dev/kubevela/pkg/config/writer"
|
"github.com/oam-dev/kubevela/pkg/config/writer"
|
||||||
"github.com/oam-dev/kubevela/pkg/cue"
|
"github.com/oam-dev/kubevela/pkg/cue"
|
||||||
"github.com/oam-dev/kubevela/pkg/cue/script"
|
"github.com/oam-dev/kubevela/pkg/cue/script"
|
||||||
"github.com/oam-dev/kubevela/pkg/oam"
|
"github.com/oam-dev/kubevela/pkg/oam"
|
||||||
|
"github.com/oam-dev/kubevela/pkg/oam/util"
|
||||||
"github.com/oam-dev/kubevela/pkg/utils/apply"
|
"github.com/oam-dev/kubevela/pkg/utils/apply"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -787,13 +786,13 @@ func (k *kubeConfigFactory) CreateOrUpdateDistribution(ctx context.Context, ns,
|
|||||||
Name: name,
|
Name: name,
|
||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
model.LabelSourceOfTruth: model.FromInner,
|
types.LabelSourceOfTruth: types.FromInner,
|
||||||
// This label will override the secret label, then change the catalog of the distributed secrets.
|
// This label will override the secret label, then change the catalog of the distributed secrets.
|
||||||
types.LabelConfigCatalog: types.CatalogConfigDistribution,
|
types.LabelConfigCatalog: types.CatalogConfigDistribution,
|
||||||
},
|
},
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
types.AnnotationConfigDistributionSpec: string(reqByte),
|
types.AnnotationConfigDistributionSpec: string(reqByte),
|
||||||
oam.AnnotationPublishVersion: utils.GenerateVersion("config"),
|
oam.AnnotationPublishVersion: util.GenerateVersion("config"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Spec: v1beta1.ApplicationSpec{
|
Spec: v1beta1.ApplicationSpec{
|
||||||
@@ -821,7 +820,7 @@ func (k *kubeConfigFactory) CreateOrUpdateDistribution(ctx context.Context, ns,
|
|||||||
func (k *kubeConfigFactory) ListDistributions(ctx context.Context, ns string) ([]*Distribution, error) {
|
func (k *kubeConfigFactory) ListDistributions(ctx context.Context, ns string) ([]*Distribution, error) {
|
||||||
var apps v1beta1.ApplicationList
|
var apps v1beta1.ApplicationList
|
||||||
if err := k.cli.List(ctx, &apps, client.MatchingLabels{
|
if err := k.cli.List(ctx, &apps, client.MatchingLabels{
|
||||||
model.LabelSourceOfTruth: model.FromInner,
|
types.LabelSourceOfTruth: types.FromInner,
|
||||||
types.LabelConfigCatalog: types.CatalogConfigDistribution,
|
types.LabelConfigCatalog: types.CatalogConfigDistribution,
|
||||||
}, client.InNamespace(ns)); err != nil {
|
}, client.InNamespace(ns)); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
34
pkg/oam/util/version.go
Normal file
34
pkg/oam/util/version.go
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2021 The KubeVela Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"cuelang.org/go/pkg/strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GenerateVersion Generate version numbers by time
|
||||||
|
func GenerateVersion(pre string) string {
|
||||||
|
timeStr := time.Now().Format("20060102150405.000")
|
||||||
|
timeStr = strings.Replace(timeStr, ".", "", 1)
|
||||||
|
if pre != "" {
|
||||||
|
return fmt.Sprintf("%s-%s", pre, timeStr)
|
||||||
|
}
|
||||||
|
return timeStr
|
||||||
|
}
|
||||||
35
pkg/oam/util/version_test.go
Normal file
35
pkg/oam/util/version_test.go
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2021 The KubeVela Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = Describe("Test version utils", func() {
|
||||||
|
It("Test New version function", func() {
|
||||||
|
s := GenerateVersion("")
|
||||||
|
Expect(s).ShouldNot(BeNil())
|
||||||
|
|
||||||
|
s2 := GenerateVersion("pre")
|
||||||
|
Expect(cmp.Diff(strings.HasPrefix(s2, "pre-"), true)).ShouldNot(BeNil())
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -29,7 +29,6 @@ import (
|
|||||||
|
|
||||||
apicommon "github.com/oam-dev/kubevela/apis/core.oam.dev/common"
|
apicommon "github.com/oam-dev/kubevela/apis/core.oam.dev/common"
|
||||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
||||||
apiutils "github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
|
||||||
"github.com/oam-dev/kubevela/pkg/component"
|
"github.com/oam-dev/kubevela/pkg/component"
|
||||||
"github.com/oam-dev/kubevela/pkg/controller/core.oam.dev/v1alpha2/application"
|
"github.com/oam-dev/kubevela/pkg/controller/core.oam.dev/v1alpha2/application"
|
||||||
"github.com/oam-dev/kubevela/pkg/controller/utils"
|
"github.com/oam-dev/kubevela/pkg/controller/utils"
|
||||||
@@ -45,10 +44,16 @@ var ErrPublishVersionNotChange = errors.Errorf("the PublishVersion is not change
|
|||||||
// ErrRevisionNotChange -
|
// ErrRevisionNotChange -
|
||||||
var ErrRevisionNotChange = errors.Errorf("the revision is not changed")
|
var ErrRevisionNotChange = errors.Errorf("the revision is not changed")
|
||||||
|
|
||||||
// RollbackApplicationWithRevision make the exist application rollback to specified revision.
|
// RevisionContextKey if this key is exit in ctx, we should use it preferentially
|
||||||
func RollbackApplicationWithRevision(ctx context.Context, cli client.Client, appName, appNamespace, revisionName, publishVersion string) (*v1beta1.ApplicationRevision, *v1beta1.Application, error) {
|
var RevisionContextKey = "revision-context-key"
|
||||||
|
|
||||||
revisionCtx := apiutils.WithProject(ctx, "")
|
// RollbackApplicationWithRevision make the exist application rollback to specified revision.
|
||||||
|
// revisionCtx the context used to manage the application revision.
|
||||||
|
func RollbackApplicationWithRevision(ctx context.Context, cli client.Client, appName, appNamespace, revisionName, publishVersion string) (*v1beta1.ApplicationRevision, *v1beta1.Application, error) {
|
||||||
|
revisionCtx, ok := ctx.Value(&RevisionContextKey).(context.Context)
|
||||||
|
if !ok {
|
||||||
|
revisionCtx = ctx
|
||||||
|
}
|
||||||
// check revision
|
// check revision
|
||||||
revs, err := application.GetSortedAppRevisions(revisionCtx, cli, appName, appNamespace)
|
revs, err := application.GetSortedAppRevisions(revisionCtx, cli, appName, appNamespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
102
pkg/utils/cache.go
Normal file
102
pkg/utils/cache.go
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2021 The KubeVela Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// memoryCache memory cache, support time expired
|
||||||
|
type memoryCache struct {
|
||||||
|
data interface{}
|
||||||
|
cacheDuration time.Duration
|
||||||
|
startTime time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMemoryCache new memory cache instance
|
||||||
|
func newMemoryCache(data interface{}, cacheDuration time.Duration) *memoryCache {
|
||||||
|
mc := &memoryCache{data: data, cacheDuration: cacheDuration, startTime: time.Now()}
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsExpired whether the cache data expires
|
||||||
|
func (m *memoryCache) IsExpired() bool {
|
||||||
|
if m.cacheDuration <= 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return time.Now().After(m.startTime.Add(m.cacheDuration))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetData get cache data
|
||||||
|
func (m *memoryCache) GetData() interface{} {
|
||||||
|
return m.data
|
||||||
|
}
|
||||||
|
|
||||||
|
// MemoryCacheStore a sample memory cache instance, if data set cache duration, will auto clear after timeout.
|
||||||
|
// But, Expired cleanup is not necessarily accurate, it has a 3-second window.
|
||||||
|
type MemoryCacheStore struct {
|
||||||
|
store sync.Map
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMemoryCacheStore memory cache store
|
||||||
|
func NewMemoryCacheStore(ctx context.Context) *MemoryCacheStore {
|
||||||
|
mcs := &MemoryCacheStore{
|
||||||
|
store: sync.Map{},
|
||||||
|
}
|
||||||
|
go mcs.run(ctx)
|
||||||
|
return mcs
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MemoryCacheStore) run(ctx context.Context) {
|
||||||
|
ticker := time.NewTicker(time.Second * 3)
|
||||||
|
defer ticker.Stop()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
case <-ticker.C:
|
||||||
|
m.store.Range(func(key, value interface{}) bool {
|
||||||
|
if value.(*memoryCache).IsExpired() {
|
||||||
|
m.store.Delete(key)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Put cache data, if cacheDuration>0, store will clear data after timeout.
|
||||||
|
func (m *MemoryCacheStore) Put(key, value interface{}, cacheDuration time.Duration) {
|
||||||
|
mc := newMemoryCache(value, cacheDuration)
|
||||||
|
m.store.Store(key, mc)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete cache data from store
|
||||||
|
func (m *MemoryCacheStore) Delete(key interface{}) {
|
||||||
|
m.store.Delete(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get cache data from store, if not exist or timeout, will return nil
|
||||||
|
func (m *MemoryCacheStore) Get(key interface{}) (value interface{}) {
|
||||||
|
mc, ok := m.store.Load(key)
|
||||||
|
if ok && !mc.(*memoryCache).IsExpired() {
|
||||||
|
return mc.(*memoryCache).GetData()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
78
pkg/utils/cache_test.go
Normal file
78
pkg/utils/cache_test.go
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2021 The KubeVela Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = Describe("Test cache utils", func() {
|
||||||
|
It("should return false for IsExpired()", func() {
|
||||||
|
c := newMemoryCache("test", 10*time.Hour)
|
||||||
|
Expect(c.IsExpired()).Should(BeFalse())
|
||||||
|
})
|
||||||
|
|
||||||
|
It("test cache store", func() {
|
||||||
|
store := NewMemoryCacheStore(context.TODO())
|
||||||
|
store.Put("test", "test data", time.Second*2)
|
||||||
|
store.Put("test2", "test data", 0)
|
||||||
|
store.Put("test3", "test data", -1)
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
|
Expect(store.Get("test")).Should(BeNil())
|
||||||
|
Expect(store.Get("test2")).Should(Equal("test data"))
|
||||||
|
Expect(store.Get("test3")).Should(Equal("test data"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("test cache store delete key", func() {
|
||||||
|
store := NewMemoryCacheStore(context.TODO())
|
||||||
|
store.Put("test", "test data", time.Minute*2)
|
||||||
|
store.Delete("test")
|
||||||
|
Expect(store.Get("test")).Should(BeNil())
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
var store *MemoryCacheStore
|
||||||
|
|
||||||
|
// BenchmarkWrite
|
||||||
|
func BenchmarkWrite(b *testing.B) {
|
||||||
|
store = NewMemoryCacheStore(context.TODO())
|
||||||
|
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
store.Put(fmt.Sprintf("%d", i), i, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BenchmarkRead
|
||||||
|
func BenchmarkRead(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
store.Get(fmt.Sprintf("%d", i))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BenchmarkRW
|
||||||
|
func BenchmarkRW(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
store.Put(fmt.Sprintf("%d", i), i, 1)
|
||||||
|
store.Get(fmt.Sprintf("%d", i))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -49,7 +49,6 @@ import (
|
|||||||
k8scmdutil "k8s.io/kubectl/pkg/cmd/util"
|
k8scmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
|
|
||||||
utils2 "github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
|
||||||
"github.com/oam-dev/kubevela/pkg/utils"
|
"github.com/oam-dev/kubevela/pkg/utils"
|
||||||
"github.com/oam-dev/kubevela/pkg/utils/common"
|
"github.com/oam-dev/kubevela/pkg/utils/common"
|
||||||
cmdutil "github.com/oam-dev/kubevela/pkg/utils/util"
|
cmdutil "github.com/oam-dev/kubevela/pkg/utils/util"
|
||||||
@@ -68,7 +67,7 @@ type ChartValues struct {
|
|||||||
|
|
||||||
// Helper provides helper functions for common Helm operations
|
// Helper provides helper functions for common Helm operations
|
||||||
type Helper struct {
|
type Helper struct {
|
||||||
cache *utils2.MemoryCacheStore
|
cache *utils.MemoryCacheStore
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHelper creates a Helper
|
// NewHelper creates a Helper
|
||||||
@@ -79,7 +78,7 @@ func NewHelper() *Helper {
|
|||||||
// NewHelperWithCache creates a Helper with cache usually used by apiserver
|
// NewHelperWithCache creates a Helper with cache usually used by apiserver
|
||||||
func NewHelperWithCache() *Helper {
|
func NewHelperWithCache() *Helper {
|
||||||
return &Helper{
|
return &Helper{
|
||||||
cache: utils2.NewMemoryCacheStore(context.Background()),
|
cache: utils.NewMemoryCacheStore(context.Background()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,11 +14,13 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package utils
|
package schema
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/oam-dev/kubevela/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UISchema ui schema
|
// UISchema ui schema
|
||||||
@@ -85,7 +87,7 @@ func (c Condition) Validate() error {
|
|||||||
if c.Action != "enable" && c.Action != "disable" && c.Action != "" {
|
if c.Action != "enable" && c.Action != "disable" && c.Action != "" {
|
||||||
return fmt.Errorf("the action of the condition only supports enable, disable or leave it empty")
|
return fmt.Errorf("the action of the condition only supports enable, disable or leave it empty")
|
||||||
}
|
}
|
||||||
if c.Op != "" && !StringsContain([]string{"==", "!=", "in"}, c.Op) {
|
if c.Op != "" && !utils.StringsContain([]string{"==", "!=", "in"}, c.Op) {
|
||||||
return fmt.Errorf("the op of the condition must be `==` 、`!=` and `in`")
|
return fmt.Errorf("the op of the condition must be `==` 、`!=` and `in`")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -180,13 +182,3 @@ func RenderLabel(source interface{}) string {
|
|||||||
return FirstUpper(fmt.Sprintf("%v", v))
|
return FirstUpper(fmt.Sprintf("%v", v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// StringsContain strings contain
|
|
||||||
func StringsContain(items []string, source string) bool {
|
|
||||||
for _, item := range items {
|
|
||||||
if item == source {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package utils
|
package schema
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
@@ -41,7 +41,6 @@ import (
|
|||||||
"github.com/kubevela/workflow/pkg/types"
|
"github.com/kubevela/workflow/pkg/types"
|
||||||
|
|
||||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
|
||||||
"github.com/oam-dev/kubevela/pkg/multicluster"
|
"github.com/oam-dev/kubevela/pkg/multicluster"
|
||||||
querytypes "github.com/oam-dev/kubevela/pkg/velaql/providers/query/types"
|
querytypes "github.com/oam-dev/kubevela/pkg/velaql/providers/query/types"
|
||||||
)
|
)
|
||||||
@@ -230,7 +229,7 @@ func (h *provider) CollectLogsInPod(ctx monitorContext.Context, wfCtx wfContext.
|
|||||||
if err = val.UnmarshalTo(opts); err != nil {
|
if err = val.UnmarshalTo(opts); err != nil {
|
||||||
return errors.Wrapf(err, "invalid log options content")
|
return errors.Wrapf(err, "invalid log options content")
|
||||||
}
|
}
|
||||||
cliCtx := utils.ContextWithUserInfo(multicluster.ContextWithClusterName(ctx, cluster))
|
cliCtx := multicluster.ContextWithClusterName(ctx, cluster)
|
||||||
h.cfg.Wrap(pkgmulticluster.NewTransportWrapper())
|
h.cfg.Wrap(pkgmulticluster.NewTransportWrapper())
|
||||||
clientSet, err := kubernetes.NewForConfig(h.cfg)
|
clientSet, err := kubernetes.NewForConfig(h.cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ import (
|
|||||||
|
|
||||||
"github.com/kubevela/workflow/pkg/cue/packages"
|
"github.com/kubevela/workflow/pkg/cue/packages"
|
||||||
|
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/clients"
|
|
||||||
"github.com/oam-dev/kubevela/pkg/oam/discoverymapper"
|
"github.com/oam-dev/kubevela/pkg/oam/discoverymapper"
|
||||||
"github.com/oam-dev/kubevela/pkg/utils/common"
|
"github.com/oam-dev/kubevela/pkg/utils/common"
|
||||||
)
|
)
|
||||||
@@ -69,7 +68,6 @@ var _ = BeforeSuite(func(done Done) {
|
|||||||
Expect(err).Should(BeNil())
|
Expect(err).Should(BeNil())
|
||||||
Expect(k8sClient).ToNot(BeNil())
|
Expect(k8sClient).ToNot(BeNil())
|
||||||
By("new kube client success")
|
By("new kube client success")
|
||||||
clients.SetKubeClient(k8sClient)
|
|
||||||
|
|
||||||
dm, err := discoverymapper.New(cfg)
|
dm, err := discoverymapper.New(cfg)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ import (
|
|||||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
||||||
"github.com/oam-dev/kubevela/apis/types"
|
"github.com/oam-dev/kubevela/apis/types"
|
||||||
pkgaddon "github.com/oam-dev/kubevela/pkg/addon"
|
pkgaddon "github.com/oam-dev/kubevela/pkg/addon"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/domain/service"
|
|
||||||
"github.com/oam-dev/kubevela/pkg/oam"
|
"github.com/oam-dev/kubevela/pkg/oam"
|
||||||
addonutil "github.com/oam-dev/kubevela/pkg/utils/addon"
|
addonutil "github.com/oam-dev/kubevela/pkg/utils/addon"
|
||||||
"github.com/oam-dev/kubevela/pkg/utils/apply"
|
"github.com/oam-dev/kubevela/pkg/utils/apply"
|
||||||
@@ -231,18 +230,6 @@ func AdditionalEndpointPrinter(ctx context.Context, c common.Args, k8sClient cli
|
|||||||
fmt.Println("Get application endpoints error:", err)
|
fmt.Println("Get application endpoints error:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if name == "velaux" {
|
|
||||||
if !isUpgrade {
|
|
||||||
fmt.Printf("\nInitialized admin username and password: admin / %s \n\n", service.InitAdminPassword)
|
|
||||||
}
|
|
||||||
fmt.Println(`To open the dashboard directly by port-forward:`)
|
|
||||||
fmt.Println()
|
|
||||||
fmt.Println(` vela port-forward -n vela-system addon-velaux 9082:80`)
|
|
||||||
fmt.Println()
|
|
||||||
fmt.Println(`Select "local | velaux | velaux" from the prompt.`)
|
|
||||||
fmt.Println()
|
|
||||||
fmt.Println(`Please refer to https://kubevela.io/docs/reference/addons/velaux for more VelaUX addon installation and visiting method.`)
|
|
||||||
}
|
|
||||||
if len(info) > 0 {
|
if len(info) > 0 {
|
||||||
fmt.Println(info)
|
fmt.Println(info)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ import (
|
|||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
|
|
||||||
"github.com/oam-dev/kubevela/apis/types"
|
"github.com/oam-dev/kubevela/apis/types"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
|
||||||
"github.com/oam-dev/kubevela/pkg/utils/common"
|
"github.com/oam-dev/kubevela/pkg/utils/common"
|
||||||
|
"github.com/oam-dev/kubevela/pkg/utils/schema"
|
||||||
"github.com/oam-dev/kubevela/pkg/utils/util"
|
"github.com/oam-dev/kubevela/pkg/utils/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ func applyUISchemaFile(client client.Client, uischemaFile string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func addDefinitionUISchema(ctx context.Context, client client.Client, name, defType, configRaw string) error {
|
func addDefinitionUISchema(ctx context.Context, client client.Client, name, defType, configRaw string) error {
|
||||||
var uiParameters []*utils.UIParameter
|
var uiParameters []*schema.UIParameter
|
||||||
err := yaml.Unmarshal([]byte(configRaw), &uiParameters)
|
err := yaml.Unmarshal([]byte(configRaw), &uiParameters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ import (
|
|||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
|
||||||
apisv1 "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
apisv1 "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
||||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils"
|
|
||||||
"github.com/oam-dev/kubevela/pkg/oam/util"
|
"github.com/oam-dev/kubevela/pkg/oam/util"
|
||||||
"github.com/oam-dev/kubevela/pkg/utils/common"
|
"github.com/oam-dev/kubevela/pkg/utils/common"
|
||||||
|
"github.com/oam-dev/kubevela/pkg/utils/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("Test definitions rest api", func() {
|
var _ = Describe("Test definitions rest api", func() {
|
||||||
@@ -72,7 +72,7 @@ var _ = Describe("Test definitions rest api", func() {
|
|||||||
defer GinkgoRecover()
|
defer GinkgoRecover()
|
||||||
req := apisv1.UpdateUISchemaRequest{
|
req := apisv1.UpdateUISchemaRequest{
|
||||||
DefinitionType: "component",
|
DefinitionType: "component",
|
||||||
UISchema: utils.UISchema{
|
UISchema: schema.UISchema{
|
||||||
{
|
{
|
||||||
JSONKey: "image",
|
JSONKey: "image",
|
||||||
UIType: "ImageInput",
|
UIType: "ImageInput",
|
||||||
@@ -80,7 +80,7 @@ var _ = Describe("Test definitions rest api", func() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
res := put("/definitions/webservice/uischema", req)
|
res := put("/definitions/webservice/uischema", req)
|
||||||
var schema utils.UISchema
|
var schema schema.UISchema
|
||||||
Expect(decodeResponseBody(res, &schema)).Should(Succeed())
|
Expect(decodeResponseBody(res, &schema)).Should(Succeed())
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -88,11 +88,11 @@ var _ = Describe("Test definitions rest api", func() {
|
|||||||
defer GinkgoRecover()
|
defer GinkgoRecover()
|
||||||
req := apisv1.UpdateUISchemaRequest{
|
req := apisv1.UpdateUISchemaRequest{
|
||||||
DefinitionType: "component",
|
DefinitionType: "component",
|
||||||
UISchema: utils.UISchema{
|
UISchema: schema.UISchema{
|
||||||
{
|
{
|
||||||
JSONKey: "image",
|
JSONKey: "image",
|
||||||
UIType: "ImageInput",
|
UIType: "ImageInput",
|
||||||
Conditions: []utils.Condition{
|
Conditions: []schema.Condition{
|
||||||
{
|
{
|
||||||
JSONKey: "",
|
JSONKey: "",
|
||||||
},
|
},
|
||||||
@@ -105,11 +105,11 @@ var _ = Describe("Test definitions rest api", func() {
|
|||||||
|
|
||||||
req2 := apisv1.UpdateUISchemaRequest{
|
req2 := apisv1.UpdateUISchemaRequest{
|
||||||
DefinitionType: "component",
|
DefinitionType: "component",
|
||||||
UISchema: utils.UISchema{
|
UISchema: schema.UISchema{
|
||||||
{
|
{
|
||||||
JSONKey: "image",
|
JSONKey: "image",
|
||||||
UIType: "ImageInput",
|
UIType: "ImageInput",
|
||||||
Conditions: []utils.Condition{
|
Conditions: []schema.Condition{
|
||||||
{
|
{
|
||||||
JSONKey: "secretName",
|
JSONKey: "secretName",
|
||||||
Value: "",
|
Value: "",
|
||||||
|
|||||||
Reference in New Issue
Block a user