|
8 | 8 | "testing"
|
9 | 9 | "time"
|
10 | 10 |
|
| 11 | + "github.com/ghodss/yaml" |
11 | 12 | "github.com/stretchr/testify/assert"
|
12 | 13 | appsv1 "k8s.io/api/apps/v1"
|
13 | 14 | corev1 "k8s.io/api/core/v1"
|
@@ -1186,5 +1187,55 @@ func TestGetTimeRemainingBeforeScaleDownDeadline(t *testing.T) {
|
1186 | 1187 | assert.Nil(t, err)
|
1187 | 1188 | assert.NotNil(t, remainingTime)
|
1188 | 1189 | }
|
| 1190 | +} |
| 1191 | + |
| 1192 | +// TestPodTemplateEqualIgnoreHashWithServiceAccount catches a corner case where the K8s ComputeHash |
| 1193 | +// function changed from underneath us, and we fell back to deep equality checking, which then |
| 1194 | +// incorrectly detected a diff because of a deprecated field being present in the live but not desired. |
| 1195 | +func TestPodTemplateEqualIgnoreHashWithServiceAccount(t *testing.T) { |
| 1196 | + var desired corev1.PodTemplateSpec |
| 1197 | + desiredTemplate := ` |
| 1198 | +metadata: |
| 1199 | + labels: |
| 1200 | + app: serviceaccount-ro |
| 1201 | +spec: |
| 1202 | + containers: |
| 1203 | + - image: nginx:1.19-alpine |
| 1204 | + name: app |
| 1205 | + serviceAccountName: default |
| 1206 | +` |
| 1207 | + err := yaml.Unmarshal([]byte(desiredTemplate), &desired) |
| 1208 | + assert.NoError(t, err) |
| 1209 | + |
| 1210 | + // liveTemplate was captured from a ReplicaSet generated from the above desired template using |
| 1211 | + // Argo Rollouts v0.10. The rollouts-pod-template-hash value will not match newer hashing |
| 1212 | + // versions, causing PodTemplateEqualIgnoreHash to fall back to a deep equality check and |
| 1213 | + // pod template defaulting. |
| 1214 | + liveTemplate := ` |
| 1215 | +metadata: |
| 1216 | + creationTimestamp: null |
| 1217 | + labels: |
| 1218 | + app: serviceaccount-ro |
| 1219 | + rollouts-pod-template-hash: 8684587d99 |
| 1220 | +spec: |
| 1221 | + containers: |
| 1222 | + - image: nginx:1.19-alpine |
| 1223 | + imagePullPolicy: IfNotPresent |
| 1224 | + name: app |
| 1225 | + resources: {} |
| 1226 | + terminationMessagePath: /dev/termination-log |
| 1227 | + terminationMessagePolicy: File |
| 1228 | + dnsPolicy: ClusterFirst |
| 1229 | + restartPolicy: Always |
| 1230 | + schedulerName: default-scheduler |
| 1231 | + securityContext: {} |
| 1232 | + serviceAccount: default |
| 1233 | + serviceAccountName: default |
| 1234 | + terminationGracePeriodSeconds: 30 |
| 1235 | +` |
| 1236 | + var live corev1.PodTemplateSpec |
| 1237 | + err = yaml.Unmarshal([]byte(liveTemplate), &live) |
| 1238 | + assert.NoError(t, err) |
1189 | 1239 |
|
| 1240 | + assert.True(t, PodTemplateEqualIgnoreHash(&live, &desired)) |
1190 | 1241 | }
|
0 commit comments