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

implement cli vela system live-diff #1419

Merged
merged 1 commit into from Apr 13, 2021

Conversation

captainroy-hy
Copy link
Collaborator

@captainroy-hy captainroy-hy commented Apr 6, 2021

to fix #733

  • implementation
  • unit tests
vela system live-diff -f app.yaml -r app-v1 --context 5
Application (application-sample) has been modified
...
    components:
    - name: myweb
      properties:
        cmd:
        - sleep
-       - "1000"
+       - "2000"
+       enemies: alien
+       image: busybox
+       lives: "3"
+     traits:
+     - properties:
+         domain: www.example.com
+         http:
+           /: 90
+       type: myingress
+     type: myworker
+   - name: new-myweb
+     properties:
+       cmd:
+       - sleep
+       - "2000"
        enemies: alien
        image: busybox
        lives: "3"
      traits:
      - properties:
          domain: www.example.com
          http:
-           /: 80
+           /: 90
        type: myingress
      type: myworker
  status:
    batchRollingState: ""
    currentBatch: 0
...
Component (myweb) has been modified
...
              app.oam.dev/component: myweb
          spec:
            containers:
            - command:
              - sleep
-             - "1000"
+             - "2000"
              image: busybox
              name: myweb
  status:
    observedGeneration: 0
  
Component (myweb) / Trait (myingress/service) has been modified
...
      trait.oam.dev/resource: service
      trait.oam.dev/type: myingress
    name: myweb
  spec:
    ports:
-   - port: 80
-     targetPort: 80
+   - port: 90
+     targetPort: 90
    selector:
      app.oam.dev/component: myweb
  
Component (myweb) / Trait (myingress/ingress) has been modified
...
    - host: www.example.com
      http:
        paths:
        - backend:
            serviceName: myweb
-           servicePort: 80
+           servicePort: 90
          path: /
  
Component (new-myweb) has been added
+ apiVersion: core.oam.dev/v1alpha2
+ kind: Component
+ metadata:
+   creationTimestamp: null
+   labels:
+     app.oam.dev/name: application-sample
+   name: new-myweb
+ spec:
+   workload:
+     apiVersion: apps/v1
+     kind: Deployment
+     metadata:
+       labels:
+         app.oam.dev/appRevision: ""
+         app.oam.dev/component: new-myweb
+         app.oam.dev/name: application-sample
+         workload.oam.dev/type: myworker
+     spec:
+       selector:
+         matchLabels:
+           app.oam.dev/component: new-myweb
+       template:
+         metadata:
+           labels:
+             app.oam.dev/component: new-myweb
+         spec:
+           containers:
+           - command:
+             - sleep
+             - "2000"
+             image: busybox
+             name: new-myweb
+ status:
+   observedGeneration: 0
  
Component (new-myweb) / Trait (myingress/service) has been added
+ apiVersion: v1
+ kind: Service
+ metadata:
+   labels:
+     app.oam.dev/appRevision: ""
+     app.oam.dev/component: new-myweb
+     app.oam.dev/name: application-sample
+     trait.oam.dev/resource: service
+     trait.oam.dev/type: myingress
+   name: new-myweb
+ spec:
+   ports:
+   - port: 90
+     targetPort: 90
+   selector:
+     app.oam.dev/component: new-myweb
  
Component (new-myweb) / Trait (myingress/ingress) has been added
+ apiVersion: networking.k8s.io/v1beta1
+ kind: Ingress
+ metadata:
+   labels:
+     app.oam.dev/appRevision: ""
+     app.oam.dev/component: new-myweb
+     app.oam.dev/name: application-sample
+     trait.oam.dev/resource: ingress
+     trait.oam.dev/type: myingress
+   name: new-myweb
+ spec:
+   rules:
+   - host: www.example.com
+     http:
+       paths:
+       - backend:
+           serviceName: new-myweb
+           servicePort: 90
+         path: /
vela system live-diff -f app.yaml -r app-v1
Application (application-sample) has been modified
  apiVersion: core.oam.dev/v1beta1
  kind: Application
  metadata:
    creationTimestamp: null
    name: application-sample
  spec:
    components:
    - name: myweb
+     properties:
+       cmd:
+       - sleep
+       - "2000"
+       enemies: alien
+       image: busybox
+       lives: "3"
+     traits:
+     - properties:
+         domain: www.example.com
+         http:
+           /: 90
+       type: myingress
+     type: myworker
+   - name: new-myweb
      properties:
        cmd:
        - sleep
-       - "1000"
+       - "2000"
        enemies: alien
        image: busybox
        lives: "3"
      traits:
      - properties:
          domain: www.example.com
          http:
-           /: 80
+           /: 90
        type: myingress
      type: myworker
  status:
    batchRollingState: ""
    currentBatch: 0
    rollingState: ""
    upgradedReadyReplicas: 0
    upgradedReplicas: 0
  
Component (myweb) has been modified
  apiVersion: core.oam.dev/v1alpha2
  kind: Component
  metadata:
    creationTimestamp: null
    labels:
      app.oam.dev/name: application-sample
    name: myweb
  spec:
    workload:
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        labels:
          app.oam.dev/appRevision: ""
          app.oam.dev/component: myweb
          app.oam.dev/name: application-sample
          workload.oam.dev/type: myworker
      spec:
        selector:
          matchLabels:
            app.oam.dev/component: myweb
        template:
          metadata:
            labels:
              app.oam.dev/component: myweb
          spec:
            containers:
            - command:
              - sleep
-             - "1000"
+             - "2000"
              image: busybox
              name: myweb
  status:
    observedGeneration: 0
  
Component (myweb) / Trait (myingress/service) has been modified
  apiVersion: v1
  kind: Service
  metadata:
    labels:
      app.oam.dev/appRevision: ""
      app.oam.dev/component: myweb
      app.oam.dev/name: application-sample
      trait.oam.dev/resource: service
      trait.oam.dev/type: myingress
    name: myweb
  spec:
    ports:
-   - port: 80
-     targetPort: 80
+   - port: 90
+     targetPort: 90
    selector:
      app.oam.dev/component: myweb
  
Component (myweb) / Trait (myingress/ingress) has been modified
  apiVersion: networking.k8s.io/v1beta1
  kind: Ingress
  metadata:
    labels:
      app.oam.dev/appRevision: ""
      app.oam.dev/component: myweb
      app.oam.dev/name: application-sample
      trait.oam.dev/resource: ingress
      trait.oam.dev/type: myingress
    name: myweb
  spec:
    rules:
    - host: www.example.com
      http:
        paths:
        - backend:
            serviceName: myweb
-           servicePort: 80
+           servicePort: 90
          path: /
  
Component (new-myweb) has been added
+ apiVersion: core.oam.dev/v1alpha2
+ kind: Component
+ metadata:
+   creationTimestamp: null
+   labels:
+     app.oam.dev/name: application-sample
+   name: new-myweb
+ spec:
+   workload:
+     apiVersion: apps/v1
+     kind: Deployment
+     metadata:
+       labels:
+         app.oam.dev/appRevision: ""
+         app.oam.dev/component: new-myweb
+         app.oam.dev/name: application-sample
+         workload.oam.dev/type: myworker
+     spec:
+       selector:
+         matchLabels:
+           app.oam.dev/component: new-myweb
+       template:
+         metadata:
+           labels:
+             app.oam.dev/component: new-myweb
+         spec:
+           containers:
+           - command:
+             - sleep
+             - "2000"
+             image: busybox
+             name: new-myweb
+ status:
+   observedGeneration: 0
  
Component (new-myweb) / Trait (myingress/service) has been added
+ apiVersion: v1
+ kind: Service
+ metadata:
+   labels:
+     app.oam.dev/appRevision: ""
+     app.oam.dev/component: new-myweb
+     app.oam.dev/name: application-sample
+     trait.oam.dev/resource: service
+     trait.oam.dev/type: myingress
+   name: new-myweb
+ spec:
+   ports:
+   - port: 90
+     targetPort: 90
+   selector:
+     app.oam.dev/component: new-myweb
  
Component (new-myweb) / Trait (myingress/ingress) has been added
+ apiVersion: networking.k8s.io/v1beta1
+ kind: Ingress
+ metadata:
+   labels:
+     app.oam.dev/appRevision: ""
+     app.oam.dev/component: new-myweb
+     app.oam.dev/name: application-sample
+     trait.oam.dev/resource: ingress
+     trait.oam.dev/type: myingress
+   name: new-myweb
+ spec:
+   rules:
+   - host: www.example.com
+     http:
+       paths:
+       - backend:
+           serviceName: new-myweb
+           servicePort: 90
+         path: /

screenshot
image

Signed-off-by: roywang seiwy2010@gmail.com

@codecov
Copy link

codecov bot commented Apr 6, 2021

Codecov Report

Merging #1419 (6ca418f) into master (26163aa) will increase coverage by 0.19%.
The diff coverage is n/a.

❗ Current head 6ca418f differs from pull request most recent head 31ea1b6. Consider uploading reports for the commit 31ea1b6 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1419      +/-   ##
==========================================
+ Coverage   53.27%   53.46%   +0.19%     
==========================================
  Files          83       81       -2     
  Lines        8179     8118      -61     
==========================================
- Hits         4357     4340      -17     
+ Misses       3303     3255      -48     
- Partials      519      523       +4     
Flag Coverage Δ
unittests 53.46% <ø> (+0.19%) ⬆️

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

Impacted Files Coverage Δ
...aits/traitdefinition/traitdefinition_controller.go 72.09% <0.00%> (-9.31%) ⬇️
pkg/builtin/build/build.go 12.35% <0.00%> (-2.12%) ⬇️
pkg/dsl/process/handle.go 75.86% <0.00%> (-1.56%) ⬇️
pkg/controller/utils/capability.go 44.55% <0.00%> (ø)
...troller/core.oam.dev/v1alpha2/application/apply.go 63.11% <0.00%> (ø)
pkg/appfile/appfile.go
pkg/appfile/template.go
pkg/builtin/kind/client.go
pkg/oam/util/template.go 35.05% <0.00%> (ø)
pkg/dsl/model/instance.go 71.79% <0.00%> (+1.52%) ⬆️
... and 2 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 26163aa...31ea1b6. Read the comment docs.

@wonderflow
Copy link
Collaborator

It's actually very cool! But I hope we can compare the resources that have already rendered out, which means compare K8s raw objects such as Deployment, services, etc.

@captainroy-hy captainroy-hy force-pushed the cli-live-diff branch 2 times, most recently from 6ca418f to 46b8d6b Compare April 12, 2021 02:47
@captainroy-hy
Copy link
Collaborator Author

Currently, dry-run will use provided capability definitions directly instead of applying them into the cluster.
And provided ones have higher priority than living ones in the cluster.
live-diff re-uses dry-run.

@captainroy-hy captainroy-hy changed the title [WIP] implement cli vela system live-diff implement cli vela system live-diff Apr 12, 2021
@captainroy-hy captainroy-hy marked this pull request as ready for review April 12, 2021 02:53
pkg/appfile/template.go Outdated Show resolved Hide resolved
pkg/appfile/template.go Outdated Show resolved Hide resolved
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.

This feature is extremely cool!love it very much!

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.

Cool!

@wonderflow
Copy link
Collaborator

ping @ryanzhang-oss please review

move dry-run and live-diff into an independent pkg

WIP add sample and doc

WIP unit test for live-diff

add unit test

Signed-off-by: roy wang <seiwy2010@gmail.com>
@ryanzhang-oss
Copy link
Collaborator

LGTM

@wonderflow wonderflow merged commit 63b348f into kubevela:master Apr 13, 2021
chivalryq pushed a commit to chivalryq/kubevela that referenced this pull request Apr 22, 2021
move dry-run and live-diff into an independent pkg

WIP add sample and doc

WIP unit test for live-diff

add unit test

Signed-off-by: roy wang <seiwy2010@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants