Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crddiff: Look up version by name, not array index #226

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions internal/crdschema/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,22 @@ func (d *RevisionDiff) GetBreakingChanges() (map[string]*diff.Diff, error) {
}

diffMap := make(map[string]*diff.Diff, len(baseDocs))
for i, baseDoc := range baseDocs {
for _, baseDoc := range baseDocs {
versionName := baseDoc.Info.Version
if i >= len(revisionDocs) || revisionDocs[i].Info.Version != versionName {
var revisionDoc *openapi3.T
for _, r := range revisionDocs {
if r.Info.Version == versionName {
revisionDoc = r
break
}
}

if revisionDoc == nil {
// no corresponding version to compare in the revision
return nil, errors.Errorf("revision has no corresponding version to compare with the base for the version name: %s", versionName)
}
sd, err := schemaDiff(baseDoc, revisionDocs[i])

sd, err := schemaDiff(baseDoc, revisionDoc)
if err != nil {
return nil, errors.Wrap(err, errBreakingRevisionChangesCompute)
}
Expand Down
11 changes: 11 additions & 0 deletions internal/crdschema/crd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,17 @@ func Test_GetRevisionBreakingChanges(t *testing.T) {
},
},
},
"Unordered": {
reason: "No diff should be reported if the order of versions is different",
args: args{
basePath: "testdata/base.yaml",
revisionModifiers: []crdModifier{
func(r *v1.CustomResourceDefinition) {
r.Spec.Versions[0], r.Spec.Versions[1] = r.Spec.Versions[1], r.Spec.Versions[0]
},
},
},
},
"ExistingEnumConstantRemovedInRevision": {
reason: "Removing an existing enum constant is a breaking API change",
args: args{
Expand Down