From 003b6d229c0c4489302d96f814259094598dcbd3 Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Wed, 8 Mar 2023 11:38:32 -0500 Subject: [PATCH] Detect and clean up unneeded after_roundtrip fixtures --- .../core.v1.ListOptions.after_roundtrip.pb | Bin 141 -> 0 bytes ...datingAdmissionPolicy.after_roundtrip.json | 131 ------------------ ...datingAdmissionPolicy.after_roundtrip.yaml | 85 ------------ .../core.v1.ListOptions.after_roundtrip.pb | Bin 141 -> 0 bytes .../api/apitesting/roundtrip/compatibility.go | 29 +++- 5 files changed, 28 insertions(+), 217 deletions(-) delete mode 100644 staging/src/k8s.io/api/testdata/v1.25.0/core.v1.ListOptions.after_roundtrip.pb delete mode 100644 staging/src/k8s.io/api/testdata/v1.26.0/admissionregistration.k8s.io.v1alpha1.ValidatingAdmissionPolicy.after_roundtrip.json delete mode 100644 staging/src/k8s.io/api/testdata/v1.26.0/admissionregistration.k8s.io.v1alpha1.ValidatingAdmissionPolicy.after_roundtrip.yaml delete mode 100644 staging/src/k8s.io/api/testdata/v1.26.0/core.v1.ListOptions.after_roundtrip.pb diff --git a/staging/src/k8s.io/api/testdata/v1.25.0/core.v1.ListOptions.after_roundtrip.pb b/staging/src/k8s.io/api/testdata/v1.25.0/core.v1.ListOptions.after_roundtrip.pb deleted file mode 100644 index 87da93272cab80b03fcadc436a015532d56226f8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 141 zcmd0{C}!XiZ@)nK(?cj8UX&nwByD@_Fpc`yb^qAB%FEJ@A) KOG+^)F#rJJfG?{6 diff --git a/staging/src/k8s.io/api/testdata/v1.26.0/admissionregistration.k8s.io.v1alpha1.ValidatingAdmissionPolicy.after_roundtrip.json b/staging/src/k8s.io/api/testdata/v1.26.0/admissionregistration.k8s.io.v1alpha1.ValidatingAdmissionPolicy.after_roundtrip.json deleted file mode 100644 index d267a4f6822..00000000000 --- a/staging/src/k8s.io/api/testdata/v1.26.0/admissionregistration.k8s.io.v1alpha1.ValidatingAdmissionPolicy.after_roundtrip.json +++ /dev/null @@ -1,131 +0,0 @@ -{ - "kind": "ValidatingAdmissionPolicy", - "apiVersion": "admissionregistration.k8s.io/v1alpha1", - "metadata": { - "name": "nameValue", - "generateName": "generateNameValue", - "namespace": "namespaceValue", - "selfLink": "selfLinkValue", - "uid": "uidValue", - "resourceVersion": "resourceVersionValue", - "generation": 7, - "creationTimestamp": "2008-01-01T01:01:01Z", - "deletionTimestamp": "2009-01-01T01:01:01Z", - "deletionGracePeriodSeconds": 10, - "labels": { - "labelsKey": "labelsValue" - }, - "annotations": { - "annotationsKey": "annotationsValue" - }, - "ownerReferences": [ - { - "apiVersion": "apiVersionValue", - "kind": "kindValue", - "name": "nameValue", - "uid": "uidValue", - "controller": true, - "blockOwnerDeletion": true - } - ], - "finalizers": [ - "finalizersValue" - ], - "managedFields": [ - { - "manager": "managerValue", - "operation": "operationValue", - "apiVersion": "apiVersionValue", - "time": "2004-01-01T01:01:01Z", - "fieldsType": "fieldsTypeValue", - "fieldsV1": {}, - "subresource": "subresourceValue" - } - ] - }, - "spec": { - "paramKind": { - "apiVersion": "apiVersionValue", - "kind": "kindValue" - }, - "matchConstraints": { - "namespaceSelector": { - "matchLabels": { - "matchLabelsKey": "matchLabelsValue" - }, - "matchExpressions": [ - { - "key": "keyValue", - "operator": "operatorValue", - "values": [ - "valuesValue" - ] - } - ] - }, - "objectSelector": { - "matchLabels": { - "matchLabelsKey": "matchLabelsValue" - }, - "matchExpressions": [ - { - "key": "keyValue", - "operator": "operatorValue", - "values": [ - "valuesValue" - ] - } - ] - }, - "resourceRules": [ - { - "resourceNames": [ - "resourceNamesValue" - ], - "operations": [ - "operationsValue" - ], - "apiGroups": [ - "apiGroupsValue" - ], - "apiVersions": [ - "apiVersionsValue" - ], - "resources": [ - "resourcesValue" - ], - "scope": "scopeValue" - } - ], - "excludeResourceRules": [ - { - "resourceNames": [ - "resourceNamesValue" - ], - "operations": [ - "operationsValue" - ], - "apiGroups": [ - "apiGroupsValue" - ], - "apiVersions": [ - "apiVersionsValue" - ], - "resources": [ - "resourcesValue" - ], - "scope": "scopeValue" - } - ], - "matchPolicy": "matchPolicyValue" - }, - "validations": [ - { - "expression": "expressionValue", - "message": "messageValue", - "reason": "reasonValue" - } - ], - "failurePolicy": "failurePolicyValue" - } -} \ No newline at end of file diff --git a/staging/src/k8s.io/api/testdata/v1.26.0/admissionregistration.k8s.io.v1alpha1.ValidatingAdmissionPolicy.after_roundtrip.yaml b/staging/src/k8s.io/api/testdata/v1.26.0/admissionregistration.k8s.io.v1alpha1.ValidatingAdmissionPolicy.after_roundtrip.yaml deleted file mode 100644 index 51655606777..00000000000 --- a/staging/src/k8s.io/api/testdata/v1.26.0/admissionregistration.k8s.io.v1alpha1.ValidatingAdmissionPolicy.after_roundtrip.yaml +++ /dev/null @@ -1,85 +0,0 @@ -apiVersion: admissionregistration.k8s.io/v1alpha1 -kind: ValidatingAdmissionPolicy -metadata: - annotations: - annotationsKey: annotationsValue - creationTimestamp: "2008-01-01T01:01:01Z" - deletionGracePeriodSeconds: 10 - deletionTimestamp: "2009-01-01T01:01:01Z" - finalizers: - - finalizersValue - generateName: generateNameValue - generation: 7 - labels: - labelsKey: labelsValue - managedFields: - - apiVersion: apiVersionValue - fieldsType: fieldsTypeValue - fieldsV1: {} - manager: managerValue - operation: operationValue - subresource: subresourceValue - time: "2004-01-01T01:01:01Z" - name: nameValue - namespace: namespaceValue - ownerReferences: - - apiVersion: apiVersionValue - blockOwnerDeletion: true - controller: true - kind: kindValue - name: nameValue - uid: uidValue - resourceVersion: resourceVersionValue - selfLink: selfLinkValue - uid: uidValue -spec: - failurePolicy: failurePolicyValue - matchConstraints: - excludeResourceRules: - - apiGroups: - - apiGroupsValue - apiVersions: - - apiVersionsValue - operations: - - operationsValue - resourceNames: - - resourceNamesValue - resources: - - resourcesValue - scope: scopeValue - matchPolicy: matchPolicyValue - namespaceSelector: - matchExpressions: - - key: keyValue - operator: operatorValue - values: - - valuesValue - matchLabels: - matchLabelsKey: matchLabelsValue - objectSelector: - matchExpressions: - - key: keyValue - operator: operatorValue - values: - - valuesValue - matchLabels: - matchLabelsKey: matchLabelsValue - resourceRules: - - apiGroups: - - apiGroupsValue - apiVersions: - - apiVersionsValue - operations: - - operationsValue - resourceNames: - - resourceNamesValue - resources: - - resourcesValue - scope: scopeValue - paramKind: - apiVersion: apiVersionValue - kind: kindValue - validations: - - expression: expressionValue - message: messageValue - reason: reasonValue diff --git a/staging/src/k8s.io/api/testdata/v1.26.0/core.v1.ListOptions.after_roundtrip.pb b/staging/src/k8s.io/api/testdata/v1.26.0/core.v1.ListOptions.after_roundtrip.pb deleted file mode 100644 index 87da93272cab80b03fcadc436a015532d56226f8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 141 zcmd0{C}!XiZ@)nK(?cj8UX&nwByD@_Fpc`yb^qAB%FEJ@A) KOG+^)F#rJJfG?{6 diff --git a/staging/src/k8s.io/apimachinery/pkg/api/apitesting/roundtrip/compatibility.go b/staging/src/k8s.io/apimachinery/pkg/api/apitesting/roundtrip/compatibility.go index 8272f9fa358..e80d6d68a15 100644 --- a/staging/src/k8s.io/apimachinery/pkg/api/apitesting/roundtrip/compatibility.go +++ b/staging/src/k8s.io/apimachinery/pkg/api/apitesting/roundtrip/compatibility.go @@ -364,6 +364,12 @@ func writeFile(t *testing.T, dir string, gvk schema.GroupVersionKind, suffix, ex } } +func deleteFile(t *testing.T, dir string, gvk schema.GroupVersionKind, suffix, extension string) { + if err := os.Remove(filepath.Join(dir, makeName(gvk)+suffix+"."+extension)); err != nil { + t.Fatalf("error removing %s: %v", extension, err) + } +} + func (c *CompatibilityTestOptions) runPreviousVersionTest(t *testing.T, gvk schema.GroupVersionKind, previousVersionDir string, usedFiles sets.String) { jsonBeforeRoundTrip, yamlBeforeRoundTrip, protoBeforeRoundTrip, err := read(previousVersionDir, gvk, "", usedFiles) if os.IsNotExist(err) || (len(jsonBeforeRoundTrip) == 0 && len(yamlBeforeRoundTrip) == 0 && len(protoBeforeRoundTrip) == 0) { @@ -422,15 +428,28 @@ func (c *CompatibilityTestOptions) runPreviousVersionTest(t *testing.T, gvk sche } protoAfterRoundTrip := protoBytes.Bytes() + jsonNeedsRemove := false + yamlNeedsRemove := false + protoNeedsRemove := false + expectedJSONAfterRoundTrip, expectedYAMLAfterRoundTrip, expectedProtoAfterRoundTrip, _ := read(previousVersionDir, gvk, ".after_roundtrip", usedFiles) if len(expectedJSONAfterRoundTrip) == 0 { expectedJSONAfterRoundTrip = jsonBeforeRoundTrip + } else if bytes.Equal(jsonBeforeRoundTrip, expectedJSONAfterRoundTrip) { + t.Errorf("JSON after_roundtrip file is identical and should be removed") + jsonNeedsRemove = true } if len(expectedYAMLAfterRoundTrip) == 0 { expectedYAMLAfterRoundTrip = yamlBeforeRoundTrip + } else if bytes.Equal(yamlBeforeRoundTrip, expectedYAMLAfterRoundTrip) { + t.Errorf("YAML after_roundtrip file is identical and should be removed") + yamlNeedsRemove = true } if len(expectedProtoAfterRoundTrip) == 0 { expectedProtoAfterRoundTrip = protoBeforeRoundTrip + } else if bytes.Equal(protoBeforeRoundTrip, expectedProtoAfterRoundTrip) { + t.Errorf("Proto after_roundtrip file is identical and should be removed") + protoNeedsRemove = true } jsonNeedsUpdate := false @@ -456,17 +475,25 @@ func (c *CompatibilityTestOptions) runPreviousVersionTest(t *testing.T, gvk sche // t.Logf("json (for locating the offending field based on surrounding data): %s", string(expectedJSON)) } - if jsonNeedsUpdate || yamlNeedsUpdate || protoNeedsUpdate { + if jsonNeedsUpdate || yamlNeedsUpdate || protoNeedsUpdate || jsonNeedsRemove || yamlNeedsRemove || protoNeedsRemove { const updateEnvVar = "UPDATE_COMPATIBILITY_FIXTURE_DATA" if os.Getenv(updateEnvVar) == "true" { if jsonNeedsUpdate { writeFile(t, previousVersionDir, gvk, ".after_roundtrip", "json", jsonAfterRoundTrip) + } else if jsonNeedsRemove { + deleteFile(t, previousVersionDir, gvk, ".after_roundtrip", "json") } + if yamlNeedsUpdate { writeFile(t, previousVersionDir, gvk, ".after_roundtrip", "yaml", yamlAfterRoundTrip) + } else if yamlNeedsRemove { + deleteFile(t, previousVersionDir, gvk, ".after_roundtrip", "yaml") } + if protoNeedsUpdate { writeFile(t, previousVersionDir, gvk, ".after_roundtrip", "pb", protoAfterRoundTrip) + } else if protoNeedsRemove { + deleteFile(t, previousVersionDir, gvk, ".after_roundtrip", "pb") } t.Logf("wrote expected compatibility data... verify, commit, and rerun tests") } else {