-
Notifications
You must be signed in to change notification settings - Fork 138
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
Fix "Invalid environment variabled" error for multi-container rockons with "environment" section #1688
Conversation
Just ignore it and move on to the next container in loop until right one is found.
Can one of the admins verify this patch? |
1 similar comment
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
1 similar comment
Can one of the admins verify this patch? |
@schakrava : probably this will be my first code approach to Rock-ons, will check it ;) Mirko |
@@ -145,13 +145,11 @@ def post(self, request, rid, command): | |||
cco.val = cc_map[c] | |||
cco.save() | |||
for e in env_map.keys(): | |||
if (not DContainerEnv.objects.filter( | |||
if (DContainerEnv.objects.filter( |
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.
To @anatox @schakrava and @phillxnet
Premise : I've never had code on rock-ons, but this time probably this help!
My opinion : back to @anatox opening post, we skip any check for wrong environment vars so we don't raise any error, but so doing we completely change business logic aka "update if exists, don't care if var doesn't exist"
@schakrava and @phillxnet : don't know DContainverEnv - Rockons relationship, can this deleted check break Rockons expected behaviours?
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.
An error could be raised if no variables are found for any container of the whole for co in containers:
loop. It would be close to original idea. However I believe that in this case raising an error is a bit reduntant or at least the text should be changed. It looks (if ever raised) like the error is in json but it is in rockstor database actually. It's not fatal anyway and doesn't prevent from installing the rockon so maybe just log a warning?
So there are options and I could modify this pr in if needed.
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.
It looks (if ever raised) like the error is in json but it is in rockstor database actually
You got it @anatox : my knowledge about Rockstor db table for Rock-ons vs json structure doesn't let me understand if we can skip it or not / if we miss something on db side (With my current knowledge I'm more for "wrong/missing" db datas). Once again I'm sure @phillxnet & @schakrava probably can help on this
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.
Finally had my "welcome to Rockons world", it was fun! and I say "No, I don't agree on this"
Let me explain @anatox:
- Rockstor Rockons db entries filled from json files, found it reading/simulating code from rockon.py under storageadmin/views
- On every Rockons "Update" button click we perfor a POST request to rockon.py view to sync db env vars to real json files vars
- Here we start our post request, getting available rockons (
rockons = self._get_available()
) then updating db entries withself._create_update_meta(r, rockons[r])
for every container/docker image _create_update_meta
then updates env vars too here and finally_update_env
has itsget_or_create
over DContainerEnv table
After this long talk, my opinion:
- A: we can have some errors on rockon.py when creating db entries
- B: we can have some wrong json scrutures
- A+B <- worst case
Current PR is a solution, but so doing we don't check & fix the real issue: it's like hiding broken floor tiles with a carpet, we don't see them anymore, but they're still there 😉
Please see this as an invitation to contribute 😃
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.
Add @anatox : can you provide a json file generating this issue? So I can help testing :)
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.
@MFlyer, my pr is not hiding anything. The error removed is actually a mistake, if we want this error to be raised anway, it should raised somewhere else. You have expaned how rockons are stored in DContainerEnv table of rockstor database. I know that, even examined database with pgadmin just to find out there is no error there an nothing is missed. But the problem I'm trying to solve is when rockon is installed in rockon_id.py.
Imagine we have some rockon Rock1. It consists of two containers: ContainerA and ContainerB. ContainerA has ENVA1 and ENVA2 variables and ContainerB has ENVB1. And that's what happens (for now):
env_map = request.data.get('environment', {})
-here we read all variables with user-assigned values in a plain list. In our example it would be[['ENVA1', 'valuea1'], ['ENVA2', 'valuea2'], ['ENVB1', 'valueb1']]
for co in containers:
- here we run through all the containers in rockon-
for e in env_map.keys()
- here we run though all environment variables inenv_map
we have filled with values before
-
-
if (not DContainerEnv.objects.filter(container=co, key=e).exists()):
- checking if this container - variable relation is stored in database. ContainerA: ENVA1 is OK. ENVA2 is OK and ENVB1 is not OK and an error will raise. And becauseenv_map
contains everything this code will allways check all variables from all the containers even when it should not. Thus no multicontainer environment will ever work (with defined environment variables)
-
Here is real json. It's not ready yet but ok to test for this error :) The install will fail when checking nextcloud
container for MYSQL_ROOT_PASSWORD
from nextcloud-mariadb
container
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.
my pr is not hiding anything
While writing my last answer i thought about possible "misunderstandings" and I really hope you did not see it like a judgement :)
My suggestion: I think you can master this issue and your last post confirms this idea 🎉 - with "master this issue" I mean you can think about db redesign, code refactoring, etc etc...and I really hope you'll do it!!! We really appreciate new contributors 😉
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.
Thank you, @MFlyer, I didn't see it like a judgement. I just wanted to show that removing an error check is not a 'hack' or something but a real solution :) I will try to "master this issue" and moreover I've already found another bug in the same function so I'll better change original pr a little.
Sorry for long delay. Restored the 'invalid variable' error but now all variables are written and then read back separately. So everything works without breaking global code style. |
I was suffering from the same error while trying to write my own custom Rock-on, and the two commits in this fix resolved the issue. I am now able to use environment variables in linked containers within the same Rock-on. |
@FroggyFlox is this one now sorted by other means? It's now super old and much has changed in the interim time. It would also require a re-base and it's now been so long that may not be a reasonable request. I'm thus inclined to close it, especially if your ongoing Rock-on revamp work is to address the same thing, in part. And we will still have the work and observations @anatox and @MFlyer put into this. |
No, it is not currently sorted by other means and the issue still stands. It is actually part of a "series" of re-work we need to do to make these kinds of settings work at the container level rather than the rock-on level (#2000, for instance). It has unfortunately been a little while since I've looked seriously at this PR, but as far as I remember I thought @anatox made the right changes. The related code has not changed that much--mostly the surrounding code--but a rebase may not be too difficult (I honestly simply need to dedicate some time to it to properly test it). Note that I do not currently have any ongoing work that would fix the related issue, and what @anatox has already written will most likely end-up being reused. I personally believe it is a "relatively" small fix that is rather expected by our users (myself included) based on the fact that this issue came up several times in the forum. As a result, it is rather high on my to-do list related to rock-ons. I agree that the given the changes in the area, it may be difficult to make simple "edits" to this PR, however. |
@FroggyFlox Thanks for straightening that one out. |
Thank you for interest to this issue again. I'm a bit busy right now but I would check it sometime next week. |
It has been another 4 years now. @anatox would you still be interested in getting your PR straightened out (aka re-baseline, or a new PR? A brief look at the coding in that area, it seems nothing specifically has changed there, so it could be fairly straightforward. Or, if you don't have the time/mindshare, @FroggyFlox, should we consider creating a new PR with these changes in here (against the |
In light of comments/interest on the forum about new Rockons that require multi-container setups, this might become a bit more important for installations like immich.app or photoprism or even ente for photo management as they have multi-container requirements. |
Closing as: |
Used to fix #1588.
env_map contains flat list of environment varialbes, so while looping through containers and checking for environment variables from that list there should not be any exception. Just ignore it and move on to the next container in loop.
Even if no such containers exists (just imagine), that would not be any problem, at least nothing worth an exception, but that's another story.