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

Windows: Don't abort everything if $HOME is not writable #8042

Merged

Conversation

mook-as
Copy link
Contributor

@mook-as mook-as commented Jan 7, 2025

This fixes Windows such that if we fail to create ~/.kube we don't fall over immediately and end up hanging indefinitely waiting for Kubernetes. Instead, we can proceed until the correct step and correctly throw up an error when we attempt to update the kubeconfig.

This also contains the start of reporting Windows integration errors as diagnostics, so that users can take action easier.

This is related to #7824 but does not fix it (because we still fail to write the kubeconfig).

If we couldn't find a correct path for kubeconfig (e.g. because the home
directory is not writable), log an error instead of throwing, as the latter
breaks startup.

Signed-off-by: Mark Yen <mark.yen@suse.com>
This makes the Windows integration report errors as diagnostics.  The
messages aren't quite detailed enough yet, but it's enough to let the user
know there is a problem.

Signed-off-by: Mark Yen <mark.yen@suse.com>
* Helper function to trigger a diagnostic report. If a diagnostic should be
* cleared, call this with the error unset.
*/
protected diagnostic(input: {key: DiagnosticKey, distro?: string, error?: unknown}) {
Copy link
Member

Choose a reason for hiding this comment

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

Do you think this needs a check for the input key? e.g.

  if (!input.key) {
    throw new Error('Diagnostic key is required');
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, because key is not optional (distro and error are), per TypeScript annotations. Also, this is a protected method, so we should be able to expect the callers to be type-checked.

config = JSON.parse(await fs.promises.readFile(configPath, 'utf-8'));
} catch (error) {
if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {
// If the file does not exist, create it.
Copy link
Member

Choose a reason for hiding this comment

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

Are we supposed to create a file 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.

We do on line 472. (This is just the old code with an extra layer of indenting.)

applicable() {
return Promise.resolve(process.platform === 'win32');
},
check(): Promise<DiagnosticsCheckerSingleResult[]> {
Copy link
Member

Choose a reason for hiding this comment

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

It's a little hard to see what's happening here should it be broken down to:

const mapResults = (results: Record<string, DiagnosticsCheckerResult>) => {
  return Object.entries(results).map(([id, result]) => ({ ...result, id }));
};

check(): Promise<DiagnosticsCheckerSingleResult[]> {
  return Promise.resolve(mapResults(cachedResults));
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 6e1d40a (I factored out the inner map function instead, and Nino seems okay with that).

@Nino-K Nino-K enabled auto-merge January 7, 2025 22:53
@Nino-K Nino-K merged commit ac92cd4 into rancher-sandbox:main Jan 7, 2025
20 checks passed
@mook-as mook-as deleted the win32/integration-no-fail-on-k3s-fail branch January 13, 2025 19:09
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