Version: v1.0

Dry-Run and Live-Diff

KubeVela allows you to dry-run and live-diff your application.

Dry-Run the Application

Dry run will help you to understand what are the real resources which will to be expanded and deployed to the Kubernetes cluster. In other words, it will mock to run the same logic as KubeVela’s controller and output the results locally.

For example, let’s dry-run the following application:

  1. # app.yaml
  2. apiVersion: core.oam.dev/v1beta1
  3. kind: Application
  4. metadata:
  5. name: vela-app
  6. spec:
  7. components:
  8. - name: express-server
  9. type: webservice
  10. properties:
  11. image: crccheck/hello-world
  12. port: 8000
  13. traits:
  14. - type: ingress
  15. properties:
  16. domain: testsvc.example.com
  17. http:
  18. "/": 8000
  1. kubectl vela dry-run -f app.yaml
  2. ---
  3. # Application(vela-app) -- Comopnent(express-server)
  4. ---
  5. apiVersion: apps/v1
  6. kind: Deployment
  7. metadata:
  8. labels:
  9. app.oam.dev/appRevision: ""
  10. app.oam.dev/component: express-server
  11. app.oam.dev/name: vela-app
  12. workload.oam.dev/type: webservice
  13. spec:
  14. selector:
  15. matchLabels:
  16. app.oam.dev/component: express-server
  17. template:
  18. metadata:
  19. labels:
  20. app.oam.dev/component: express-server
  21. spec:
  22. containers:
  23. - image: crccheck/hello-world
  24. name: express-server
  25. ports:
  26. - containerPort: 8000
  27. ---
  28. apiVersion: v1
  29. kind: Service
  30. metadata:
  31. labels:
  32. app.oam.dev/appRevision: ""
  33. app.oam.dev/component: express-server
  34. app.oam.dev/name: vela-app
  35. trait.oam.dev/resource: service
  36. trait.oam.dev/type: ingress
  37. name: express-server
  38. spec:
  39. ports:
  40. - port: 8000
  41. targetPort: 8000
  42. selector:
  43. app.oam.dev/component: express-server
  44. ---
  45. apiVersion: networking.k8s.io/v1beta1
  46. kind: Ingress
  47. metadata:
  48. labels:
  49. app.oam.dev/appRevision: ""
  50. app.oam.dev/component: express-server
  51. app.oam.dev/name: vela-app
  52. trait.oam.dev/resource: ingress
  53. trait.oam.dev/type: ingress
  54. name: express-server
  55. spec:
  56. rules:
  57. - host: testsvc.example.com
  58. http:
  59. paths:
  60. - backend:
  61. serviceName: express-server
  62. servicePort: 8000
  63. path: /
  64. ---

In this example, the definitions(webservice and ingress) which vela-app depends on is the built-in components and traits of KubeVela. You can also use -d or --definitions to specify your local definition files.

-d or --definitions permitting user to provide capability definitions used in the application from local files. dry-run cmd will prioritize the provided capabilities than the living ones in the cluster.

Live-Diff the Application

Live-diff helps you to have a preview of what would change if you’re going to upgrade an application without making any changes to the living cluster. This feature is extremely useful for serious production deployment, and make the upgrade under control

It basically generates a diff between the specific revision of running instance and the local candidate application. The result shows the changes (added/modified/removed/no_change) of the application as well as its sub-resources, such as components and traits.

Assume you have just deployed the application in dry-run section. Then you can list the revisions of the Application.

  1. $ kubectl get apprev -l app.oam.dev/name=vela-app
  2. NAME AGE
  3. vela-app-v1 50s

Assume we’re going to upgrade the application like below.

  1. # new-app.yaml
  2. apiVersion: core.oam.dev/v1beta1
  3. kind: Application
  4. metadata:
  5. name: vela-app
  6. spec:
  7. components:
  8. - name: express-server
  9. type: webservice
  10. properties:
  11. image: crccheck/hello-world
  12. port: 8080 # change port
  13. cpu: 0.5 # add requests cpu units
  14. - name: my-task # add a component
  15. type: task
  16. properties:
  17. image: busybox
  18. cmd: ["sleep", "1000"]
  19. traits:
  20. - type: ingress
  21. properties:
  22. domain: testsvc.example.com
  23. http:
  24. "/": 8080 # change port

Run live-diff like this:

  1. kubectl vela live-diff -f new-app.yaml -r vela-app-v1

-r or --revision is a flag that specifies the name of a living ApplicationRevision with which you want to compare the updated application.

-c or --context is a flag that specifies the number of lines shown around a change. The unchanged lines which are out of the context of a change will be omitted. It’s useful if the diff result contains a lot of unchanged content while you just want to focus on the changed ones.

Click to view the details of diff result

  1. ---
  2. # Application (vela-app) has been modified(*)
  3. ---
  4. apiVersion: core.oam.dev/v1beta1
  5. kind: Application
  6. metadata:
  7. creationTimestamp: null
  8. name: vela-app
  9. namespace: default
  10. spec:
  11. components:
  12. - name: express-server
  13. properties:
  14. + cpu: 0.5
  15. image: crccheck/hello-world
  16. - port: 8000
  17. + port: 8080
  18. + type: webservice
  19. + - name: my-task
  20. + properties:
  21. + cmd:
  22. + - sleep
  23. + - "1000"
  24. + image: busybox
  25. traits:
  26. - properties:
  27. domain: testsvc.example.com
  28. http:
  29. - /: 8000
  30. + /: 8080
  31. type: ingress
  32. - type: webservice
  33. + type: task
  34. status:
  35. batchRollingState: ""
  36. currentBatch: 0
  37. rollingState: ""
  38. upgradedReadyReplicas: 0
  39. upgradedReplicas: 0
  40. ---
  41. ## Component (express-server) has been modified(*)
  42. ---
  43. apiVersion: core.oam.dev/v1alpha2
  44. kind: Component
  45. metadata:
  46. creationTimestamp: null
  47. labels:
  48. app.oam.dev/name: vela-app
  49. name: express-server
  50. spec:
  51. workload:
  52. apiVersion: apps/v1
  53. kind: Deployment
  54. metadata:
  55. labels:
  56. app.oam.dev/appRevision: ""
  57. app.oam.dev/component: express-server
  58. app.oam.dev/name: vela-app
  59. workload.oam.dev/type: webservice
  60. spec:
  61. selector:
  62. matchLabels:
  63. app.oam.dev/component: express-server
  64. template:
  65. metadata:
  66. labels:
  67. app.oam.dev/component: express-server
  68. spec:
  69. containers:
  70. - image: crccheck/hello-world
  71. name: express-server
  72. ports:
  73. - - containerPort: 8000
  74. + - containerPort: 8080
  75. status:
  76. observedGeneration: 0
  77. ---
  78. ### Component (express-server) / Trait (ingress/service) has been removed(-)
  79. ---
  80. - apiVersion: v1
  81. - kind: Service
  82. - metadata:
  83. - labels:
  84. - app.oam.dev/appRevision: ""
  85. - app.oam.dev/component: express-server
  86. - app.oam.dev/name: vela-app
  87. - trait.oam.dev/resource: service
  88. - trait.oam.dev/type: ingress
  89. - name: express-server
  90. - spec:
  91. - ports:
  92. - - port: 8000
  93. - targetPort: 8000
  94. - selector:
  95. - app.oam.dev/component: express-server
  96. ---
  97. ### Component (express-server) / Trait (ingress/ingress) has been removed(-)
  98. ---
  99. - apiVersion: networking.k8s.io/v1beta1
  100. - kind: Ingress
  101. - metadata:
  102. - labels:
  103. - app.oam.dev/appRevision: ""
  104. - app.oam.dev/component: express-server
  105. - app.oam.dev/name: vela-app
  106. - trait.oam.dev/resource: ingress
  107. - trait.oam.dev/type: ingress
  108. - name: express-server
  109. - spec:
  110. - rules:
  111. - - host: testsvc.example.com
  112. - http:
  113. - paths:
  114. - - backend:
  115. - serviceName: express-server
  116. - servicePort: 8000
  117. - path: /
  118. ---
  119. ## Component (my-task) has been added(+)
  120. ---
  121. + apiVersion: core.oam.dev/v1alpha2
  122. + kind: Component
  123. + metadata:
  124. + creationTimestamp: null
  125. + labels:
  126. + app.oam.dev/name: vela-app
  127. + name: my-task
  128. + spec:
  129. + workload:
  130. + apiVersion: batch/v1
  131. + kind: Job
  132. + metadata:
  133. + labels:
  134. + app.oam.dev/appRevision: ""
  135. + app.oam.dev/component: my-task
  136. + app.oam.dev/name: vela-app
  137. + workload.oam.dev/type: task
  138. + spec:
  139. + completions: 1
  140. + parallelism: 1
  141. + template:
  142. + spec:
  143. + containers:
  144. + - command:
  145. + - sleep
  146. + - "1000"
  147. + image: busybox
  148. + name: my-task
  149. + restartPolicy: Never
  150. + status:
  151. + observedGeneration: 0
  152. ---
  153. ### Component (my-task) / Trait (ingress/service) has been added(+)
  154. ---
  155. + apiVersion: v1
  156. + kind: Service
  157. + metadata:
  158. + labels:
  159. + app.oam.dev/appRevision: ""
  160. + app.oam.dev/component: my-task
  161. + app.oam.dev/name: vela-app
  162. + trait.oam.dev/resource: service
  163. + trait.oam.dev/type: ingress
  164. + name: my-task
  165. + spec:
  166. + ports:
  167. + - port: 8080
  168. + targetPort: 8080
  169. + selector:
  170. + app.oam.dev/component: my-task
  171. ---
  172. ### Component (my-task) / Trait (ingress/ingress) has been added(+)
  173. ---
  174. + apiVersion: networking.k8s.io/v1beta1
  175. + kind: Ingress
  176. + metadata:
  177. + labels:
  178. + app.oam.dev/appRevision: ""
  179. + app.oam.dev/component: my-task
  180. + app.oam.dev/name: vela-app
  181. + trait.oam.dev/resource: ingress
  182. + trait.oam.dev/type: ingress
  183. + name: my-task
  184. + spec:
  185. + rules:
  186. + - host: testsvc.example.com
  187. + http:
  188. + paths:
  189. + - backend:
  190. + serviceName: my-task
  191. + servicePort: 8080
  192. + path: /