|
7 | 7 | "os" |
8 | 8 | "os/exec" |
9 | 9 | "path/filepath" |
| 10 | + "strconv" |
10 | 11 | "strings" |
11 | 12 | "testing" |
12 | 13 |
|
@@ -1167,6 +1168,74 @@ func TestServerSideDiff(t *testing.T) { |
1167 | 1168 | assert.Empty(t, liveDeploy.Annotations[AnnotationLastAppliedConfig]) |
1168 | 1169 | }) |
1169 | 1170 |
|
| 1171 | + t.Run("will strip kubectl.kubernetes.io/last-applied-configuration from both sides", func(t *testing.T) { |
| 1172 | + t.Parallel() |
| 1173 | + |
| 1174 | + const lastAppliedRaw = `{"apiVersion":"v1","kind":"Secret","metadata":{"name":"secret","namespace":"default","annotations":{"app":"test"}},"data":{"password":"U0VDUkVUVkFM"},"stringData":{"username":"SECRETVAL"}}` |
| 1175 | + |
| 1176 | + liveState := StrToUnstructured(`{ |
| 1177 | + "apiVersion": "v1", |
| 1178 | + "kind": "Secret", |
| 1179 | + "metadata": { |
| 1180 | + "name": "secret", |
| 1181 | + "namespace": "default", |
| 1182 | + "annotations": { |
| 1183 | + "app": "test", |
| 1184 | + "kubectl.kubernetes.io/last-applied-configuration": ` + strconv.Quote(lastAppliedRaw) + ` |
| 1185 | + } |
| 1186 | + }, |
| 1187 | + "type": "Opaque", |
| 1188 | + "data": { |
| 1189 | + "password": "U0VDUkVUVkFM" |
| 1190 | + } |
| 1191 | + }`) |
| 1192 | + desiredState := StrToUnstructured(`{ |
| 1193 | + "apiVersion": "v1", |
| 1194 | + "kind": "Secret", |
| 1195 | + "metadata": { |
| 1196 | + "name": "secret", |
| 1197 | + "namespace": "default", |
| 1198 | + "annotations": { |
| 1199 | + "app": "test" |
| 1200 | + } |
| 1201 | + }, |
| 1202 | + "type": "Opaque", |
| 1203 | + "data": { |
| 1204 | + "password": "U0VDUkVUVkFM" |
| 1205 | + } |
| 1206 | + }`) |
| 1207 | + predictedLiveJSON := `{ |
| 1208 | + "apiVersion": "v1", |
| 1209 | + "kind": "Secret", |
| 1210 | + "metadata": { |
| 1211 | + "name": "secret", |
| 1212 | + "namespace": "default", |
| 1213 | + "annotations": { |
| 1214 | + "app": "test", |
| 1215 | + "kubectl.kubernetes.io/last-applied-configuration": ` + strconv.Quote(lastAppliedRaw) + ` |
| 1216 | + } |
| 1217 | + }, |
| 1218 | + "type": "Opaque", |
| 1219 | + "data": { |
| 1220 | + "password": "U0VDUkVUVkFM" |
| 1221 | + } |
| 1222 | + }` |
| 1223 | + opts := buildOpts(predictedLiveJSON) |
| 1224 | + opts = append(opts, WithIgnoreMutationWebhook(false)) |
| 1225 | + |
| 1226 | + // when |
| 1227 | + result, err := serverSideDiff(desiredState, liveState, opts...) |
| 1228 | + |
| 1229 | + // then |
| 1230 | + require.NoError(t, err) |
| 1231 | + require.NotNil(t, result) |
| 1232 | + assert.NotContains(t, string(result.PredictedLive), "kubectl.kubernetes.io/last-applied-configuration", |
| 1233 | + "PredictedLive must not contain the last-applied-configuration annotation") |
| 1234 | + assert.NotContains(t, string(result.NormalizedLive), "kubectl.kubernetes.io/last-applied-configuration", |
| 1235 | + "NormalizedLive must not contain the last-applied-configuration annotation") |
| 1236 | + assert.NotContains(t, string(result.PredictedLive), "SECRETVAL", |
| 1237 | + "PredictedLive must not contain raw secret values from last-applied-configuration") |
| 1238 | + }) |
1170 | 1239 | t.Run("will mask Secret data symmetrically so identical values do not produce a spurious diff", func(t *testing.T) { |
1171 | 1240 | t.Parallel() |
1172 | 1241 |
|
|
0 commit comments