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

Read user namespace from file #97

Merged
merged 1 commit into from
May 26, 2022

Conversation

dkwon17
Copy link
Contributor

@dkwon17 dkwon17 commented May 24, 2022

Reads the current namespace from /var/run/secrets/kubernetes.io/serviceaccount/namespace.
Fixes #92.

Signed-off-by: David Kwon dakwon@redhat.com

@dkwon17 dkwon17 requested a review from ibuziuk May 24, 2022 18:08
@dkwon17
Copy link
Contributor Author

dkwon17 commented May 24, 2022

It might be a bit hard to test this PR at the moment since we do not have a devfile v2 yet (issue). In general, the steps here from the docs can be followed. Unlike what's mentioned in the docs, we don't need a settings.xml file with GH credentials.

Additionally, if there's already a default telemetry plugin listening on port 4167, the default telemetry plugin should first be removed before testing this PR. This is because running this project also requires listening on port 4167.

Comment on lines 67 to 88
private String getCurrentNamespace(KubernetesClient client) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(Config.KUBERNETES_NAMESPACE_PATH));
String namespace = br .readLine();
br.close();
return namespace.strip();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

got a bit lost with implementation. Why do we pass the client in param? also wondering if it is a reliable way of getting the namespace based on the KUBERNETES_NAMESPACE_PATH ? should not we close reader in finally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, thank you for pointing that out.

As for whether getting the namespace based on the KUBERNETES_NAMESPACE_PATH is reliable, it seems to work well empirically, but are there cases where /var/run/secrets/kubernetes.io/serviceaccount is not mounted to the container?

I've updated the code so that there is a new approach as well as the file reading approach. The new approach is reading the DEVWORKSPACE_NAMESPACE environment variable set on the workspace containers by the DWO

image

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks good, thanks

@dkwon17 dkwon17 force-pushed the readnamespacefromfile branch 3 times, most recently from 0fc3132 to fed60f4 Compare May 25, 2022 21:00
Signed-off-by: David Kwon <dakwon@redhat.com>
@ibuziuk ibuziuk merged commit f0d37f1 into che-incubator:master May 26, 2022
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.

Failed to find devworkspace with id: workspace694f8b9811b240be in namespace: null
2 participants