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

tests: record fields that are never set #3435

Merged

Conversation

acpana
Copy link
Collaborator

@acpana acpana commented Dec 19, 2024

We should check that all fields for a CRD are set in the fixtures at some point (either in create.yaml or update.yaml. Further, doing that we automate a fair amount of PR reviewing away from checking the CRD definition and how it's tested in the resourcefixtures

( This is actually a better incarnation of #2326 )

@acpana acpana requested review from justinsb and yuwenma December 19, 2024 21:55
}

// Any XYZRef field was already handled and handling the children will just double count
if strings.Contains(fieldPath, "Ref") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's an example of this? Because I think you've already checked strings.HasSuffix(fieldPath, "Ref") { above...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah for references in particular I decided to call it set if the field ending in Ref specifies either external or name.

For instance, when we visit projectRef we run the special handling to determine if either is set.

but then in our depth first traversal we also visit the fields children again and can end up in a situation where we call out that external is not set when name is:

        +       [missing_field] crd=alloydbbackups.alloydb.cnrm.cloud.google.com version=v1beta1: field ".spec.clusterNameRef.external" is not set in unstructured objects

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah gotcha!

Suggested change
if strings.Contains(fieldPath, "Ref") {
// Any fooRef field was already handled and handling the children will just double count
// when we visit fooRef.namespace, fooRef.name and fooRef.external etc
if strings.Contains(fieldPath, "Ref.") {

@acpana acpana force-pushed the acpana/new-fieldtool branch from 5671196 to d69a244 Compare December 19, 2024 22:10
tests/apichecks/crds_test.go Outdated Show resolved Hide resolved
// Check if field exists in any unstructured object
missing := true
for _, obj := range unstructs {
if hasField(obj.Object, fieldPath) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh, can we have another linter that checks for fields we hallucinated :-) (I.e. checks the other way round) There might be a refactor where we introduce something like CollectFields(obj *unstructured.Unstructured) sets[string]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting so the check is there to make sure that the fields in the list are defined in the CRD, right ?

Copy link
Collaborator

@justinsb justinsb Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I think we've got most of them, but there really shouldn't be an exception list here. Though if you implement this, I think it's reasonable to first creating an exception list and then we can farm them out by type!

tests/apichecks/crds_test.go Outdated Show resolved Hide resolved
@justinsb
Copy link
Collaborator

Looks good, a few nits but then I think we should merge

@acpana acpana force-pushed the acpana/new-fieldtool branch from 69f7bf0 to efac31e Compare December 20, 2024 08:28
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: justinsb

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow google-oss-prow bot merged commit 687c2c0 into GoogleCloudPlatform:master Dec 20, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants