-
Notifications
You must be signed in to change notification settings - Fork 586
[charmed_mysql] refactor & support k8s env #4134
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
Conversation
a574484
to
66da2d2
Compare
Congratulations! One of the builds has completed. 🍾 You can install the built RPMs by following these steps:
Please note that the RPMs should be used only in a testing environment. |
978b4e4
to
f4f97ac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The shell commands added in this PR will not work: please refactor them to use Python to drive the iteration rather than shell loops.
The fix up commits can be squashed into the parent since they aren't really separate tasks - note that the preferred commit/PR title formatting in sos
is to use a "[tag]" at the start of the subject, e.g.:
[charmed_mysql_k8s] add new plugin
Since your first patch is also refactoring charmed_mysql it could also be:
[charmed_mysql_k8s,charmed_mysql] refactor charmed_mysql and add k8s version
Or split the first patch in two - one to refactor charmed_mysql
and a second to add the new charmed_mysql_k8s
plugin. This may make the changes easier to review and navigate in the git log in future.
@bmr-cymru I've updated the PR description. I think it is better to keep the changes for both plugins in this PR, as I removed some dead K8S code from the |
@Deezzir - yes - keep them in the same PR, but perhaps consider splitting the first patch into two commits (the refactoring of the existing plugin, then the addition of the new plugin). It's just a suggestion, but again, it's about making it easy to review. I would definitely consider rebasing and squashing/rewriting commits at this point. Like I said, |
e99cd26
to
12b09e7
Compare
@bmr-cymru the commits are now squashed into two separate commits - one for |
Great, thanks! It's way easier to comprehend the changes in this structure. |
12b09e7
to
6a076fd
Compare
@bmr-cymru I've removed the |
79196ee
to
dd3b5f2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the late review here, as I have been head down on other items.
Why not have one charmed_mysql plugin, and have a check in there to distinguish between the k8s version and the non-k8s version. There are a lot of items that are similar, and it can be nice to have them in the same plugin. I am ok, if you feel that would require too much work.
One example where this is done is the kubernetes plugin, where we have checks for Charmed k8s, Canonical k8s, microk8s.
The code itself looks good to me up to the 2 points mentioned by Arif:
I can live with the current plugins design, the preference among options can be subjective and we also have e.g. |
dd3b5f2
to
a176ee8
Compare
@pmoravec @arif-ali I've tried to make the I've also addressed the generic trigger, now it should be better |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The child plugin is not being initialized/checked for triggers. I can still put them in one file and make some variables like queries and conf_paths shared. WDYT?
We should be able to do this in one file, like we have done in the past with other plugins. If it helps, we can work on this offline, and help you to get to the end result.
a176ee8
to
00b92a1
Compare
2103fe5
to
8298a12
Compare
We synced with @arif-ali (kudos) and decided to merge the two plugin files into one, with dispatching depending on the environment and shared logic. PTAL |
238d178
to
e2c048b
Compare
"dumpdbs_error: option is set, but username and password " | ||
"are not provided" | ||
) | ||
return None, None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a theoretical thought: could there be a deployment with username set but empty password? If so, we must return db_user, None
here.
# If dumpdbs is set, then get all databases | ||
if self.get_option("dumpdbs"): | ||
db_user, db_pass = self._get_db_credentials() | ||
if not db_user or not db_pass: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto if a user can have empty password. (but again, rather theoretical than practical comment, you can ignore it)
sos/report/plugins/charmed_mysql.py
Outdated
f"{self.snap_path_current}{self.conf_paths['MYSQL_CONF']}", | ||
f"{self.snap_path_common}{self.conf_paths['MYSQL_LOGS']}", | ||
f"{self.snap_path_current}{self.conf_paths['MYSQL_ROUTER_CONF']}", | ||
f"{self.snap_path_common}{self.conf_paths['MYSQL_ROUTER_LOGS']}", | ||
f"{self.snap_path_common}{self.conf_paths['MYSQL_SHELL_LOGS']}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather a nitpick (or not, @TurboTurtle ?): while self.conf_paths
entries start with leading /
, isn't it safer to have os.path.join here (or at least {self.snap_path_current}/{self.conf_paths[..]}
)? Or am I too paranoically overdoing it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the self.conf_paths
entries begin with os.path.sep
(/
) then you need to trim that off before passing to join()
, otherwise the joined path is treated as absolute and returned unmodified:
>>> join("/myroot", "/some/other/path")
'/some/other/path'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Deezzir can you also have a look at this too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What can we do here? As pointed by @bmr-cymru we cannot use os.path.join
without escaping the leading /
. I guess we can do a dedicated function for that. Wdyt? Or we leave it as is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess there are three ways to go here:
- Keep it as-is - maybe add a comment above the blocks 214-215 and 220-224 noting that this expects the paths to be in the form
/path/with/leading/slash
. I don't mind this too much tbh. - Change the
conf_paths
table to use relative paths, and switch tojoin($ROOT, self.conf_paths[...])
everywhere (so line 151 would just bejoin("/", self.conf_path[...])
, this list would bejoin(self.snap_path_*, self.conf_paths[...])
). This is more churn but consistent and obedient to preferred path construction style. - Add a little
_join_conf_path()
helper to trim the leading/
and glue the paths together in the list literals. This is less preferable imho.
What do others thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the third option, proactively added a _join_conf_path
to safely join the paths, PTAL!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally ACK. I would appreciate the direct return in check_enabled
method, other comments are just ideas left for a consideration.
Thanks for the patience with our reviews.
e2c048b
to
6b8df12
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a nitpick based on @pmoravec comment, but otherwise looks ok to me
Signed-off-by: Deezzir <[email protected]>
6b8df12
to
88a36fb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functionally this is fine - as a minor style nitpick _join_conf_paths()
could be a local function defined inside CharmedMySQL._process_snap()
(above the add_forbidden_paths()
call) - it doesn't reference self.
and is only called from that one method, but it's not a hard requirement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all your work on this, and the patience on all the reviews
This PR introduces a proper K8S variant for the
charmed_mysql
plugin. The collection will use akubectl
if it detects a K8S environment andmysql
pods or thesnap
to collect data.Please place an 'X' inside each '[]' to confirm you adhere to our Contributor Guidelines