-
Notifications
You must be signed in to change notification settings - Fork 710
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
Should resourcelock be in the same namespace as controller? #352
Comments
I suspect it should be because the resource lock is per controller; i.e. we might have different controllers in different namespaces each claiming a different set of TFJobs. So resource lock should be scoped to a namespace because we only 1 instance of the controller in each namespace accessing the subset of TFJobs assigned to that namespace. |
After taking a deep look at source code here, I think resourcelock's name and namespace is not related to CRD or controller. It is used for create new @jlewi @gaocegege FYI. |
Thanks for investigating.Can you clarify what you mean unrelated? Shouldn't the resourceLock be deployed in the same namespace as the controller? It seems strange that the controller would be creating resources in the default namespace. If I deploy the controller in some name space e.g. "controller-test", then my expectation is that if I delete the namespace "controller-test" all resources associated with the controller should be deleted. Is there a downside to creating the resourceLock in the same namespace as the controller? |
No, it shouldn't. You can deploy
I don't think so. Actually, you can deploy
It will create only one
SGTM. But i'm not sure how to get the namespace of controller if user deploy it in themselves way, set a NAME_SPACE env seems a little strange. How about set optional start flags |
I think this a good solution as it allows us to use the same namespace as the controller for the resourcelock when deployed on K8s. If we use a flag that we set via environment variable when running on K8s, does that mean we can't run the container using the exec form and need to run in a shell because we rely on environment variable expansion? Why not just continue to use an environment variable (as opposed to flags) and if the environment variable isn't set set use the default namespace? |
You can use the ENV statement to set an environment variable in your Dockerfile. IMHO, We should use environmental variables sparingly:
Command-line arguments seems better:
|
So I generally agree about environment variables vs. command line flags. But in this particular case, POD_NAMESPACE describes the runtime environment so isn't this a suitable use case for using an environment variable and not a flag? The only time we want to set a flag is when running on K8s in which case the POD_NAMESPACE environment variable will be set via the downward API. If you wanted to set namespace via a flag, then I think you would still need to set the environment variable POD_NAMESPACE using the downward API and then you'd have to set the value of the flag to the environment variable e.g. |
The simple question: what if I want to run another program with the same
Sorry i'm not very clear about your point here,
Why should i still need to set the environment variable? AFAIK, most components of k8s (kubelet, controller-manager, scheduler) used |
So the problem we want to solve is how to let the tf-operator know what namespace its running in. The namespace is a property of the runtime environment i.e. the K8s pod. The environment variable should only be set when running on K8s. Furthermore, the namespace should be controlled by setting the namespace you deploy the operator in. The convention in K8s seems to pass this through via environment variables (e.g. this is what the etcd-operator does). I think the cleanest way to do this is
If the operator uses a flag then we need to set the flag equal to the environment variable. This relies on shell expansion to evaluate the environment variable and set the flag. I think its cleaner to not rely on variable expansion and just access the environment variable directly. I believe the motivation for this PR was to simplify running the controller locally (not on K8s) in a debug setting. In which case the operator isn't running in a namespace so we can't rely on the downward API to set the environment variable. This is an exceptional use case since the operator is intended to run on K8s. So I think its perfectly reasonable to make developers explicitly set the NAMESPACE environment variable when running the controller locally. |
Thanks for your nice explanation, one last question: Should the environment variable I prefer optional. |
Optional is fine. |
Could we close the issue since #348 is merged 🤔 |
As we discussed here, need to investigate whether the namespace of resourcelock should be the same as controller.
The text was updated successfully, but these errors were encountered: