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

DEVPROD-13370 Validate single task distros during project validation #8624

Merged
merged 7 commits into from
Jan 18, 2025

Conversation

bynn
Copy link
Contributor

@bynn bynn commented Jan 14, 2025

DEVPROD-13370

Description

during project validation, any tasks that specify a single task distro will need to be on an allowed list or it will error

Testing

unit testing
(e2e will be done later)

@bynn bynn requested a review from a team January 14, 2025 16:01
distroWarnings = map[string]string{}
singleTaskDistroIDs = []string{}
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not actually necessary to initialize an empty slice here, just appending to the nil slice singleTaskDistroIDs is sufficient. The first append will allocate capacity for the slice. Only maps need to be initialized explicitly before use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just curious but it's possible that singleTaskDistroIDs is never appended to or touched in the code. would it not error and just pass in nil automatically?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's possible that it's never appended to, but it's also quite rare to find code that makes a distinction between a nil slice vs. an empty slice. A nil slice still evaluates len to zero like an empty slice, and you can for loop through it like an empty slice.

The only way you would really tell it's nil and not empty is if you specifically checked if slice == nil. I find that scenario pretty rare compared to length checking.

validator/project_validator.go Outdated Show resolved Hide resolved
validator/project_validator.go Outdated Show resolved Hide resolved
validator/project_validator.go Outdated Show resolved Hide resolved
Message: fmt.Sprintf("buildvariant '%s' references a single task distro '%s' which is not allowed for buildvariants", buildVariant.Name, name),
Level: Error,
},
)
Copy link
Contributor

Choose a reason for hiding this comment

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

RunOn can also be specified for a specific build variant task. Does that also need to be validated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wouldn't the code already take that into account since its looping over all tasks in a bv?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see there's an outermost loop. Never mind!

validator/project_validator.go Outdated Show resolved Hide resolved
validator/project_validator.go Outdated Show resolved Hide resolved
Copy link
Contributor Author

@bynn bynn left a comment

Choose a reason for hiding this comment

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

these were very insightful comments thank you

distroWarnings = map[string]string{}
singleTaskDistroIDs = []string{}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just curious but it's possible that singleTaskDistroIDs is never appended to or touched in the code. would it not error and just pass in nil automatically?

validator/project_validator.go Outdated Show resolved Hide resolved
validator/project_validator.go Outdated Show resolved Hide resolved
validator/project_validator.go Outdated Show resolved Hide resolved
validator/project_validator.go Outdated Show resolved Hide resolved
validator/project_validator.go Outdated Show resolved Hide resolved
Message: fmt.Sprintf("buildvariant '%s' references a single task distro '%s' which is not allowed for buildvariants", buildVariant.Name, name),
Level: Error,
},
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

wouldn't the code already take that into account since its looping over all tasks in a bv?

@bynn bynn requested a review from Kimchelly January 16, 2025 00:04
distroWarnings = map[string]string{}
singleTaskDistroIDs = []string{}
Copy link
Contributor

Choose a reason for hiding this comment

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

It's possible that it's never appended to, but it's also quite rare to find code that makes a distinction between a nil slice vs. an empty slice. A nil slice still evaluates len to zero like an empty slice, and you can for loop through it like an empty slice.

The only way you would really tell it's nil and not empty is if you specifically checked if slice == nil. I find that scenario pretty rare compared to length checking.

validator/project_validator.go Show resolved Hide resolved
validator/project_validator.go Outdated Show resolved Hide resolved
Message: fmt.Sprintf("buildvariant '%s' references a single task distro '%s' which is not allowed for buildvariants", buildVariant.Name, name),
Level: Error,
},
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see there's an outermost loop. Never mind!

validator/project_validator_test.go Outdated Show resolved Hide resolved
@bynn bynn requested a review from Kimchelly January 16, 2025 22:16
@bynn bynn merged commit efd1901 into evergreen-ci:main Jan 18, 2025
10 checks passed
@bynn bynn deleted the DEVPROD-13370 branch January 18, 2025 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants