Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: get raw Application yaml, json or jsonpath #4415

Merged
merged 7 commits into from Jul 22, 2022

Conversation

charlie0129
Copy link
Member

@charlie0129 charlie0129 commented Jul 20, 2022

Signed-off-by: Charlie Chiang charlie_c_0129@outlook.com

Description of your changes

Added support for getting raw Application yaml in Vela CLI, via -o --output parameter.

Looking at some examples will give you a better understanding:


Get whole Application in yaml

vela status first-vela-app -o yaml

Click to see command output
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  annotations:
    app.oam.dev/last-applied-configuration: '{"kind":"Application","apiVersion":"core.oam.dev/v1beta1","metadata":{"name":"first-vela-app","namespace":"default","creationTimestamp":null,"labels":{"oam.dev/render-hash":"ea855623cc3ffbb9"}},"spec":{"components":[{"name":"express-server","type":"webservice","properties":{"image":"oamdev/hello-world","ports":[{"expose":true,"port":8000}]},"traits":[{"type":"scaler","properties":{"replicas":1}}]}],"policies":[{"name":"target-default","type":"topology","properties":{"clusters":["local"],"namespace":"default"}}]},"status":{}}'
    app.oam.dev/last-applied-time: "2022-07-20T16:57:46+08:00"
    oam.dev/kubevela-version: v1.4.0
  creationTimestamp: "2022-07-20T08:57:46Z"
  finalizers:
  - app.oam.dev/resource-tracker-finalizer
  generation: 1
  labels:
    oam.dev/render-hash: ea855623cc3ffbb9
  name: first-vela-app
  namespace: default
  resourceVersion: "4535251"
  uid: 63032d71-85c2-4571-8d81-56b7370bb113
spec:
  components:
  - name: express-server
    properties:
      image: oamdev/hello-world
      ports:
      - expose: true
        port: 8000
    traits:
    - properties:
        replicas: 1
      type: scaler
    type: webservice
  policies:
  - name: target-default
    properties:
      clusters:
      - local
      namespace: default
    type: topology
status:
  appliedResources:
  - apiVersion: apps/v1
    cluster: local
    creator: workflow
    kind: Deployment
    name: express-server
    namespace: default
  - apiVersion: v1
    cluster: local
    creator: workflow
    kind: Service
    name: express-server
    namespace: default
  conditions:
  - lastTransitionTime: "2022-07-20T08:57:46Z"
    reason: Available
    status: "True"
    type: Parsed
  - lastTransitionTime: "2022-07-20T08:57:46Z"
    reason: Available
    status: "True"
    type: Revision
  - lastTransitionTime: "2022-07-20T08:57:46Z"
    reason: Available
    status: "True"
    type: Policy
  - lastTransitionTime: "2022-07-20T08:57:46Z"
    reason: Available
    status: "True"
    type: Render
  - lastTransitionTime: "2022-07-20T08:57:55Z"
    reason: Available
    status: "True"
    type: Workflow
  - lastTransitionTime: "2022-07-20T08:57:55Z"
    reason: ReconcileSuccess
    status: "True"
    type: Ready
  latestRevision:
    name: first-vela-app-v1
    revision: 1
    revisionHash: 8ad93499a2dc2fa9
  observedGeneration: 1
  services:
  - cluster: local
    healthy: true
    message: Ready:1/1
    name: express-server
    namespace: default
    traits:
    - healthy: true
      type: scaler
    workloadDefinition:
      apiVersion: apps/v1
      kind: Deployment
  status: running
  workflow:
    appRevision: first-vela-app-v1:630c401488fe8a9
    contextBackend:
      name: workflow-first-vela-app-context
      uid: a321f89e-2c9c-40ea-81ab-27d6e8a5d273
    finished: true
    message: Succeeded
    mode: DAG
    startTime: "2022-07-20T08:57:46Z"
    steps:
    - firstExecuteTime: "2022-07-20T08:57:46Z"
      id: ega2uspq28
      lastExecuteTime: "2022-07-20T08:57:55Z"
      name: deploy-target-default
      phase: succeeded
      type: deploy
    suspend: false
    terminated: false

Get whole Application in json

vela status first-vela-app -o json

Click to see command output
{
  "kind": "Application",
  "apiVersion": "core.oam.dev/v1beta1",
  "metadata": {
    "name": "first-vela-app",
    "namespace": "default",
    "uid": "63032d71-85c2-4571-8d81-56b7370bb113",
    "resourceVersion": "4535251",
    "generation": 1,
    "creationTimestamp": "2022-07-20T08:57:46Z",
    "labels": {
      "oam.dev/render-hash": "ea855623cc3ffbb9"
    },
    "annotations": {
      "app.oam.dev/last-applied-configuration": "{\"kind\":\"Application\",\"apiVersion\":\"core.oam.dev/v1beta1\",\"metadata\":{\"name\":\"first-vela-app\",\"namespace\":\"default\",\"creationTimestamp\":null,\"labels\":{\"oam.dev/render-hash\":\"ea855623cc3ffbb9\"}},\"spec\":{\"components\":[{\"name\":\"express-server\",\"type\":\"webservice\",\"properties\":{\"image\":\"oamdev/hello-world\",\"ports\":[{\"expose\":true,\"port\":8000}]},\"traits\":[{\"type\":\"scaler\",\"properties\":{\"replicas\":1}}]}],\"policies\":[{\"name\":\"target-default\",\"type\":\"topology\",\"properties\":{\"clusters\":[\"local\"],\"namespace\":\"default\"}}]},\"status\":{}}",
      "app.oam.dev/last-applied-time": "2022-07-20T16:57:46+08:00",
      "oam.dev/kubevela-version": "v1.4.0"
    },
    "finalizers": [
      "app.oam.dev/resource-tracker-finalizer"
    ]
  },
  "spec": {
    "components": [
      {
        "name": "express-server",
        "type": "webservice",
        "properties": {
          "image": "oamdev/hello-world",
          "ports": [
            {
              "expose": true,
              "port": 8000
            }
          ]
        },
        "traits": [
          {
            "type": "scaler",
            "properties": {
              "replicas": 1
            }
          }
        ]
      }
    ],
    "policies": [
      {
        "name": "target-default",
        "type": "topology",
        "properties": {
          "clusters": [
            "local"
          ],
          "namespace": "default"
        }
      }
    ]
  },
  "status": {
    "conditions": [
      {
        "type": "Parsed",
        "status": "True",
        "lastTransitionTime": "2022-07-20T08:57:46Z",
        "reason": "Available"
      },
      {
        "type": "Revision",
        "status": "True",
        "lastTransitionTime": "2022-07-20T08:57:46Z",
        "reason": "Available"
      },
      {
        "type": "Policy",
        "status": "True",
        "lastTransitionTime": "2022-07-20T08:57:46Z",
        "reason": "Available"
      },
      {
        "type": "Render",
        "status": "True",
        "lastTransitionTime": "2022-07-20T08:57:46Z",
        "reason": "Available"
      },
      {
        "type": "Workflow",
        "status": "True",
        "lastTransitionTime": "2022-07-20T08:57:55Z",
        "reason": "Available"
      },
      {
        "type": "Ready",
        "status": "True",
        "lastTransitionTime": "2022-07-20T08:57:55Z",
        "reason": "ReconcileSuccess"
      }
    ],
    "observedGeneration": 1,
    "status": "running",
    "services": [
      {
        "name": "express-server",
        "namespace": "default",
        "cluster": "local",
        "workloadDefinition": {
          "apiVersion": "apps/v1",
          "kind": "Deployment"
        },
        "healthy": true,
        "message": "Ready:1/1",
        "traits": [
          {
            "type": "scaler",
            "healthy": true
          }
        ]
      }
    ],
    "workflow": {
      "appRevision": "first-vela-app-v1:630c401488fe8a9",
      "mode": "DAG",
      "message": "Succeeded",
      "suspend": false,
      "terminated": false,
      "finished": true,
      "contextBackend": {
        "name": "workflow-first-vela-app-context",
        "uid": "a321f89e-2c9c-40ea-81ab-27d6e8a5d273"
      },
      "steps": [
        {
          "id": "ega2uspq28",
          "name": "deploy-target-default",
          "type": "deploy",
          "phase": "succeeded",
          "firstExecuteTime": "2022-07-20T08:57:46Z",
          "lastExecuteTime": "2022-07-20T08:57:55Z"
        }
      ],
      "startTime": "2022-07-20T08:57:46Z"
    },
    "latestRevision": {
      "name": "first-vela-app-v1",
      "revision": 1,
      "revisionHash": "8ad93499a2dc2fa9"
    },
    "appliedResources": [
      {
        "cluster": "local",
        "creator": "workflow",
        "kind": "Deployment",
        "namespace": "default",
        "name": "express-server",
        "apiVersion": "apps/v1"
      },
      {
        "cluster": "local",
        "creator": "workflow",
        "kind": "Service",
        "namespace": "default",
        "name": "express-server",
        "apiVersion": "v1"
      }
    ]
  }
}

Quickly check Application status using jsonpath

vela status first-vela-app -o jsonpath='{.status}' | jq

Click to see command output
{
  "conditions": [
    {
      "type": "Parsed",
      "status": "True",
      "lastTransitionTime": "2022-07-20T08:57:46Z",
      "reason": "Available"
    },
    {
      "type": "Revision",
      "status": "True",
      "lastTransitionTime": "2022-07-20T08:57:46Z",
      "reason": "Available"
    },
    {
      "type": "Policy",
      "status": "True",
      "lastTransitionTime": "2022-07-20T08:57:46Z",
      "reason": "Available"
    },
    {
      "type": "Render",
      "status": "True",
      "lastTransitionTime": "2022-07-20T08:57:46Z",
      "reason": "Available"
    },
    {
      "type": "Workflow",
      "status": "True",
      "lastTransitionTime": "2022-07-20T08:57:55Z",
      "reason": "Available"
    },
    {
      "type": "Ready",
      "status": "True",
      "lastTransitionTime": "2022-07-20T08:57:55Z",
      "reason": "ReconcileSuccess"
    }
  ],
  "observedGeneration": 1,
  "status": "running",
  "services": [
    {
      "name": "express-server",
      "namespace": "default",
      "cluster": "local",
      "workloadDefinition": {
        "apiVersion": "apps/v1",
        "kind": "Deployment"
      },
      "healthy": true,
      "message": "Ready:1/1",
      "traits": [
        {
          "type": "scaler",
          "healthy": true
        }
      ]
    }
  ],
  "workflow": {
    "appRevision": "first-vela-app-v1:630c401488fe8a9",
    "mode": "DAG",
    "message": "Succeeded",
    "suspend": false,
    "terminated": false,
    "finished": true,
    "contextBackend": {
      "name": "workflow-first-vela-app-context",
      "uid": "a321f89e-2c9c-40ea-81ab-27d6e8a5d273"
    },
    "steps": [
      {
        "id": "ega2uspq28",
        "name": "deploy-target-default",
        "type": "deploy",
        "phase": "succeeded",
        "firstExecuteTime": "2022-07-20T08:57:46Z",
        "lastExecuteTime": "2022-07-20T08:57:55Z"
      }
    ],
    "startTime": "2022-07-20T08:57:46Z"
  },
  "latestRevision": {
    "name": "first-vela-app-v1",
    "revision": 1,
    "revisionHash": "8ad93499a2dc2fa9"
  },
  "appliedResources": [
    {
      "cluster": "local",
      "creator": "workflow",
      "kind": "Deployment",
      "namespace": "default",
      "name": "express-server",
      "apiVersion": "apps/v1"
    },
    {
      "cluster": "local",
      "creator": "workflow",
      "kind": "Service",
      "namespace": "default",
      "name": "express-server",
      "apiVersion": "v1"
    }
  ]
}

Only the above three formats are supported in -o --output option.

Fixes #4235

I have:

  • Read and followed KubeVela's contribution process.
  • Related Docs updated properly. In a new feature or configuration option, an update to the documentation is necessary.
  • Run make reviewable to ensure this PR is ready for review.
  • Added backport release-x.y labels to auto-backport this PR if necessary.

How has this code been tested

Manually tested with possible user inputs. Unit tests for the util function are added.

Special notes for your reviewer

There is a --detail-format flag mentioned in the original issue. I didn't use it because it serves a different purpose.

Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com>
@charlie0129 charlie0129 changed the title Feat: get raw Application Feat: get raw Application yaml, json or jsonpath Jul 20, 2022
@codecov
Copy link

codecov bot commented Jul 20, 2022

Codecov Report

Merging #4415 (319a5f7) into master (181bc92) will increase coverage by 2.12%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #4415      +/-   ##
==========================================
+ Coverage   59.38%   61.50%   +2.12%     
==========================================
  Files         342      347       +5     
  Lines       34115    34260     +145     
==========================================
+ Hits        20258    21073     +815     
+ Misses      11201    10443     -758     
- Partials     2656     2744      +88     
Flag Coverage Δ
apiserver-e2etests 27.10% <ø> (-0.16%) ⬇️
apiserver-unittests 40.06% <ø> (+0.02%) ⬆️
core-unittests 56.51% <ø> (+0.14%) ⬆️
e2e-multicluster-test 19.82% <ø> (?)
e2e-rollout-tests 22.26% <ø> (+0.06%) ⬆️
e2etests 28.67% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/workflow/hooks/data_passing.go 60.97% <0.00%> (-14.64%) ⬇️
pkg/apiserver/interfaces/api/oam_application.go 63.07% <0.00%> (-6.16%) ⬇️
...tepdefinition/workflowstepdefinition_controller.go 71.27% <0.00%> (-5.32%) ⬇️
pkg/apiserver/utils/bcode/bcode.go 50.00% <0.00%> (-2.95%) ⬇️
...server/infrastructure/datastore/kubeapi/kubeapi.go 63.49% <0.00%> (-1.15%) ⬇️
pkg/addon/addon.go 64.43% <0.00%> (-1.14%) ⬇️
pkg/addon/helper.go 69.89% <0.00%> (-1.03%) ⬇️
pkg/apiserver/domain/service/addon.go 58.69% <0.00%> (-0.73%) ⬇️
.../core/scopes/healthscope/healthscope_controller.go 71.59% <0.00%> (-0.29%) ⬇️
pkg/cmd/util/helpers.go 50.00% <0.00%> (ø)
... and 57 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 181bc92...319a5f7. Read the comment docs.

@charlie0129 charlie0129 marked this pull request as ready for review July 20, 2022 15:44
Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com>
@wonderflow
Copy link
Collaborator

Great job! Please trim the managedFields.

Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com>
@charlie0129
Copy link
Member Author

Great job! Please trim the managedFields.

Sure, gone are the managedFields now.

Copy link
Collaborator

@wonderflow wonderflow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great

Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com>
references/cli/status.go Outdated Show resolved Hide resolved
@@ -118,6 +136,9 @@ func NewAppStatusCommand(c common.Args, order string, ioStreams cmdutil.IOStream
if err != nil {
return err
}
if outputFormat != "" {
return printRawApplication(context.Background(), c, outputFormat, cmd.OutOrStdout(), namespace, appName)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does "showEndpoints" still work? if "return" here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is intended.

If the user wants raw output, then the endpoints table will be purely noise to them.

references/cli/status.go Outdated Show resolved Hide resolved
Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com>
Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com>
Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com>
Copy link
Collaborator

@barnettZQG barnettZQG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] how to display vela application yaml from CLI?
5 participants