Commit c08b1c4
committed
Normalize YAML manifests before running diff
The current behavior of helm-diff is to show diffs even when the
YAML files are semantically identical but they contain style
differences, such as indentation or key ordering.
As an example, the following two YAMLs would be showing diffs:
```
apiVersion: v1
kind: Service
metadata:
name: app-name
labels:
app.kubernetes.io/name: app-name
app.kubernetes.io/managed-by: Helm
spec:
ports:
- name: http
port: 80
targetPort: http
selector:
app.kubernetes.io/name: app-name
type: ClusterIP
```
```
apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: app-name
name: app-name
spec:
ports:
- name: http
port: 80
targetPort: http
selector:
app.kubernetes.io/name: app-name
type: ClusterIP
```
even though they are semantically the same.
This commit exploits the reordering and normalization that is performed
by the yaml package when marshaling by unmarshaling and re-marshaling
all manifests before running the diff, thus eliminating the issue.1 parent 818e596 commit c08b1c4
1 file changed
+11
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
138 | | - | |
| 138 | + | |
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
166 | 176 | | |
167 | 177 | | |
168 | 178 | | |
| |||
0 commit comments