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

Parametrize reboot commands #297

Merged
merged 3 commits into from
Mar 29, 2021

Conversation

evrardjp
Copy link
Collaborator

No description provided.

@evrardjp
Copy link
Collaborator Author

This is on top of #260 . We can either merge it with 2 prs or just one.

@evrardjp evrardjp changed the title Refactor reboot command Parametrize reboot commands Feb 1, 2021
@kingdonb kingdonb mentioned this pull request Feb 5, 2021
@kingdonb
Copy link
Contributor

kingdonb commented Feb 5, 2021

I was going to suggest adding a make target that runs the tests, but this might be complicated since the binary won't compile on macos, the tests can't be run without some kind of linux environment. It would be great if the tests you've added here can be hooked up to run as part of the CI.

@kingdonb kingdonb self-assigned this Feb 5, 2021
@kingdonb kingdonb self-requested a review February 5, 2021 14:30
@evrardjp
Copy link
Collaborator Author

evrardjp commented Feb 5, 2021

@kingdonb IIRC, the build image test is running make + make image

@kingdonb
Copy link
Contributor

kingdonb commented Feb 5, 2021

The Dockerfile isn't running any test from what I can tell, and there is no sign of test in the Makefile at all. There are a few tests that look like they are meant to be run by hand, on kind, one that sets up the reboot sentinels and another that checks the reboots proceeding orderly. I like the unit tests I saw that you added, this is a great technique to make source code better.

The linux binary is cross-compiled in the Makefile and copied into the docker image, it would be possible to run the test inside a build if there was a compiler/sdk added in the Dockerfile, or build from some SDK image. Perhaps this Dockerfile can be factored to support this as a multi-stage build?

I found a Linux machine to run the tests on that you added:

$ cd cmd/kured/
$ go test
WARN[0000] Reboot blocked: prometheus query error: Post "/api/v1/query": unsupported protocol scheme ""
FATA[0000] Error invoking sentinel command: fork/exec ./babar: no such file or directory
PASS
ok  	github.com/weaveworks/kured/cmd/kured	0.068s

I am not sure if it's possible to redirect those logs or capture somehow, since they are good logs that indicate success of the test, (but outwardly giving the appearance of bad news during the test execution is less than helpful for anyone running the tests and reading along for success output.)

I think this is a great PR and I am likely to give it my approval if some of this can be addressed

@evrardjp
Copy link
Collaborator Author

Rebased.

@evrardjp
Copy link
Collaborator Author

New features in, need adapting. WIP.

@evrardjp
Copy link
Collaborator Author

This should do the trick.

Without this patch, we rely on global state in many functions for
which we check the reboot blockers.

This is a problem, as it's harder to test.

This patch fixes it by refactoring the reboot blockers. This also
includes a first series of unit tests for our main.
Without this patch, you cannot configure the reboot
command to use, or the use another command to trigger
a reboot.

This is a problem, as multiple users have asked for
it in the past, and we are lacking flexibility.

This fixes it by introducing two new parameters,
- one to provide a custom reboot command.
  This should help people running kured on
  non systemd OS
- one to provide a custom sentinel command.
  This should help people running non Ubuntu OS,
  as they can directly use their command instead of
  generating a file (useful for CentOS/SUSE)

For this, several refactors had to be done, to
remove global state in some functions. Making those
functions closer to "pure functions" helps us
increase our test coverage here and later.

As commandReboot was very close to rebootCommand,
the function to reboot the node has been renamed
to invokeReboot.
Without this, go test will rightfully fail.

This is a problem, as we don't have go test enabled, but we want
to have this in the future.

This should fix it.
@evrardjp
Copy link
Collaborator Author

Rebased for 1.20.

@evrardjp
Copy link
Collaborator Author

@kingdonb go tests fixed in this PR. New go tests added in #326.

Copy link
Member

@ckotzbauer ckotzbauer left a comment

Choose a reason for hiding this comment

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

I hadn't time to test, but the code looks good!

@evrardjp
Copy link
Collaborator Author

Well, the CI does a preliminary test and doesn't seem to complain too much :)

@evrardjp
Copy link
Collaborator Author

I won't merge my own PR, so someone else should do ;)

@dholbach dholbach added this to the 1.7.0 milestone Mar 24, 2021
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.

None yet

4 participants