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

Change schema of hub.extraEnv to allow use of valueFrom #597

Merged
merged 3 commits into from
Mar 27, 2018

Conversation

mattjbray
Copy link
Contributor

This was discussed back in #228, but was not done because of difficulties with toYaml. It looks like indent hadn't been discovered then.

Motivation: I'm adding tracing to the hub component, and I need to use valueFrom to access the downward API.

@mattjbray
Copy link
Contributor Author

Note: if we need to maintain backwards-compatibility, I'd happily create a new config setting that can co-exist with the existing hub.envVar.

@yuvipanda
Copy link
Collaborator

Thanks for the patch, @mattjbray! I would like us to be backwards compatible - we've done this for extraConfig with some type introspection in gotmpl. Do you think you can do something similar for this too?

@mattjbray
Copy link
Contributor Author

@yuvipanda Good idea - I've updated the PR.

@minrk
Copy link
Member

minrk commented Mar 22, 2018

Nice! Does it make sense to do the same for singleuser.extraEnv? Or does the fact that that gets passed through jupyterhub config make that not work?

@yuvipanda yuvipanda merged commit 2dd0d6a into jupyterhub:master Mar 27, 2018
@yuvipanda
Copy link
Collaborator

Thanks for the PR, @mattjbray! Congratulations on getting your first PR here merged! \o/ Hope to see more :)

@minrk yeah, we need to fix that up on the kubespawner side I believe.

@yuvipanda
Copy link
Collaborator

@mattjbray can you also tell us a little more about the tracing you are doing? I'm very curious!

@mattjbray mattjbray deleted the extra-env-as-yaml branch March 28, 2018 09:18
@mattjbray
Copy link
Contributor Author

@yuvipanda thanks!

Sure, at the moment we're using DataDog, a proprietary service.

This DataDog helm chart adds a DaemonSet that runs the DataDog agent on each node. The agent collects metrics about the host (including pods running, etc.), and also provides a collector service much like Zipkin, to which other applications running on the host can send their own metrics.

DataDog provide automatic instrumentation for Python applications (e.g. the tornado server for hub). You just have to wrap the program with their ddtrace executable. To do that we're customizing the hub Dockerfile:

FROM jupyterhub/k8s-hub:4b122ad

USER root

# Install ddtrace and create a script that wraps jupyterhub with ddtrace-run.
RUN pip3 install 'ddtrace==0.11.0'
RUN mv /usr/local/bin/jupyterhub /usr/local/bin/jupyterhub-orig
COPY scripts/jupyterhub /usr/local/bin/jupyterhub

USER jovyan

Where scripts/jupyterhub is simply:

#!/bin/bash

# Wrap with datadog tracer
ddtrace-run /usr/local/bin/jupyterhub-orig "$@"

Then in our values.yaml we tell ddtrace running in the hub deployment how to connect to the collector. This is where extraEnv comes in:

jupyterhub:
  hub:
    extraEnv:
      - name: "DATADOG_TRACE_AGENT_HOSTNAME"
        valueFrom:
          fieldRef:
            fieldPath: status.hostIP
      - name: "DATADOG_TRACE_AGENT_PORT"
        value: "8126"
      - name: "DATADOG_PATCH_MODULES"
        value: "tornado:true,sqlite:true"

datadog:
  datadog:
    apmEnabled: true
  daemonset:
    useHostPort: true

@manics
Copy link
Member

manics commented Apr 4, 2018

I thought I'd mention a use case for keeping the backwards compatibility in future too. If extraEnv is a dict you can easily merge a public config in a git repo with private variables set on the command line during, e.g.

hub:
  extraEnv:
    OAUTH2_AUTHORIZE_URL: "https://login.elixir-czech.org/oidc/authorize"
    OAUTH2_TOKEN_URL: "https://login.elixir-czech.org/oidc/token"
    OAUTH_CALLBACK_URL: https://example.org/hub/oauth_callback
    OAUTH_CLIENT_ID: xxx

and set the private variables separately during deployment: --set hub.extraEnv.OAUTH_CLIENT_SECRET=XXX, but to my knowledge you can't do this when extraEnv is a list.

@consideRatio
Copy link
Member

Ah! @manics this was useful knowledge for me!

consideRatio added a commit to consideRatio/zero-to-jupyterhub-k8s that referenced this pull request Apr 4, 2018
- hub.extraEnv's default value now {} - see [this comment](jupyterhub#597 (comment)) by @manics.
- prePuller.extraImages was referenced in the image-puller daemonsets, and now has an empty placeholder.
@manics manics mentioned this pull request Aug 15, 2018
7 tasks
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.

5 participants