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

Show correct message on NodeStatus failure #564

Merged

Conversation

HomayoonAlimohammadi
Copy link
Contributor

Make sure we don't show the you don't have a cluster, run k8s bootstrap in wrong scenarios.

@HomayoonAlimohammadi HomayoonAlimohammadi force-pushed the KU-1096/separate-errors-for-node-status-request branch from e29b359 to 91d1e7a Compare July 25, 2024 10:20
@HomayoonAlimohammadi HomayoonAlimohammadi changed the title [TEST] Return internal error Show correct message on NodeStatus failure Jul 25, 2024
@HomayoonAlimohammadi HomayoonAlimohammadi marked this pull request as ready for review July 25, 2024 10:25
@HomayoonAlimohammadi HomayoonAlimohammadi requested a review from a team as a code owner July 25, 2024 10:25
Copy link
Contributor

@bschimke95 bschimke95 left a comment

Choose a reason for hiding this comment

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

Great work @HomayoonAlimohammadi!
Did a first pass

"github.com/canonical/lxd/shared/api"
)

// GetNodeStatus retrieves the NodeStatus from k8sd client.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: it retrieves it from the server - the client just does the underlying http request.

Also, let's not overdo it with the line breaks. The comments can be at least the same length as the code.

src/k8s/pkg/k8sd/api/node.go Show resolved Hide resolved
env.Exit(1)
return
}
_ = GetNodeStatus(client, cmd, env)
Copy link
Contributor

Choose a reason for hiding this comment

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

This implementation hides a lot of details and is not particular easy to read.
You would need to check the implementation of GetNodeStatus to understand what is going on and why we ignore everything here.

I would:
a) change the GetNodeStatus function to return the status and an error
b) create a new function e.g. isBootstrapped that wraps around the GetNodeStatus call, handles the error decoding logic and returns a bool
c) Then you can do something like this in the commands:

if isBootstrapped(...) {
   cmd.Print("Node already bootstrapped/part of a cluster etc")
   cmd.Exit(1)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the amazing comment @bschimke95 . I tried to address your concern. it didn't turn out to be exactly like you suggested but I guess it's close. returning 3 things does bother me a bit but I feel it's not really that bad. it reduces duplication, it's easily testable and more readable than the previous version. the name isBootstrapped does not seem to work here since we need to return the status and an error as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

the files in src/k8s/cmd/k8s follow the format k8s_<command>_<subcommand>.go
That way a developer can easily see what commands the CLI supports.

Therefore, please move utils like that to src/k8s/cmd/utils.

.gitignore Outdated
@@ -1,6 +1,8 @@
/parts/
/stage/
/prime/
.vscode/
Copy link
Contributor

Choose a reason for hiding this comment

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

don't folks normally put this in their global gitignore?

https://blog.martinhujer.cz/dont-put-idea-vscode-directories-to-projects-gitignore/

I don't really know how i land on this...

Copy link
Contributor Author

@HomayoonAlimohammadi HomayoonAlimohammadi Jul 25, 2024

Choose a reason for hiding this comment

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

TIL about global git ignore 😄

Copy link
Contributor

@addyess addyess left a comment

Choose a reason for hiding this comment

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

Nice. thanks @HomayoonAlimohammadi

.gitignore Outdated
Comment on lines 22 to 23
/docs/tools/.sphinx/node_modules No newline at end of file
/docs/tools/.sphinx/node_modules
Copy link
Contributor

Choose a reason for hiding this comment

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

so you've added a newline here -- i like files with newlines at the end
thanks for having that here...

Copy link
Contributor

@bschimke95 bschimke95 left a comment

Choose a reason for hiding this comment

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

LGTM, only minor comment left.
Great stuff

src/k8s/cmd/util/node_status.go Outdated Show resolved Hide resolved
@HomayoonAlimohammadi HomayoonAlimohammadi merged commit 6e610cd into main Jul 26, 2024
18 checks passed
@HomayoonAlimohammadi HomayoonAlimohammadi deleted the KU-1096/separate-errors-for-node-status-request branch July 26, 2024 08:30
bschimke95 pushed a commit that referenced this pull request Jul 26, 2024
* Show correct message on NodeStatus failure
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.

3 participants