Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

pmorie
Copy link
Contributor

@pmorie pmorie commented May 8, 2015

WIP for #7739

@smarterclayton PTAL

@pmorie
Copy link
Contributor Author

pmorie commented May 8, 2015

If people are okay with this, I will write doc for the API.

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't know why we would transform this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@smarterclayton os.Env transforms ${ into the empty string, even if it's unmatched.

Copy link
Member

Choose a reason for hiding this comment

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

Can we fork os.Env to fix this and escaping?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fwiw i have some unpushed code with more variants and dusty corners of
os.Expand's behavior explored.
On Fri, May 8, 2015 at 2:06 PM Brian Grant [email protected] wrote:

In pkg/kubelet/kubelet_test.go
#7936 (comment)
:

  •                   Value: "literal-${TEST_LITERAL}",
    
  •               },
    
  •               {
    
  •                   Name:  "SERVICE_VAR_TEST",
    
  •                   Value: "${TEST_SERVICE_HOST}:${TEST_SERVICE_PORT}",
    
  •               },
    
  •           },
    
  •       },
    
  •       masterServiceNs: "nothing",
    
  •       nilLister:       false,
    
  •       expectedEnvs: util.NewStringSet(
    
  •           "TEST_LITERAL=test-test-test",
    
  •           "POD_NAME=dapi-test-pod-name",
    
  •           "POD_NAME_TEST=test-dapi-test-pod-name",
    
  •           "POD_NAME_TEST2=test2-dapi-test-pod-name",
    
  •           "POD_NAME_TEST3=test3-POD_NAME",
    

Can we fork os.Env to fix this and escaping?


Reply to this email directly or view it on GitHub
https://github.com/GoogleCloudPlatform/kubernetes/pull/7936/files#r29962317
.

@thockin
Copy link
Member

thockin commented May 8, 2015

Do we really need to do this? It's one step away from evaluating Command and Args in the same way. I argued that Docker should not do this but they did anyway. Can we just depend on that?

@jonboulle this is not part of appc right now...

@smarterclayton
Copy link
Contributor

Docker does not do this, or at least, I can't make it work in 1.6. Command and Args are almost useless in practice without a ton of bash inside my container, which reduces the utility of env vars (service or field ref) enough where it's very difficult to use them for anything.

If we don't make resolution possible, we essentially are saying "don't use our env vars to do anything interesting".

On May 7, 2015, at 8:26 PM, Tim Hockin [email protected] wrote:

Do we really need to do this? It's one step away from evaluating Command and Args in the same way. I argued that Docker should not do this but they did anyway. Can we just depend on that?

@jonboulle this is not part of appc right now...


Reply to this email directly or view it on GitHub.

@smarterclayton
Copy link
Contributor

Caveat, I'm not advocating it must be automatic. But it's very difficult to use our env for anything real (esp building urls to services)

On May 7, 2015, at 8:26 PM, Tim Hockin [email protected] wrote:

Do we really need to do this? It's one step away from evaluating Command and Args in the same way. I argued that Docker should not do this but they did anyway. Can we just depend on that?

@jonboulle this is not part of appc right now...


Reply to this email directly or view it on GitHub.

@pmorie
Copy link
Contributor Author

pmorie commented May 8, 2015

Oops, I was going to have a flag in the kibelet that turned this on and
off.
On Thu, May 7, 2015 at 8:53 PM Clayton Coleman [email protected]
wrote:

Caveat, I'm not advocating it must be automatic. But it's very difficult
to use our env for anything real (esp building urls to services)

On May 7, 2015, at 8:26 PM, Tim Hockin [email protected]
wrote:

Do we really need to do this? It's one step away from evaluating Command
and Args in the same way. I argued that Docker should not do this but they
did anyway. Can we just depend on that?

@jonboulle this is not part of appc right now...


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub
#7936 (comment)
.

@smarterclayton
Copy link
Contributor

I'm not sure whether this is an API thing or a kubelet thing. If it's optional, why would it be optional at any layer except the API?

On May 7, 2015, at 8:54 PM, Paul Morie [email protected] wrote:

Oops, I was going to have a flag in the kibelet that turned this on and
off.
On Thu, May 7, 2015 at 8:53 PM Clayton Coleman [email protected]
wrote:

Caveat, I'm not advocating it must be automatic. But it's very difficult
to use our env for anything real (esp building urls to services)

On May 7, 2015, at 8:26 PM, Tim Hockin [email protected]
wrote:

Do we really need to do this? It's one step away from evaluating Command
and Args in the same way. I argued that Docker should not do this but they
did anyway. Can we just depend on that?

@jonboulle this is not part of appc right now...


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub
#7936 (comment)
.


Reply to this email directly or view it on GitHub.

@jonboulle
Copy link
Contributor

@thockin I don't understand how this relates to appc, isn't the proposal here to just change the contract between the kubelet and the runtime?

@pmorie
Copy link
Contributor Author

pmorie commented May 8, 2015

@smarterclayton I'm not sure what optional at the API server means in this case -- if it's not allowed, is it a validation error? If so we might break people that are passing who knows what in. I guess the API server could have two config items:

  1. Is it allowed
  2. Is it validation error if an env contains ${var}

@smarterclayton
Copy link
Contributor

I'm talking about an option on the pod or container. If the concern is resolution is unexpected or not always desired, then it's probably a Boolean on the container. The question is whether you ever use ${} inside an environment variable and not want it resolved. I lean towards no, but there's room to be cautious about that statement.

On May 7, 2015, at 10:50 PM, Paul Morie [email protected] wrote:

@smarterclayton I'm not sure what optional at the API server means in this case -- if it's not allowed, is it a validation error? If so we might break people that are passing who knows what in. I guess the API server could have two config items:

Is it allowed
Is it validation error if an env contains ${var}

Reply to this email directly or view it on GitHub.

@pmorie
Copy link
Contributor Author

pmorie commented May 8, 2015

@smarterclayton One other thing we could do is have an EnvVarSource field that was for expanded vars.

apiVersion: v1beta3
kind: Pod
metadata:
  name: expansion-pod
spec:
  containers:
    - name: test-container
      image: gcr.io/google_containers/busybox
      command: [ "/bin/sh", "-c", "env" ]
      env:
        - name: A_NEW_SERVICE_URL
          valueFrom:
            expansion: "glorp://${FOO_SERVICE_HOST}:${FOO_SERVICE_PORT}"
  restartPolicy: Never

@pmorie
Copy link
Contributor Author

pmorie commented May 8, 2015

The EnvVarSource approach has the virtue of not changing the behavior of the existing API.

@smarterclayton
Copy link
Contributor

So I expect expansion to be common. Doing a quick review of the existing examples, here's a list:

That was just me going down the list of our examples in order until I got bored (about 5 seconds). And they all needed it to even boot their thing up on Kube, in a very simple example. So the question is, as soon as someone needs namespace to make path segment unique on a shared disk, where will they get it? Pod name to get an identity? What if you want it to be shorter? Build something real that talks to multiple services?

I could live with envvarsource, I just don't think it's practical to abuse our users that way.

@thockin
Copy link
Member

thockin commented May 8, 2015

@jonboulle yeah, sorry, I got carried away. I thought Docker was doing
this and that maybe we should consider it for appc, but I am as yet
unconvinced and anyway it can be done at a higher level (kubelet)

On Thu, May 7, 2015 at 6:45 PM, Jonathan Boulle [email protected]
wrote:

@thockin https://github.com/thockin I don't understand how this relates
to appc, isn't the proposal here to just change the contract between the
kubelet and the runtime?


Reply to this email directly or view it on GitHub
#7936 (comment)
.

@thockin
Copy link
Member

thockin commented May 8, 2015

The examples I looked at all need it in argv, not in env vars. Expanding
one var into another var isn't going to help those. What am I missing?

On Thu, May 7, 2015 at 9:13 PM, Clayton Coleman [email protected]
wrote:

So I expect expansion to be common. Doing a quick review of the existing
examples, here's a list:

That was just me going down the list of our examples in order. And they
all needed it for at least that part. So the question is, as soon as
someone needs namespace to make path segment unique on a shared disk, where
will they get it? Pod name to get an identity? What if you want it to be
shorter?

I could live with envvarsource, I just don't think it's practical to abuse
our users that way.


Reply to this email directly or view it on GitHub
#7936 (comment)
.

@smarterclayton
Copy link
Contributor

You mean the ones using code? Or writing shell wrappers just to mutate env?

Why would we force people to expand in Argv? That's forcing the user to do something awkward. Can you articulate why controlled env expansion is bad?

On May 8, 2015, at 12:51 AM, Tim Hockin [email protected] wrote:

The examples I looked at all need it in argv, not in env vars. Expanding
one var into another var isn't going to help those. What am I missing?

On Thu, May 7, 2015 at 9:13 PM, Clayton Coleman [email protected]
wrote:

So I expect expansion to be common. Doing a quick review of the existing
examples, here's a list:

That was just me going down the list of our examples in order. And they
all needed it for at least that part. So the question is, as soon as
someone needs namespace to make path segment unique on a shared disk, where
will they get it? Pod name to get an identity? What if you want it to be
shorter?

I could live with envvarsource, I just don't think it's practical to abuse
our users that way.


Reply to this email directly or view it on GitHub
#7936 (comment)
.


Reply to this email directly or view it on GitHub.

@smarterclayton
Copy link
Contributor

Not that we shouldn't allow expansion in Argv. I just thing Argv is reserved for arguments (some of which can be expanded) , and Env should be reserved for Env (some of which can be expanded). Taking env into Argv in order to get it back into env strikes me as a workaround.

Likewise, I want all docker shell wrappers to disappear if they have _SERVICE_HOST or the pod namespace or the host IP (which we should expose via fieldref). Having it in two places (shell and pod) is more fragile and less flexible.

On May 8, 2015, at 12:51 AM, Tim Hockin [email protected] wrote:

The examples I looked at all need it in argv, not in env vars. Expanding
one var into another var isn't going to help those. What am I missing?

On Thu, May 7, 2015 at 9:13 PM, Clayton Coleman [email protected]
wrote:

So I expect expansion to be common. Doing a quick review of the existing
examples, here's a list:

That was just me going down the list of our examples in order. And they
all needed it for at least that part. So the question is, as soon as
someone needs namespace to make path segment unique on a shared disk, where
will they get it? Pod name to get an identity? What if you want it to be
shorter?

I could live with envvarsource, I just don't think it's practical to abuse
our users that way.


Reply to this email directly or view it on GitHub
#7936 (comment)
.


Reply to this email directly or view it on GitHub.

@pmorie
Copy link
Contributor Author

pmorie commented May 8, 2015

Taking env into Argv in order to get it back into env strikes me as a workaround.

Yes.

One other thing, you can't do the expansion in argv if your image doesn't have a shell.

@pmorie
Copy link
Contributor Author

pmorie commented May 8, 2015

I think I will re-implement this with an env var source -- I would really prefer not to suddenly change the behavior of the existing Value field.

@ghost
Copy link

ghost commented May 8, 2015

Before you go burn more time, let's really figure out if we want to do this
at all. If we want to do this, it seems pretty obvious that we should also
process Command and Args. And if we are doing that, ${FOO} is the obvious
syntax. We will also need to decide if service env vars are in scope or
not. The user didn't list them and it is unclear whether they come before
processing or after.

On Thu, May 7, 2015 at 10:30 PM, Paul Morie [email protected]
wrote:

I think I will re-implement this with an env var source -- I would really
prefer not to suddenly change the behavior of the existing Value field.


Reply to this email directly or view it on GitHub
#7936 (comment)
.

@smarterclayton
Copy link
Contributor

My preference would be to eventually require service fieldrefs in order to get service env vars (eventually), so requiring a field ref in order to expand is not unreasonable. In that model we can nuke auto injection (eventually) or make it optional. They should be lower in priority than the env provided in the pod as long as they are magic.

Let's marshal the arguments on both sides here and reach a decision. We've been dancing around this for months and it's something every non-trivial use case on Kube has already put in as a "hack" (lit: a change required solely to make X work on Kube). Paul or I will do the "pro" side

On May 8, 2015, at 1:34 AM, thockin-cc [email protected] wrote:

Before you go burn more time, let's really figure out if we want to do this
at all. If we want to do this, it seems pretty obvious that we should also
process Command and Args. And if we are doing that, ${FOO} is the obvious
syntax. We will also need to decide if service env vars are in scope or
not. The user didn't list them and it is unclear whether they come before
processing or after.

On Thu, May 7, 2015 at 10:30 PM, Paul Morie [email protected]
wrote:

I think I will re-implement this with an env var source -- I would really
prefer not to suddenly change the behavior of the existing Value field.


Reply to this email directly or view it on GitHub
#7936 (comment)
.


Reply to this email directly or view it on GitHub.

@pmorie
Copy link
Contributor Author

pmorie commented May 8, 2015

@thockin

We will also need to decide if service env vars are in scope or
not. The user didn't list them and it is unclear whether they come before
processing or after.

In #7739:

  1. Should support $VAR and ${VAR}
  2. Resolution should happen after runtime-resolved variables are resolved (ie, fieldRef for EnvVarSource)
  3. Should only support kubernetes vars, ie:
  4. Service env vars
  5. Env vars in the container's env

@thockin
Copy link
Member

thockin commented May 8, 2015

Don't get me wrong. I think it's cute. I am just not convinced it is cute
enough to pay for itself.

The Cons:

  1. All complexity needs to be justified, especially just before 1.0
  2. Slippery slope to evaluating command and args
  3. Slippery slope to ${FOO:-default} and other syntax
  4. Requires careful spec and comprehension wrt injected env vars (services)
    and anything lower-layers (docker, rkt) might inject
  5. Requires a spec for escaping

On Fri, May 8, 2015 at 5:51 AM, Clayton Coleman [email protected]
wrote:

My preference would be to eventually require service fieldrefs in order to
get service env vars (eventually), so requiring a field ref in order to
expand is not unreasonable. In that model we can nuke auto injection
(eventually) or make it optional. They should be lower in priority than the
env provided in the pod as long as they are magic.

Let's marshal the arguments on both sides here and reach a decision. We've
been dancing around this for months and it's something every non-trivial
use case on Kube has already put in as a "hack" (lit: a change required
solely to make X work on Kube). Paul or I will do the "pro" side

On May 8, 2015, at 1:34 AM, thockin-cc [email protected]
wrote:

Before you go burn more time, let's really figure out if we want to do
this
at all. If we want to do this, it seems pretty obvious that we should
also
process Command and Args. And if we are doing that, ${FOO} is the
obvious
syntax. We will also need to decide if service env vars are in scope or
not. The user didn't list them and it is unclear whether they come
before
processing or after.

On Thu, May 7, 2015 at 10:30 PM, Paul Morie [email protected]
wrote:

I think I will re-implement this with an env var source -- I would
really
prefer not to suddenly change the behavior of the existing Value
field.


Reply to this email directly or view it on GitHub
<
https://github.com/GoogleCloudPlatform/kubernetes/pull/7936#issuecomment-100105664>

.


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub
#7936 (comment)
.

@pmorie
Copy link
Contributor Author

pmorie commented May 8, 2015

Here's my own attempt at an accounting of pros and cons. Feel free to remix or add your own unique twist to express your feels on this subject:

CONS

  1. Adds additional complexity
  2. Pushes us toward processing Command and Args this way as well
  3. More functionality dealing with env vars, which smell bad (justifiably) to many in the group
  4. Won't support all cases people might want if they think they can use a shell ${var} syntax; for example, ${var:default} is not supported by os.Expand

PROS

(I'm writing this including possible Command and Args expansion, since it seems like it would be strongly complementary if we decide to pull the trigger on this)

  1. Eliminates need for a shell in image to do this very basic expansion; friendlier to image scratchbuilders
  2. Eliminates many setup scripts; friendlier to usesrs
  3. Keeping construction of variables out of user scripts will decrease binding of images to kubernetes
  4. Eliminate more scripts by processing Command and Args

@pmorie
Copy link
Contributor Author

pmorie commented May 8, 2015

Don't get me wrong. I think it's cute. I am just not convinced it is cute
enough to pay for itself.

zing!

@smarterclayton
Copy link
Contributor

On May 8, 2015, at 12:17 PM, Tim Hockin [email protected] wrote:

Don't get me wrong. I think it's cute. I am just not convinced it is cute
enough to pay for itself.

The Cons:

  1. All complexity needs to be justified, especially just before 1.0

Agree. I honk the justification is real users and use cases (constructing urls to other services in pod.json vs creating custom docker images to do that).

  1. Slippery slope to evaluating command and args
  2. Slippery slope to ${FOO:-default} and other syntax

Defaults would be required to be specified as part of the container env set I think (in the short term there are no defaults). Since its evaluated all at once.

  1. Requires careful spec and comprehension wrt injected env vars (services)

Which I believe we already said blindly injection them was a mistake? Which I was hoping to fix by making it explicit here.

and anything lower-layers (docker, rkt) might inject
5. Requires a spec for escaping

Either we don't expand things that aren't defined (no escaping) or we have the value be defined as a variable itself that doesn't expand and we don't double expand. I believe this is solvable.

On Fri, May 8, 2015 at 5:51 AM, Clayton Coleman [email protected]
wrote:

My preference would be to eventually require service fieldrefs in order to
get service env vars (eventually), so requiring a field ref in order to
expand is not unreasonable. In that model we can nuke auto injection
(eventually) or make it optional. They should be lower in priority than the
env provided in the pod as long as they are magic.

Let's marshal the arguments on both sides here and reach a decision. We've
been dancing around this for months and it's something every non-trivial
use case on Kube has already put in as a "hack" (lit: a change required
solely to make X work on Kube). Paul or I will do the "pro" side

On May 8, 2015, at 1:34 AM, thockin-cc [email protected]
wrote:

Before you go burn more time, let's really figure out if we want to do
this
at all. If we want to do this, it seems pretty obvious that we should
also
process Command and Args. And if we are doing that, ${FOO} is the
obvious
syntax. We will also need to decide if service env vars are in scope or
not. The user didn't list them and it is unclear whether they come
before
processing or after.

On Thu, May 7, 2015 at 10:30 PM, Paul Morie [email protected]
wrote:

I think I will re-implement this with an env var source -- I would
really
prefer not to suddenly change the behavior of the existing Value
field.


Reply to this email directly or view it on GitHub
<
https://github.com/GoogleCloudPlatform/kubernetes/pull/7936#issuecomment-100105664>

.


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub
#7936 (comment)
.


Reply to this email directly or view it on GitHub.

@smarterclayton
Copy link
Contributor

I think the way to correct that is to have you try to take a real non-Kube app that needs to either known it's own URL or get another persons. I think you'd agree with me after doing it. But I'm an optimist :)

On May 8, 2015, at 12:22 PM, Paul Morie [email protected] wrote:

Don't get me wrong. I think it's cute. I am just not convinced it is cute
enough to pay for itself.

zing!


Reply to this email directly or view it on GitHub.

@pmorie
Copy link
Contributor Author

pmorie commented May 8, 2015

Defaults would be required to be specified as part of the container env set I think (in the short term there are no defaults). Since its evaluated all at once

Good point

@pmorie
Copy link
Contributor Author

pmorie commented May 16, 2015

@derekwaynecarr I think this is ready for review.

@derekwaynecarr
Copy link
Member

Thanks for the heads up.

Sent from my iPhone

On May 16, 2015, at 4:55 PM, Paul Morie [email protected] wrote:

@derekwaynecarr I think this is ready for review.


Reply to this email directly or view it on GitHub.

@derekwaynecarr
Copy link
Member

I recommend the following:

  1. Add a sample pod showing the feature in use. It looked like Support limited substitution syntax in env var values #7739 had some good examples in the comment thread. I think most readers of this design will better understand the feature by seeing it actually used in a pod definition.
  2. When the Kubelet encounters an unmatched reference, is it possible to throw an Event in the namespace of the Pod where the involved object is the Pod? It's possible the container with the incorrect variable value may continue to run for a long period of time, and the end-user would have no visual or obvious warning of the poor configuration. I suspect an Event would help improve things a little more for an end-user.

@pmorie
Copy link
Contributor Author

pmorie commented May 18, 2015

@derekwaynecarr Added examples and a plan for how to support events. PTAL and let me know your thoughts on the events stuff. I think we may need to add an interface in the third party code that mirrors my proposed ObjectEventRecorder to avoid introducing a dependency from third_party on kube.

@derekwaynecarr
Copy link
Member

Example use the wrong syntax... ${ should be $(

@pmorie
Copy link
Contributor Author

pmorie commented May 18, 2015

Whoops, thanks 4 catch

@derekwaynecarr
Copy link
Member

LGTM, will merge when shippable/travis is happy.

@pmorie pmorie force-pushed the env-resolution branch 2 times, most recently from b8137cf to 7769617 Compare May 18, 2015 17:33
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, but I think you mean "not consumed" both here and below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, fixed

@pmorie pmorie force-pushed the env-resolution branch 3 times, most recently from da279f1 to b29740a Compare May 18, 2015 19:02
@a-robinson
Copy link
Contributor

LGTM

@pmorie
Copy link
Contributor Author

pmorie commented May 18, 2015

⌛ ⌛ ⌛

^ My impression of travis-ci

@a-robinson
Copy link
Contributor

Shippable going green is good enough. Thanks @pmorie!

a-robinson added a commit that referenced this pull request May 18, 2015
Add simple env var resolution
@a-robinson a-robinson merged commit ce95c49 into kubernetes:master May 18, 2015
@pmorie
Copy link
Contributor Author

pmorie commented May 18, 2015

👍

@pmorie
Copy link
Contributor Author

pmorie commented May 18, 2015

Created #8465 as a follow-up to use byte buffer

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.

9 participants