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

chore: add windows tests #120

Merged
merged 2 commits into from
Apr 26, 2024
Merged

Conversation

eddycharly
Copy link
Contributor

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?


Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 17, 2024
@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Apr 17, 2024
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Apr 17, 2024
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 17, 2024
@eddycharly eddycharly marked this pull request as draft April 17, 2024 20:38
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 17, 2024
@eddycharly eddycharly force-pushed the windows-tests branch 3 times, most recently from 9a8b1c6 to 727413b Compare April 18, 2024 08:41
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 18, 2024
@eddycharly
Copy link
Contributor Author

/label tide/merge-method-squash

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Apr 18, 2024
@eddycharly eddycharly force-pushed the windows-tests branch 3 times, most recently from c27bbe7 to 9a44bb1 Compare April 18, 2024 10:19
@eddycharly eddycharly marked this pull request as ready for review April 18, 2024 10:21
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 18, 2024
versions, err := utils.ReadDir(k.fs, groupPath)
if err != nil {
return nil, fmt.Errorf("failed reading local files dir %s: %w", groupPath, err)
if apiGroups, err := fs.ReadDir(k.fs, "apis"); err == nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note that the behaviour changes slightly. this is because it seems impossible to have a consistent behaviour between windows and linux :(

see golang/go#46734

Copy link
Contributor

Choose a reason for hiding this comment

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

IIUC the go issue you linked refers to files opened with ReadDir returning true for errors.Is(err, fs.ErrNotExist)

That would mean for files with the name apis we throw no error and apiGroups is empty. I think that is preferrable to the current diff which throws out all errors.

Was the original code causing problems? If i understood correctly as above I feel like it wouldnt throw any more errors, just throw one less error for the file-named-apis case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIRC the inconsistency case was when calling ReadDir on a file.

That would mean for files with the name apis we throw no error and apiGroups is empty. I think that is preferrable to the current diff which throws out all errors.

In this case ReadDir will fail, err == nil will not be true and apiGroups is not considered at all.
My feeling was that we were becoming more permissive with this kind of errors so it made sense to check err == nil and just do nothing in case there was an error.

Let me know if you want me to change the behaviour but yeah the real problem is errors.Is(err, fs.ErrNotExist) not being consistent across all systems (at least with an error we got from ReadDir).

Copy link
Contributor

Choose a reason for hiding this comment

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

Let me know if you want me to change the behaviour but yeah the real problem is errors.Is(err, fs.ErrNotExist) not being consistent across all systems (at least with an error we got from ReadDir).

Is it possible to check if the file exists without checking the ReadDir err result? Like stat?

apiGroups, err := fs.ReadDir(k.fs, "apis")
if err != nil && CrossPlatformCheckDirExists(k.fs, "apis")  {
    return nil, fmt.Errorf("...: %w", err)
}

Copy link
Contributor Author

@eddycharly eddycharly Apr 23, 2024

Choose a reason for hiding this comment

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

We can probably do something like that.
Ultimately do you prefer returning an error in this case ? Or just skip the error to let the chain continue collecting paths ?

Copy link
Contributor

Choose a reason for hiding this comment

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

If the dir does not exist it should skip it, but if it does exist and we couldn't read it then it should be an error

Copy link
Contributor

@alexzielenski alexzielenski left a comment

Choose a reason for hiding this comment

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

Really appreciate you doing this! I had a few questions

versions, err := utils.ReadDir(k.fs, groupPath)
if err != nil {
return nil, fmt.Errorf("failed reading local files dir %s: %w", groupPath, err)
if apiGroups, err := fs.ReadDir(k.fs, "apis"); err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

IIUC the go issue you linked refers to files opened with ReadDir returning true for errors.Is(err, fs.ErrNotExist)

That would mean for files with the name apis we throw no error and apiGroups is empty. I think that is preferrable to the current diff which throws out all errors.

Was the original code causing problems? If i understood correctly as above I feel like it wouldnt throw any more errors, just throw one less error for the file-named-apis case.

pkg/openapiclient/local_crds.go Show resolved Hide resolved
pkg/openapiclient/local_schemas.go Outdated Show resolved Hide resolved
@eddycharly
Copy link
Contributor Author

Really appreciate you doing this!

I think i introduced the bug... I break it, i fix it! =)

pkg/openapiclient/local_crds_test.go Outdated Show resolved Hide resolved
fs: os.DirFS("../../invalid"),
dir: ".",
name: "not a dir",
fs: os.DirFS("../../testcases/schemas/error_not_a_dir"),
want: sets.New[string](),
Copy link
Contributor

Choose a reason for hiding this comment

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

This fails on windows returning a nil set rather than an empty set, but not on *nix.

It is also curious to me that we can return nil Paths() but no 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.

It is also curious to me that we can return nil Paths() but no error

If there's no api nor apis folders, what shall we return ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem was reading /api / /apis without trying to read / first 🙈

@eddycharly eddycharly force-pushed the windows-tests branch 3 times, most recently from f64ac7d to 3bed0bb Compare April 25, 2024 08:05
@eddycharly
Copy link
Contributor Author

@alexzielenski tests are green finally :)

Copy link
Contributor

@alexzielenski alexzielenski left a comment

Choose a reason for hiding this comment

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

one more nit 😬

func crossPlatformCheckDirExists(f fs.FS, path string) bool {
_, err := fs.Stat(f, path)
if err != nil {
return !os.IsNotExist(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

I looked at the implementation for os.IsNotExist...it seems very similar to errors.Is except it only looks at specific syscall error types and godoc advises agsinst new usage:

// IsNotExist returns a boolean indicating whether the error is known to
// report that a file or directory does not exist. It is satisfied by
// ErrNotExist as well as some syscall errors.
//
// This function predates errors.Is. It only supports errors returned by
// the os package. New code should use errors.Is(err, fs.ErrNotExist).
func IsNotExist(err error) bool {
	return underlyingErrorIs(err, ErrNotExist)
}

Did the errors.Is check not work here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

trying with errors.Is...

Comment on lines +33 to +38
// check if '.' can be listed
if _, err := fs.ReadDir(k.fs, "."); err != nil {
if crossPlatformCheckDirExists(k.fs, ".") {
return nil, fmt.Errorf("error listing %s: %w", ".", err)
}
}
Copy link
Contributor

@alexzielenski alexzielenski Apr 25, 2024

Choose a reason for hiding this comment

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

I assume this is right but I dont understand why this is necessary. My expectation was that if . cant be listed then ReadDir would yield an error? I'd expect the crossPlatfomrCheckDirExists check after that to not skip the error since it wouldnt be an IsNotExist error, but some permission or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My feeling is that if . is a file and we try to list /api it returns a not exist on windows. It's hard to check as i don't have a windows box but i can send a unit test and log the results...

@alexzielenski
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Apr 25, 2024
@eddycharly
Copy link
Contributor Author

@alexzielenski Shouldn't tide/merge-method-squash allow merging even with merge commits ?

@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. do-not-merge/contains-merge-commits size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 26, 2024
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Apr 26, 2024
@alexzielenski
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 26, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexzielenski, eddycharly

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

@k8s-ci-robot k8s-ci-robot merged commit 57b5e37 into kubernetes-sigs:main Apr 26, 2024
6 checks passed
@eddycharly eddycharly deleted the windows-tests branch April 26, 2024 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants