Compare commits

..

6 Commits

Author SHA1 Message Date
github-actions[bot]
58ca3a820d fix: add supported but missing provider (#4651)
Signed-off-by: Yuedong Wu <57584831+lunarwhite@users.noreply.github.com>
(cherry picked from commit fa96c917a8)

Co-authored-by: Yuedong Wu <57584831+lunarwhite@users.noreply.github.com>
2022-08-24 09:29:04 +08:00
Tianxin Dong
63b31be38e Fix: fix signedKey using platform id (#4654)
Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com>

Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com>
2022-08-24 09:28:07 +08:00
Tianxin Dong
06f10d4026 Fix: optimize workflow debug cmd (#4649)
Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com>

Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com>
2022-08-23 17:41:33 +08:00
Somefive
7a2b18b78a Fix: open basic lit fails lookup path to KubeVela 1.5 (#4625)
* Fix: open basic lit fails lookup path

Signed-off-by: Somefive <yd219913@alibaba-inc.com>

* Fix: test

Signed-off-by: Somefive <yd219913@alibaba-inc.com>

Signed-off-by: Somefive <yd219913@alibaba-inc.com>
2022-08-18 10:29:05 +08:00
github-actions[bot]
52ee87df16 [Backport release-1.5] Fix: up command example (#4627)
* Fix: up command example

Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
(cherry picked from commit 3ab6e8d80c)

* typo

Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
(cherry picked from commit 5e232b1caa)

Co-authored-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
2022-08-17 13:50:23 +08:00
github-actions[bot]
3177d26fc4 Fix: skipGC remove labels for multi-cluster resource not use correct ctx (#4622)
Signed-off-by: Somefive <yd219913@alibaba-inc.com>
(cherry picked from commit c59755b6a4)

Co-authored-by: Somefive <yd219913@alibaba-inc.com>
2022-08-15 11:09:32 +08:00
13 changed files with 122 additions and 21 deletions

View File

@@ -32,6 +32,7 @@ const (
// SystemInfo systemInfo model
type SystemInfo struct {
BaseModel
SignedKey string `json:"signedKey"`
InstallID string `json:"installID"`
EnableCollection bool `json:"enableCollection"`
StatisticInfo StatisticInfo `json:"statisticInfo,omitempty"`

View File

@@ -58,7 +58,8 @@ const (
GrantTypeRefresh = "refresh"
)
var signedKey = ""
// signedKey is the signed key of JWT
var signedKey string
// AuthenticationService is the service of authentication
type AuthenticationService interface {

View File

@@ -63,6 +63,7 @@ func (u systemInfoServiceImpl) Get(ctx context.Context) (*model.SystemInfo, erro
}
return info, nil
}
info.SignedKey = rand.String(32)
installID := rand.String(16)
info.InstallID = installID
info.EnableCollection = true
@@ -161,7 +162,7 @@ func (u systemInfoServiceImpl) Init(ctx context.Context) error {
if err != nil {
return err
}
signedKey = info.InstallID
signedKey = info.SignedKey
_, err = initDexConfig(ctx, u.KubeClient, "http://velaux.com")
return err
}

View File

@@ -22,6 +22,7 @@ import (
"cuelang.org/go/cue"
"cuelang.org/go/cue/ast"
"cuelang.org/go/cue/format"
"cuelang.org/go/cue/parser"
jsonpatch "github.com/evanphx/json-patch"
"github.com/pkg/errors"
@@ -361,7 +362,7 @@ func jsonMergePatch(base cue.Value, patch cue.Value) (string, error) {
if err != nil {
return "", errors.Wrapf(err, "failed to merge base value and patch value by JsonMergePatch")
}
output, err := OpenBaiscLit(string(merged))
output, err := openJSON(string(merged))
if err != nil {
return "", errors.Wrapf(err, "failed to parse open basic lit for merged result")
}
@@ -386,9 +387,47 @@ func jsonPatch(base cue.Value, patch cue.Value) (string, error) {
if err != nil {
return "", errors.Wrapf(err, "failed to apply json patch")
}
output, err := OpenBaiscLit(string(merged))
output, err := openJSON(string(merged))
if err != nil {
return "", errors.Wrapf(err, "failed to parse open basic lit for merged result")
}
return output, nil
}
func isEllipsis(elt ast.Node) bool {
_, ok := elt.(*ast.Ellipsis)
return ok
}
func openJSON(data string) (string, error) {
f, err := parser.ParseFile("-", data, parser.ParseComments)
if err != nil {
return "", err
}
ast.Walk(f, func(node ast.Node) bool {
field, ok := node.(*ast.Field)
if ok {
v := field.Value
switch lit := v.(type) {
case *ast.StructLit:
if len(lit.Elts) == 0 || !isEllipsis(lit.Elts[len(lit.Elts)-1]) {
lit.Elts = append(lit.Elts, &ast.Ellipsis{})
}
case *ast.ListLit:
if len(lit.Elts) == 0 || !isEllipsis(lit.Elts[len(lit.Elts)-1]) {
lit.Elts = append(lit.Elts, &ast.Ellipsis{})
}
}
}
return true
}, nil)
if len(f.Decls) > 0 {
if emb, ok := f.Decls[0].(*ast.EmbedDecl); ok {
if s, _ok := emb.Expr.(*ast.StructLit); _ok {
f.Decls = s.Elts
}
}
}
b, err := format.Node(f)
return string(b), err
}

View File

@@ -182,7 +182,8 @@ func peelCloseExpr(node ast.Node) ast.Node {
func lookField(node ast.Node, key string) ast.Node {
if field, ok := node.(*ast.Field); ok {
if labelStr(field.Label) == key {
// Note: the trim here has side effect: "\(v)" will be trimmed to \(v), only used for comparing fields
if strings.Trim(labelStr(field.Label), `"`) == strings.Trim(key, `"`) {
return field.Value
}
}

View File

@@ -352,7 +352,7 @@ func (h *gcHandler) deleteManagedResource(ctx context.Context, mr v1beta1.Manage
delete(labels, oam.LabelAppNamespace)
entry.obj.SetLabels(labels)
}
return errors.Wrapf(h.Client.Update(ctx, entry.obj), "failed to remove owner labels for resource while skipping gc")
return errors.Wrapf(h.Client.Update(_ctx, entry.obj), "failed to remove owner labels for resource while skipping gc")
}
if err := h.Client.Delete(_ctx, entry.obj); err != nil && !kerrors.IsNotFound(err) {
return errors.Wrapf(err, "failed to delete resource %s", mr.ResourceKey())

View File

@@ -118,13 +118,20 @@ func (d *debugOpts) debugApplication(ctx context.Context, c common.Args, app *v1
}
// debug workflow steps
rawValue, err := d.getDebugRawValue(ctx, cli, pd, app)
rawValue, data, err := d.getDebugRawValue(ctx, cli, pd, app)
if err != nil {
if data != "" {
ioStreams.Info(color.RedString("%s%s", emojiFail, err.Error()))
ioStreams.Info(color.GreenString("Original Data in Debug:\n"), data)
return nil
}
return err
}
if err := d.handleCueSteps(rawValue, ioStreams); err != nil {
return err
ioStreams.Info(color.RedString("%s%s", emojiFail, err.Error()))
ioStreams.Info(color.GreenString("Original Data in Debug:\n"), data)
return nil
}
} else {
// dry run components
@@ -252,20 +259,20 @@ func unwrapStepName(step string) string {
return step
}
func (d *debugOpts) getDebugRawValue(ctx context.Context, cli client.Client, pd *packages.PackageDiscover, app *v1beta1.Application) (*value.Value, error) {
func (d *debugOpts) getDebugRawValue(ctx context.Context, cli client.Client, pd *packages.PackageDiscover, app *v1beta1.Application) (*value.Value, string, error) {
debugCM := &corev1.ConfigMap{}
if err := cli.Get(ctx, client.ObjectKey{Name: debug.GenerateContextName(app.Name, d.step), Namespace: app.Namespace}, debugCM); err != nil {
return nil, fmt.Errorf("failed to get debug configmap, please make sure your application have the debug policy, you can add the debug policy by using `vela up -f <app.yaml> --debug`: %w", err)
return nil, "", fmt.Errorf("failed to get debug configmap, please make sure your application have the debug policy, you can add the debug policy by using `vela up -f <app.yaml> --debug`: %w", err)
}
if debugCM.Data == nil || debugCM.Data["debug"] == "" {
return nil, fmt.Errorf("debug configmap is empty")
return nil, "", fmt.Errorf("debug configmap is empty")
}
v, err := value.NewValue(debugCM.Data["debug"], pd, "")
if err != nil {
return nil, fmt.Errorf("failed to parse debug configmap: %w", err)
return nil, debugCM.Data["debug"], fmt.Errorf("failed to parse debug configmap: %w", err)
}
return v, nil
return v, debugCM.Data["debug"], nil
}
func (d *debugOpts) handleCueSteps(v *value.Value, ioStreams cmdutil.IOStreams) error {

View File

@@ -93,9 +93,7 @@ func TestDebugApplicationWithWorkflow(t *testing.T) {
"debug": "error",
},
},
step: "test-wf1",
focus: "test",
expectedErr: "failed to parse debug configmap",
step: "test-wf1",
},
"success": {
app: &v1beta1.Application{

View File

@@ -289,7 +289,7 @@ func NewDefinitionInitCommand(c common.Args) *cobra.Command {
cmd.Flags().StringP(FlagTemplateYAML, "f", "", "Specify the template yaml file that definition will use to build the schema. If empty, a default template for the given definition type will be used.")
cmd.Flags().StringP(FlagOutput, "o", "", "Specify the output path of the generated definition. If empty, the definition will be printed in the console.")
cmd.Flags().BoolP(FlagInteractive, "i", false, "Specify whether use interactive process to help generate definitions.")
cmd.Flags().StringP(FlagProvider, "p", "", "Specify which provider the cloud resource definition belongs to. Only `alibaba`, `aws`, `azure` are supported.")
cmd.Flags().StringP(FlagProvider, "p", "", "Specify which provider the cloud resource definition belongs to. Only `alibaba`, `aws`, `azure`, `gcp`, `baidu`, `tencent`, `elastic`, `ucloud`, `vsphere` are supported.")
cmd.Flags().StringP(FlagGit, "", "", "Specify which git repository the configuration(HCL) is stored in. Valid when --provider/-p is set.")
cmd.Flags().StringP(FlagLocal, "", "", "Specify the local path of the configuration(HCL) file. Valid when --provider/-p is set.")
cmd.Flags().StringP(FlagPath, "", "", "Specify which path the configuration(HCL) is stored in the Git repository. Valid when --git is set.")
@@ -302,7 +302,7 @@ func generateTerraformTypedComponentDefinition(cmd *cobra.Command, name, kind, p
}
switch provider {
case "aws", "azure", "alibaba", "tencent", "gcp", "baidu", "elastic", "ucloud":
case "aws", "azure", "alibaba", "tencent", "gcp", "baidu", "elastic", "ucloud", "vsphere":
var terraform *commontype.Terraform
git, err := cmd.Flags().GetString(FlagGit)
@@ -378,7 +378,7 @@ func generateTerraformTypedComponentDefinition(cmd *cobra.Command, name, kind, p
}
return out.String(), nil
default:
return "", errors.Errorf("Provider `%s` is not supported. Only `alibaba`, `aws`, `azure`, `gcp`, `baidu`, `tencent`, `elastic`, `ucloud` are supported.", provider)
return "", errors.Errorf("Provider `%s` is not supported. Only `alibaba`, `aws`, `azure`, `gcp`, `baidu`, `tencent`, `elastic`, `ucloud`, `vsphere` are supported.", provider)
}
}

View File

@@ -213,7 +213,7 @@ var (
Apply Kubernetes objects in clusters
Apply Kubernetes objects in multiple clusters. Use --clusters to specify which clusters to
apply. If -n/--namespace is used, the original object namespace will be overrode.
apply. If -n/--namespace is used, the original object namespace will be overridden.
You can use -f/--file to specify the object file/folder to apply. Multiple file inputs are allowed.
Directory input and web url input is supported as well.

View File

@@ -268,7 +268,7 @@ var (
vela up example-app -n example-ns --publish-version beta --revision example-app-v2
# Deploy an application from stdin
cat <<EOF | vela up vela up -f -
cat <<EOF | vela up -f -
... <app.yaml here> ...
EOF
`))

View File

@@ -659,5 +659,23 @@ var _ = Describe("Test multicluster scenario", func() {
g.Expect(k8sClient.Get(hubCtx, types.NamespacedName{Namespace: testNamespace, Name: "another"}, &corev1.ConfigMap{})).Should(Satisfy(kerrors.IsNotFound))
})
})
It("Test Application with env in webservice and labels & storage trait", func() {
bs, err := ioutil.ReadFile("./testdata/app/app-with-env-labels-storage.yaml")
Expect(err).Should(Succeed())
app := &v1beta1.Application{}
Expect(yaml.Unmarshal(bs, app)).Should(Succeed())
app.SetNamespace(namespace)
Expect(k8sClient.Create(hubCtx, app)).Should(Succeed())
deploy := &appsv1.Deployment{}
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(hubCtx, types.NamespacedName{Namespace: namespace, Name: "test"}, deploy)).Should(Succeed())
}, 15*time.Second).Should(Succeed())
Expect(deploy.GetLabels()["key"]).Should(Equal("val"))
Expect(len(deploy.Spec.Template.Spec.Containers[0].Env)).Should(Equal(1))
Expect(deploy.Spec.Template.Spec.Containers[0].Env[0].Name).Should(Equal("testKey"))
Expect(deploy.Spec.Template.Spec.Containers[0].Env[0].Value).Should(Equal("testValue"))
Expect(len(deploy.Spec.Template.Spec.Volumes)).Should(Equal(1))
})
})
})

View File

@@ -0,0 +1,35 @@
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: test
spec:
components:
- name: test
properties:
cmd:
- sleep
- -c
- "86400"
env:
- name: testKey
value: testValue
image: busybox
imagePullPolicy: IfNotPresent
traits:
- properties:
key: val
type: labels
- properties:
pvc:
- accessModes:
- ReadWriteOnce
mountOnly: false
mountPath: /data
name: lvhyca
resources:
requests:
storage: 4096Mi
storageClassName: default
volumeMode: Filesystem
type: storage
type: webservice