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

Handle invalid locked k8s version field #5205

Merged
merged 4 commits into from
Aug 2, 2023

Conversation

ericpromislow
Copy link
Contributor

@ericpromislow ericpromislow commented Jul 20, 2023

Fixes #5203

More checks that any specified k8s field is valid, and doesn't conflict with the locked field, if given.

And also verify that if the k8s version field is locked, that it's also valid.

Waiting on PR 5199

@gaktive gaktive requested a review from rak-phillip July 21, 2023 18:09
@ericpromislow ericpromislow marked this pull request as draft July 21, 2023 22:58
@ericpromislow ericpromislow force-pushed the 4952-handle-invalid-k8s-version branch from b323b91 to 37eb237 Compare July 21, 2023 23:11
@ericpromislow ericpromislow force-pushed the 5203-handle-invalid-locked-k8s-versions branch from ce28d28 to 80ac720 Compare July 21, 2023 23:30
Base automatically changed from 4952-handle-invalid-k8s-version to main July 24, 2023 16:51
@ericpromislow ericpromislow force-pushed the 5203-handle-invalid-locked-k8s-versions branch from 8c03609 to e7c0e06 Compare July 24, 2023 16:52
@ericpromislow ericpromislow marked this pull request as ready for review July 24, 2023 16:53
rak-phillip
rak-phillip previously approved these changes Jul 24, 2023
Copy link
Contributor

@rak-phillip rak-phillip left a comment

Choose a reason for hiding this comment

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

LGTM. Tested in Linux and was alerted that the version in my locked file was invalid and that the most recent stable version of 1.27.3 would be used instead.

@ericpromislow ericpromislow force-pushed the 5203-handle-invalid-locked-k8s-versions branch from e7c0e06 to 073d22c Compare July 24, 2023 23:29
@gaktive gaktive requested a review from jandubois July 25, 2023 17:43
@ericpromislow ericpromislow force-pushed the 5203-handle-invalid-locked-k8s-versions branch 3 times, most recently from 3a49e75 to 480ed95 Compare July 25, 2023 22:02
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

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

The logic looks fine to me, but is it possible to check the behaviour with BATS or e2e tests, so we don't break it in the future when we refactor stuff?

@ericpromislow ericpromislow force-pushed the 5203-handle-invalid-locked-k8s-versions branch from 480ed95 to 3a3d8b8 Compare July 26, 2023 18:28
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

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

This PR really needs to include a BATS test that verifies all the situations it is supposed to cover.

@ericpromislow ericpromislow force-pushed the 5203-handle-invalid-locked-k8s-versions branch from 3a3d8b8 to 5f9e67d Compare July 27, 2023 00:16
@ericpromislow
Copy link
Contributor Author

Actually writing the BATs test uncovered a case where an invalid locked k8s version was quietly changed to a valid one, so good show.

And then I realized we need a BATs test where a specified valid k8s version on the command-line != the locked k8s version.

@ericpromislow ericpromislow requested a review from jandubois July 27, 2023 00:41
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

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

Thanks for adding the test!

I did a quick review of the new BATS test, just based on how the helper functions work. I haven't verified yet that the test covers all the acceptance criteria; will do that tomorrow.

@ericpromislow ericpromislow requested a review from jandubois July 27, 2023 17:46
@ericpromislow ericpromislow force-pushed the 5203-handle-invalid-locked-k8s-versions branch from ca37357 to f56df81 Compare July 27, 2023 18:25
@ericpromislow ericpromislow force-pushed the 5203-handle-invalid-locked-k8s-versions branch from 618958f to 4695b4d Compare July 28, 2023 20:15
@ericpromislow ericpromislow force-pushed the 5203-handle-invalid-locked-k8s-versions branch from 4695b4d to 818cbda Compare August 1, 2023 18:22
…ock profile.

Also add a BATs to verify this is implemented.

Signed-off-by: Eric Promislow <[email protected]>
- Don't write tests that rely on marshalled exception objects in the log files.
  Rely on handcrafted messages.

Signed-off-by: Eric Promislow <[email protected]>
@ericpromislow ericpromislow force-pushed the 5203-handle-invalid-locked-k8s-versions branch from 966ba1e to 726884b Compare August 1, 2023 20:15
@ericpromislow ericpromislow requested a review from jandubois August 1, 2023 23:05
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

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

This looks fine to me now, but I would like @rak-phillip to review the TypeScript code one more time before we merge this!

Copy link
Contributor

@rak-phillip rak-phillip left a comment

Choose a reason for hiding this comment

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

I think these changes look good, I just have one minor comment to address and then I think we're good to merge.

let storedVersion: semver.SemVer|null;
let matchedVersion: semver.SemVer|undefined;
const invalidK8sVersionMainMessage = `Requested kubernetes version '${ currentConfigVersionString }' is not a valid version.`;
const sv = new SettingsValidator();
const lockedSettings = settingsImpl.getLockedSettings();
const versionIsLocked = lockedSettings.kubernetes?.version ?? false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would we want to convert lockedSettings.kubernetes.version to its boolean representation via something like const versionIsLocked = !!lockedSettings.kubernetes?.version ?? false;? I know that truthy and falsy values are entirely valid, but doing the conversion more explicitly communicates what we are planning to do with this value later on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That isn't necessary. While the type of lockedSettings is Record<string, any>, it's like that because I still never get recursive typescript types right -- it should be

type LockedSettingsType = Record<string, boolean | LockedSettingsType>

So all references are either boolean or null (the expression isn't represented in the current object), and the expression as above is always boolean without needing a !!.

@rak-phillip rak-phillip merged commit 2816514 into main Aug 2, 2023
@rak-phillip rak-phillip deleted the 5203-handle-invalid-locked-k8s-versions branch August 2, 2023 17:20
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.

Invalid k8s versions in a locked profile are fatal errors
3 participants