-
Notifications
You must be signed in to change notification settings - Fork 290
[DPTP-4298] validate _cluster.yaml for sanitized-prow-jobs #4646
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
base: main
Are you sure you want to change the base?
Conversation
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: pruan-rht 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 |
Prucek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add some tests?
cmd/prow-job-dispatcher/main.go
Outdated
| "flag" | ||
| "fmt" | ||
| "io/fs" | ||
| "log" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add log, when we have logrus?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just using that for less cluter print out, I've taken it out.
| } | ||
|
|
||
| // If validate-only mode is enabled, run validation and exit | ||
| if o.validateOnly { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add this to the o.validate method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call, done
pkg/dispatcher/helpers.go
Outdated
| return err | ||
| } | ||
|
|
||
| // Parse the original YAML structure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you have the loadClusterConfigFromBytes function already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that function didn't work correctly for me when I tried it. That's why I started the SaveClusterCOnfigPreservingFormat()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would still like to use the original structure, instead of creating a new one. Once there is a change in there, this change will be forgotten, and all validation will fail.
|
|
||
| // SaveClusterConfigPreservingFormat saves the ClusterMap to YAML while preserving the original format, order, and case sensitivity | ||
| // This method reconstructs the YAML with the exact same structure and field order as the original | ||
| func SaveClusterConfigPreservingFormat(clusterMap ClusterMap, blockedClusters sets.Set[string], originalFilePath, outputFilePath string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you refactor this function? IMO it is a bit too long and it could be separated into separate functions that can be unit-tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done and added a some tests in the release repo
refactored large function into smaller chunks and fold `validate_only` into `validate()`
|
@pruan-rht: The following tests failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
|
Can we somehow test the available capabilities? Do we know what capabilities exist? |
| return o.PrometheusOptions.Validate() | ||
|
|
||
| // Prometheus validation is not required in validate-only mode | ||
| if !o.validateOnly { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have this condition in the function three times. I think if put correctly, it can be there only once
| } | ||
| } | ||
|
|
||
| fmt.Println(string(output)) // Print the diff output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please remove some of those comments? In some places, I would agree with them. But they are mostly disturbing. The code should be sufficient most of the time
| clusterConfig string | ||
| wantErr bool | ||
| expectedErrMsg string | ||
| allowDiffError bool // Allow diff errors as they are informational |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain this to me? I would assume if I diff the file, every diff error is relevant. Why not?
| expectedErrMsg: "failed to load config", | ||
| allowDiffError: false, | ||
| }, | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you maybe add more tests, with all sorts of different errors? They don't need to be files; the struct can be created in the test itself.
I would like to see tests:
- if there is a capacity outside of the range 0-100
- indentation errors
- blocked with capacity/ blocked with disabled? (I don't know what is allowed)
...
try to cover most of the common mistakes that can occur
on a successful run
on a bad config