ability to show complete yaml with dry-run
warroyo opened this issue · comments
currently when deploying with kapp I can only get a diff of changes this makes it hard to do comparisons of generated yaml outside of kapp as well as hard to see the impact of rebase rules etc.
What I would like:
when using kapp to deploy I would like a dry-run feature similar to kubectl that outputs all of the yaml that will be applied. right now I can see a diff but I want to be able to see the complete yaml after any rebase rules, etc. run.
related discussion https://kubernetes.slack.com/archives/CH8KCCKA5/p1650058772827969
Acceptance criteria
- As the solution of this issue, kapp will have a flag like diff-dry-run(this could be something else as well, putting here now just for reference) with
deploy
. If this flag is set to true, kapp will print the full yaml that's generated after applying rebase rules etc to the screen and exit. - Command will look like: kapp deploy -a app1 -f xyz --diff-dry-run=true
- If we use the kapp/example to
create
a simple-app, output will look like:
$ ./carvel-kapp/kapp deploy -a simple-app -f carvel-kapp/examples/simple-app-example/config-1.yml --diff-dry-run=true
Target cluster 'https://127.0.0.1:33907' (nodes: minikube)
---
apiVersion: v1
kind: Service
metadata:
labels:
kapp.k14s.io/app: "1653993324805986000"
kapp.k14s.io/association: v1.462a95c01b2a0bdc4d5acadc4a22dd74
name: simple-app
namespace: default
spec:
ports:
- port: 80
targetPort: 80
selector:
kapp.k14s.io/app: "1653993324805986000"
simple-app: ""
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
kapp.k14s.io/app: "1653993324805986000"
kapp.k14s.io/association: v1.22a4cbb25c518f776737777e8407b8d9
name: simple-app
namespace: default
spec:
selector:
matchLabels:
kapp.k14s.io/app: "1653993324805986000"
simple-app: ""
template:
metadata:
labels:
kapp.k14s.io/app: "1653993324805986000"
kapp.k14s.io/association: v1.22a4cbb25c518f776737777e8407b8d9
simple-app: ""
spec:
containers:
- env:
- name: HELLO_MSG
value: stranger
image: docker.io/dkalinin/k8s-simple-app@sha256:4c8b96d4fffdfae29258d94a22ae4ad1fe36139d47288b8960d9958d1e63a9d0
name: simple-app
Succeeded
- Now
updating
port from 80 to 8080 in service and redeploy the app, output will look like:
./carvel-kapp/kapp deploy -a simple-app -f carvel-kapp/examples/simple-app-example/config-1.yml --diff-yaml-to-be-applied
Target cluster 'https://127.0.0.1:33907' (nodes: minikube)
---
apiVersion: v1
kind: Service
metadata:
creationTimestamp: "2022-05-08T11:41:34Z"
labels:
kapp.k14s.io/app: "1654056205083501000"
kapp.k14s.io/association: v1.462a95c01b2a0bdc4d5acadc4a22dd74
name: simple-app
namespace: default
resourceVersion: "1618"
uid: b46121dc-5eee-411b-aead-b894673d7ebd
spec:
clusterIP: 10.98.158.196
ports:
- port: 8080
targetPort: 8080
selector:
kapp.k14s.io/app: "1654056205083501000"
simple-app: ""
status:
loadBalancer: {}
Succeeded
- If we
remove
deployment and deploy app again only with service(without making any changes)then: a) if deployment has hasorphan
delete strategy, kapp will print yaml and b) if deployment hasplain
delete strategy, kapp will not print yaml.
Summary:
Operation | kapp will print yaml |
---|---|
Create | Yes |
Update | Yes |
Remove( resource with plain delete strategy) | No |
Remove(resource with orphan delete strategy) | Yes |
- This flag can not be used with any other flag. If we do so then --diff-dry-run will print the output and exist as this flag will have the highest priority.
Note:- diff-dry-run
is just used for reference, it is not finalised yet. Request you all to give suggestion for the naming or if you are fine with this then please vote, this will also be helpful.
Alternate name: yaml-to-be-applied
- i'm not sure "dry run" is good term to use here since there is also server side dry run feature in k8s.
- something to think about is whether this bit is more related to diff or apply. one way to think about is what is the yaml to be applied.
@warroyo
Let we deployed an app having two resources service and deployment. Now in second time we remove service and redeploy the app with deployment by making some update. In this case kapp will print the yaml only for deployment as the service will be deleted in this case. Although if we want can print the yaml for both deployment and service but what kind of operation is getting applied on the service will not be clear.
If we will not print yaml for removed resources then again will not be able to distinguish with resource with no update as we will not be printing yaml for them as well.
Hence, we decided to show the yaml with some additional information like operation to be applied. The output will be something like:
- create:
- resA yaml
- resB yaml
- update:
-resC yaml
- orphan:
- resD yaml // for resources having orphan delete strategy
- delete:
- resource name
- noop:
interesting twist :), is this now more of a --diff-changes but in a YAML format (e.g. --diff-changes-as-yaml)?
- dry-run is used just for reference for now. We will change it.
- This is more related to apply as we are going to print complete yaml (as shown in acceptance criteria) which is being generated by kapp after applying rebase rules and all to make changes in resources in cluster.